@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
@@ -1,180 +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 { AssetAmount, Cur, Cursors, HostAmount, Writer, Writers } from "../Cursors.sol";
6
-
7
- using Cursors for Cur;
8
- using Writers for Writer;
9
-
10
- string constant ALFCTB = "addLiquidityFromCustodiesToBalances";
11
- string constant ALFBTB = "addLiquidityFromBalancesToBalances";
12
- string constant RLFCTB = "removeLiquidityFromCustodyToBalances";
13
- string constant RLFBTB = "removeLiquidityFromBalanceToBalances";
14
-
15
- /// @title AddLiquidityFromCustodiesToBalances
16
- /// @notice Command that adds liquidity using paired CUSTODY state blocks and emits BALANCE outputs.
17
- /// The hook receives the live custody cursor so it can consume a pair per iteration.
18
- abstract contract AddLiquidityFromCustodiesToBalances is CommandBase {
19
- uint internal immutable addLiquidityFromCustodiesToBalancesId = commandId(ALFCTB);
20
- uint private immutable outScale;
21
-
22
- constructor(string memory input, uint scaledRatio) {
23
- outScale = scaledRatio;
24
- emit Command(host, ALFCTB, input, addLiquidityFromCustodiesToBalancesId, State.Custodies, State.Balances, false);
25
- }
26
-
27
- /// @dev Override to add liquidity from the current `custodies` stream
28
- /// position, consuming the two custody blocks that make up the pair.
29
- /// `request` may be ignored by implementations that don't need it.
30
- /// Implementations validate and unpack it as
31
- /// needed. Implementations should advance `custodies` past the consumed
32
- /// pair and may append BALANCE outputs to `out` within the capacity
33
- /// implied by this command's configured `scaledRatio`.
34
- function addLiquidityFromCustodiesToBalances(
35
- bytes32 account,
36
- Cur memory custodies,
37
- Cur memory request,
38
- Writer memory out
39
- ) internal virtual;
40
-
41
- function addLiquidityFromCustodiesToBalances(
42
- CommandContext calldata c
43
- ) external onlyCommand(addLiquidityFromCustodiesToBalancesId, c.target) returns (bytes memory) {
44
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
45
- Cur memory request = cursor(c.request);
46
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
47
-
48
- while (state.i < state.bound) {
49
- addLiquidityFromCustodiesToBalances(c.account, state, request, writer);
50
- }
51
-
52
- return state.complete(writer);
53
- }
54
- }
55
-
56
- /// @title RemoveLiquidityFromCustodyToBalances
57
- /// @notice Command that removes liquidity from a single CUSTODY state block and emits BALANCE outputs.
58
- abstract contract RemoveLiquidityFromCustodyToBalances is CommandBase {
59
- uint internal immutable removeLiquidityFromCustodyToBalancesId = commandId(RLFCTB);
60
- uint private immutable outScale;
61
-
62
- constructor(string memory input, uint scaledRatio) {
63
- outScale = scaledRatio;
64
- emit Command(host, RLFCTB, input, removeLiquidityFromCustodyToBalancesId, State.Custodies, State.Balances, false);
65
- }
66
-
67
- /// @dev Override to remove liquidity from a custody position.
68
- /// `request` may be ignored by implementations that don't need it.
69
- /// Implementations validate and unpack
70
- /// it as needed, and may append BALANCE outputs to `out` within the
71
- /// capacity implied by this command's configured `scaledRatio`.
72
- function removeLiquidityFromCustodyToBalances(
73
- bytes32 account,
74
- HostAmount memory custody,
75
- Cur memory request,
76
- Writer memory out
77
- ) internal virtual;
78
-
79
- function removeLiquidityFromCustodyToBalances(
80
- CommandContext calldata c
81
- ) external onlyCommand(removeLiquidityFromCustodyToBalancesId, c.target) returns (bytes memory) {
82
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
83
- Cur memory request = cursor(c.request);
84
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
85
-
86
- while (state.i < state.bound) {
87
- HostAmount memory custody = state.unpackCustodyValue();
88
- removeLiquidityFromCustodyToBalances(c.account, custody, request, writer);
89
- }
90
-
91
- return state.complete(writer);
92
- }
93
- }
94
-
95
- /// @title AddLiquidityFromBalancesToBalances
96
- /// @notice Command that adds liquidity using paired BALANCE state blocks and emits BALANCE outputs.
97
- /// The hook receives the live balances cursor so it can consume a pair per iteration.
98
- abstract contract AddLiquidityFromBalancesToBalances is CommandBase {
99
- uint internal immutable addLiquidityFromBalancesToBalancesId = commandId(ALFBTB);
100
- uint private immutable outScale;
101
-
102
- constructor(string memory input, uint scaledRatio) {
103
- outScale = scaledRatio;
104
- emit Command(host, ALFBTB, input, addLiquidityFromBalancesToBalancesId, State.Balances, State.Balances, false);
105
- }
106
-
107
- /// @dev Override to add liquidity from the current `balances` stream
108
- /// position, consuming the two balance blocks that make up the pair.
109
- /// `request` is the live auxiliary request cursor. Implementations should
110
- /// advance `balances` past the consumed pair, may consume `request` as
111
- /// needed, and may append BALANCE outputs to `out` within the capacity
112
- /// implied by this command's configured `scaledRatio`.
113
- function addLiquidityFromBalancesToBalances(
114
- bytes32 account,
115
- Cur memory balances,
116
- Cur memory request,
117
- Writer memory out
118
- ) internal virtual;
119
-
120
- function addLiquidityFromBalancesToBalances(
121
- CommandContext calldata c
122
- ) external onlyCommand(addLiquidityFromBalancesToBalancesId, c.target) returns (bytes memory) {
123
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
124
- Cur memory request = cursor(c.request);
125
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
126
-
127
- while (state.i < state.bound) {
128
- addLiquidityFromBalancesToBalances(c.account, state, request, writer);
129
- }
130
-
131
- return state.complete(writer);
132
- }
133
- }
134
-
135
- /// @title RemoveLiquidityFromBalanceToBalances
136
- /// @notice Command that removes liquidity from a single BALANCE state block and emits BALANCE outputs.
137
- abstract contract RemoveLiquidityFromBalanceToBalances is CommandBase {
138
- uint internal immutable removeLiquidityFromBalanceToBalancesId = commandId(RLFBTB);
139
- uint private immutable outScale;
140
-
141
- constructor(string memory input, uint scaledRatio) {
142
- outScale = scaledRatio;
143
- emit Command(host, RLFBTB, input, removeLiquidityFromBalanceToBalancesId, State.Balances, State.Balances, false);
144
- }
145
-
146
- /// @dev Override to remove liquidity from a balance position.
147
- /// `request` is the live auxiliary request cursor. Implementations may
148
- /// consume it as needed or ignore it, and may append BALANCE outputs to
149
- /// `out` within the capacity implied by this command's configured
150
- /// `scaledRatio`.
151
- function removeLiquidityFromBalanceToBalances(
152
- bytes32 account,
153
- AssetAmount memory balance,
154
- Cur memory request,
155
- Writer memory out
156
- ) internal virtual;
157
-
158
- function removeLiquidityFromBalanceToBalances(
159
- CommandContext calldata c
160
- ) external onlyCommand(removeLiquidityFromBalanceToBalancesId, c.target) returns (bytes memory) {
161
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
162
- Cur memory request = cursor(c.request);
163
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
164
-
165
- while (state.i < state.bound) {
166
- AssetAmount memory balance = state.unpackBalanceValue();
167
- removeLiquidityFromBalanceToBalances(c.account, balance, request, writer);
168
- }
169
-
170
- return state.complete(writer);
171
- }
172
- }
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
package/commands/Mint.sol DELETED
@@ -1,54 +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, Writers, Writer } from "../Cursors.sol";
6
- using Cursors for Cur;
7
- using Writers for Writer;
8
-
9
- string constant NAME = "mintToBalances";
10
-
11
- /// @title MintToBalances
12
- /// @notice Command that mints new BALANCE outputs from a request stream.
13
- /// The output-to-input ratio is set at construction via `scaledRatio`.
14
- /// The hook receives both the request cursor and output writer directly to allow
15
- /// flexible parsing patterns.
16
- abstract contract MintToBalances is CommandBase {
17
- uint internal immutable mintToBalancesId = commandId(NAME);
18
- uint private immutable outScale;
19
-
20
- constructor(string memory input, uint scaledRatio) {
21
- outScale = scaledRatio;
22
- emit Command(host, NAME, input, mintToBalancesId, State.Empty, State.Balances, false);
23
- }
24
-
25
- /// @dev Override to mint balances described by the current `input` stream
26
- /// position for `account`.
27
- /// Implementations should consume the request blocks they handle by
28
- /// advancing `input`, and may append BALANCE outputs to `out` within the
29
- /// capacity implied by this command's configured `scaledRatio`.
30
- function mintToBalances(
31
- bytes32 account,
32
- Cur memory input,
33
- Writer memory out
34
- ) internal virtual;
35
-
36
- function mintToBalances(
37
- CommandContext calldata c
38
- ) external onlyCommand(mintToBalancesId, c.target) returns (bytes memory) {
39
- (Cur memory request, uint count, ) = cursor(c.request, 1);
40
- Writer memory writer = Writers.allocScaledBalances(count, outScale);
41
-
42
- while (request.i < request.bound) {
43
- mintToBalances(c.account, request, writer);
44
- }
45
-
46
- return request.complete(writer);
47
- }
48
- }
49
-
50
-
51
-
52
-
53
-
54
-
@@ -1,55 +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, Writers, Writer } from "../Cursors.sol";
6
-
7
- string constant NAME = "reclaimToBalances";
8
-
9
- using Cursors for Cur;
10
- using Writers for Writer;
11
-
12
- /// @title ReclaimToBalances
13
- /// @notice Command that reclaims or recovers assets from a request stream into BALANCE outputs.
14
- /// The hook receives the request cursor and output writer directly for flexible parsing.
15
- /// The output-to-input ratio is set at construction via `scaledRatio`.
16
- abstract contract ReclaimToBalances is CommandBase {
17
- uint internal immutable reclaimToBalancesId = commandId(NAME);
18
- uint private immutable outScale;
19
-
20
- constructor(string memory input, uint scaledRatio) {
21
- outScale = scaledRatio;
22
- emit Command(host, NAME, input, reclaimToBalancesId, State.Empty, State.Balances, false);
23
- }
24
-
25
- /// @dev Override to reclaim balances described by the current `input`
26
- /// stream position.
27
- /// Implementations validate and unpack as needed, should advance `input`
28
- /// past the consumed request blocks, and may append BALANCE outputs to
29
- /// `out` within the capacity implied by this command's configured
30
- /// `scaledRatio`.
31
- function reclaimToBalances(
32
- bytes32 account,
33
- Cur memory input,
34
- Writer memory out
35
- ) internal virtual;
36
-
37
- function reclaimToBalances(
38
- CommandContext calldata c
39
- ) external onlyCommand(reclaimToBalancesId, c.target) returns (bytes memory) {
40
- (Cur memory request, uint count, ) = cursor(c.request, 1);
41
- Writer memory writer = Writers.allocScaledBalances(count, outScale);
42
-
43
- while (request.i < request.bound) {
44
- reclaimToBalances(c.account, request, writer);
45
- }
46
-
47
- return request.complete(writer);
48
- }
49
- }
50
-
51
-
52
-
53
-
54
-
55
-
@@ -1,99 +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 { AssetAmount, HostAmount, Cur, Cursors, Writer, Writers } from "../Cursors.sol";
6
-
7
- string constant RDBTB = "redeemFromBalanceToBalances";
8
- string constant RDCTB = "redeemFromCustodyToBalances";
9
-
10
- using Cursors for Cur;
11
- using Writers for Writer;
12
-
13
- /// @title RedeemFromBalanceToBalances
14
- /// @notice Command that redeems BALANCE state positions into BALANCE outputs.
15
- /// The output-to-input ratio is set at construction via `scaledRatio`.
16
- abstract contract RedeemFromBalanceToBalances is CommandBase {
17
- uint internal immutable redeemFromBalanceToBalancesId = commandId(RDBTB);
18
- uint private immutable outScale;
19
-
20
- constructor(string memory input, uint scaledRatio) {
21
- outScale = scaledRatio;
22
- emit Command(host, RDBTB, input, redeemFromBalanceToBalancesId, State.Balances, State.Balances, false);
23
- }
24
-
25
- /// @dev Override to redeem a balance position into balances.
26
- /// `request` is the live auxiliary request cursor for this command.
27
- /// Implementations may consume it as needed or ignore it, and may append
28
- /// BALANCE outputs to `out` within the capacity implied by this command's
29
- /// configured `scaledRatio`.
30
- function redeemFromBalanceToBalances(
31
- bytes32 account,
32
- AssetAmount memory balance,
33
- Cur memory request,
34
- Writer memory out
35
- ) internal virtual;
36
-
37
- function redeemFromBalanceToBalances(
38
- CommandContext calldata c
39
- ) external onlyCommand(redeemFromBalanceToBalancesId, c.target) returns (bytes memory) {
40
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
41
- Cur memory request = cursor(c.request);
42
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
43
-
44
- while (state.i < state.bound) {
45
- AssetAmount memory balance = state.unpackBalanceValue();
46
- redeemFromBalanceToBalances(c.account, balance, request, writer);
47
- }
48
-
49
- return state.complete(writer);
50
- }
51
- }
52
-
53
- /// @title RedeemFromCustodyToBalances
54
- /// @notice Command that redeems CUSTODY state positions into BALANCE outputs.
55
- /// The output-to-input ratio is set at construction via `scaledRatio`.
56
- abstract contract RedeemFromCustodyToBalances is CommandBase {
57
- uint internal immutable redeemFromCustodyToBalancesId = commandId(RDCTB);
58
- uint private immutable outScale;
59
-
60
- constructor(string memory input, uint scaledRatio) {
61
- outScale = scaledRatio;
62
- emit Command(host, RDCTB, input, redeemFromCustodyToBalancesId, State.Custodies, State.Balances, false);
63
- }
64
-
65
- /// @dev Override to redeem a custody position into balances.
66
- /// `request` is the live auxiliary request cursor for this command.
67
- /// Implementations may consume it as needed or ignore it, and may append
68
- /// BALANCE outputs to `out` within the capacity implied by this command's
69
- /// configured `scaledRatio`.
70
- function redeemFromCustodyToBalances(
71
- bytes32 account,
72
- HostAmount memory custody,
73
- Cur memory request,
74
- Writer memory out
75
- ) internal virtual;
76
-
77
- function redeemFromCustodyToBalances(
78
- CommandContext calldata c
79
- ) external onlyCommand(redeemFromCustodyToBalancesId, c.target) returns (bytes memory) {
80
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
81
- Cur memory request = cursor(c.request);
82
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
83
-
84
- while (state.i < state.bound) {
85
- HostAmount memory custody = state.unpackCustodyValue();
86
- redeemFromCustodyToBalances(c.account, custody, request, writer);
87
- }
88
-
89
- return state.complete(writer);
90
- }
91
- }
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
@@ -1,99 +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 { AssetAmount, HostAmount, Cur, Cursors, Writer, Writers } from "../Cursors.sol";
6
-
7
- string constant RFBTB = "repayFromBalanceToBalances";
8
- string constant RFCTB = "repayFromCustodyToBalances";
9
-
10
- using Cursors for Cur;
11
- using Writers for Writer;
12
-
13
- /// @title RepayFromBalanceToBalances
14
- /// @notice Command that repays debt using BALANCE state blocks and emits BALANCE outputs.
15
- /// The output-to-input ratio is set at construction via `scaledRatio`.
16
- abstract contract RepayFromBalanceToBalances is CommandBase {
17
- uint internal immutable repayFromBalanceToBalancesId = commandId(RFBTB);
18
- uint private immutable outScale;
19
-
20
- constructor(string memory input, uint scaledRatio) {
21
- outScale = scaledRatio;
22
- emit Command(host, RFBTB, input, repayFromBalanceToBalancesId, State.Balances, State.Balances, false);
23
- }
24
-
25
- /// @dev Override to repay debt using a balance amount.
26
- /// `request` is the live auxiliary request cursor for this command.
27
- /// Implementations may consume it as needed or ignore it, and may append
28
- /// BALANCE outputs to `out` within the capacity implied by this command's
29
- /// configured `scaledRatio`.
30
- function repayFromBalanceToBalances(
31
- bytes32 account,
32
- AssetAmount memory balance,
33
- Cur memory request,
34
- Writer memory out
35
- ) internal virtual;
36
-
37
- function repayFromBalanceToBalances(
38
- CommandContext calldata c
39
- ) external onlyCommand(repayFromBalanceToBalancesId, c.target) returns (bytes memory) {
40
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
41
- Cur memory request = cursor(c.request);
42
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
43
-
44
- while (state.i < state.bound) {
45
- AssetAmount memory balance = state.unpackBalanceValue();
46
- repayFromBalanceToBalances(c.account, balance, request, writer);
47
- }
48
-
49
- return state.complete(writer);
50
- }
51
- }
52
-
53
- /// @title RepayFromCustodyToBalances
54
- /// @notice Command that repays debt using CUSTODY state blocks and emits BALANCE outputs.
55
- /// The output-to-input ratio is set at construction via `scaledRatio`.
56
- abstract contract RepayFromCustodyToBalances is CommandBase {
57
- uint internal immutable repayFromCustodyToBalancesId = commandId(RFCTB);
58
- uint private immutable outScale;
59
-
60
- constructor(string memory input, uint scaledRatio) {
61
- outScale = scaledRatio;
62
- emit Command(host, RFCTB, input, repayFromCustodyToBalancesId, State.Custodies, State.Balances, false);
63
- }
64
-
65
- /// @dev Override to repay debt using a custody amount.
66
- /// `request` is the live auxiliary request cursor for this command.
67
- /// Implementations may consume it as needed or ignore it, and may append
68
- /// BALANCE outputs to `out` within the capacity implied by this command's
69
- /// configured `scaledRatio`.
70
- function repayFromCustodyToBalances(
71
- bytes32 account,
72
- HostAmount memory custody,
73
- Cur memory request,
74
- Writer memory out
75
- ) internal virtual;
76
-
77
- function repayFromCustodyToBalances(
78
- CommandContext calldata c
79
- ) external onlyCommand(repayFromCustodyToBalancesId, c.target) returns (bytes memory) {
80
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
81
- Cur memory request = cursor(c.request);
82
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
83
-
84
- while (state.i < state.bound) {
85
- HostAmount memory custody = state.unpackCustodyValue();
86
- repayFromCustodyToBalances(c.account, custody, request, writer);
87
- }
88
-
89
- return state.complete(writer);
90
- }
91
- }
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
package/commands/Swap.sol DELETED
@@ -1,90 +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 { AssetAmount, Cur, Cursors, HostAmount, Writer, Writers } from "../Cursors.sol";
6
- using Cursors for Cur;
7
- using Writers for Writer;
8
-
9
- string constant SEBTB = "swapExactBalanceToBalance";
10
- string constant SECTB = "swapExactCustodyToBalance";
11
-
12
- /// @title SwapExactBalanceToBalance
13
- /// @notice Command that swaps each BALANCE state block into a new BALANCE output
14
- /// using a virtual hook. Each state balance is passed individually to `swapExactBalanceToBalance`.
15
- abstract contract SwapExactBalanceToBalance is CommandBase {
16
- uint internal immutable swapExactBalanceToBalanceId = commandId(SEBTB);
17
-
18
- constructor(string memory input) {
19
- emit Command(host, SEBTB, input, swapExactBalanceToBalanceId, State.Balances, State.Balances, false);
20
- }
21
-
22
- /// @dev Override to swap an exact balance input into a balance output.
23
- /// `request` is the live auxiliary request cursor for this command;
24
- /// implementations validate and unpack it as needed.
25
- function swapExactBalanceToBalance(
26
- bytes32 account,
27
- AssetAmount memory balance,
28
- Cur memory request
29
- ) internal virtual returns (AssetAmount memory out);
30
-
31
- function swapExactBalanceToBalance(
32
- CommandContext calldata c
33
- ) external onlyCommand(swapExactBalanceToBalanceId, c.target) returns (bytes memory) {
34
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
35
- Cur memory request = cursor(c.request);
36
- Writer memory writer = Writers.allocBalances(stateCount);
37
-
38
- while (state.i < state.bound) {
39
- AssetAmount memory balance = state.unpackBalanceValue();
40
- AssetAmount memory out = swapExactBalanceToBalance(c.account, balance, request);
41
- writer.appendNonZeroBalance(out);
42
- }
43
-
44
- return state.complete(writer);
45
- }
46
- }
47
-
48
- /// @title SwapExactCustodyToBalance
49
- /// @notice Command that swaps each CUSTODY state block into a BALANCE output
50
- /// using a virtual hook. Each custody position is passed individually to `swapExactCustodyToBalance`.
51
- abstract contract SwapExactCustodyToBalance is CommandBase {
52
- uint internal immutable swapExactCustodyToBalanceId = commandId(SECTB);
53
-
54
- constructor(string memory input) {
55
- emit Command(host, SECTB, input, swapExactCustodyToBalanceId, State.Custodies, State.Balances, false);
56
- }
57
-
58
- /// @dev Override to swap an exact custody input into a balance output.
59
- /// `request` is the live auxiliary request cursor for this command;
60
- /// implementations validate and unpack it as needed.
61
- function swapExactCustodyToBalance(
62
- bytes32 account,
63
- HostAmount memory custody,
64
- Cur memory request
65
- ) internal virtual returns (AssetAmount memory out);
66
-
67
- function swapExactCustodyToBalance(
68
- CommandContext calldata c
69
- ) external onlyCommand(swapExactCustodyToBalanceId, c.target) returns (bytes memory) {
70
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
71
- Cur memory request = cursor(c.request);
72
- Writer memory writer = Writers.allocBalances(stateCount);
73
-
74
- while (state.i < state.bound) {
75
- HostAmount memory custody = state.unpackCustodyValue();
76
- AssetAmount memory out = swapExactCustodyToBalance(c.account, custody, request);
77
- writer.appendNonZeroBalance(out);
78
- }
79
-
80
- return state.complete(writer);
81
- }
82
- }
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
@@ -1,58 +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 { AssetAmount, Cur, Cursors, Writer, Writers } from "../Cursors.sol";
6
-
7
- string constant UBTB = "unstakeBalanceToBalances";
8
-
9
- using Cursors for Cur;
10
- using Writers for Writer;
11
-
12
- /// @title UnstakeBalanceToBalances
13
- /// @notice Command that unstakes BALANCE state positions and emits BALANCE outputs.
14
- /// The output-to-input ratio is set at construction via `scaledRatio`.
15
- abstract contract UnstakeBalanceToBalances is CommandBase {
16
- uint internal immutable unstakeBalanceToBalancesId = commandId(UBTB);
17
- uint private immutable outScale;
18
-
19
- constructor(string memory input, uint scaledRatio) {
20
- outScale = scaledRatio;
21
- emit Command(host, UBTB, input, unstakeBalanceToBalancesId, State.Balances, State.Balances, false);
22
- }
23
-
24
- /// @dev Override to unstake or redeem a balance position.
25
- /// `request` is the live auxiliary request cursor for this command;
26
- /// implementations validate and unpack it as needed, and may append
27
- /// BALANCE outputs to `out` within the capacity implied by this
28
- /// command's configured `scaledRatio`.
29
- function unstakeBalanceToBalances(
30
- bytes32 account,
31
- AssetAmount memory balance,
32
- Cur memory request,
33
- Writer memory out
34
- ) internal virtual;
35
-
36
- function unstakeBalanceToBalances(
37
- CommandContext calldata c
38
- ) external onlyCommand(unstakeBalanceToBalancesId, c.target) returns (bytes memory) {
39
- (Cur memory state, uint stateCount, ) = cursor(c.state, 1);
40
- Cur memory request = cursor(c.request);
41
- Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
42
-
43
- while (state.i < state.bound) {
44
- AssetAmount memory balance = state.unpackBalanceValue();
45
- unstakeBalanceToBalances(c.account, balance, request, writer);
46
- }
47
-
48
- return state.complete(writer);
49
- }
50
- }
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
package/events/Quote.sol DELETED
@@ -1,21 +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 Quote(uint indexed host, uint cid, string schema)";
7
-
8
- /// @notice Emitted when a price quote or rate is published by a command.
9
- abstract contract QuoteEvent is EventEmitter {
10
- /// @param host Host node ID publishing the quote.
11
- /// @param cid Command ID associated with the quote.
12
- /// @param schema Schema string describing the quote's data layout.
13
- event Quote(uint indexed host, uint cid, string schema);
14
-
15
- constructor() {
16
- emit EventAbi(ABI);
17
- }
18
- }
19
-
20
-
21
-
File without changes