@rootzero/contracts 1.25.0 → 1.27.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.
- package/CHANGELOG.md +125 -0
- package/Codec.sol +1 -2
- package/Endpoints.sol +2 -0
- package/README.md +73 -51
- package/Utils.sol +2 -1
- package/codec/Blocks.sol +276 -88
- package/codec/Buffers.sol +24 -20
- package/codec/Decoders.sol +35 -37
- package/codec/Descriptors.sol +75 -72
- package/codec/Keys.sol +5 -1
- package/codec/Schema.sol +7 -1
- package/codec/Specs.sol +19 -9
- package/codec/Writers.sol +14 -19
- package/commands/Allocate.sol +8 -7
- package/commands/Base.sol +14 -49
- package/commands/Bootstrap.sol +81 -0
- package/commands/Burn.sol +7 -7
- package/commands/Cashout.sol +86 -0
- package/commands/Credit.sol +20 -17
- package/commands/Debit.sol +25 -20
- package/commands/Deposit.sol +13 -13
- package/commands/Payout.sol +8 -8
- package/commands/Provision.sol +13 -13
- package/commands/Recover.sol +7 -7
- package/commands/Relay.sol +22 -23
- package/commands/Repay.sol +38 -35
- package/commands/Settle.sol +26 -23
- package/commands/Withdraw.sol +7 -7
- package/commands/admin/AllowAssets.sol +7 -7
- package/commands/admin/Allowance.sol +7 -7
- package/commands/admin/Annotate.sol +7 -7
- package/commands/admin/Appoint.sol +7 -7
- package/commands/admin/Authorize.sol +7 -7
- package/commands/admin/Base.sol +5 -8
- package/commands/admin/DenyAssets.sol +7 -7
- package/commands/admin/Dismiss.sol +7 -7
- package/commands/admin/Execute.sol +8 -8
- package/commands/admin/Unauthorize.sol +7 -7
- package/core/Access.sol +1 -0
- package/core/Calls.sol +3 -3
- package/core/Endpoint.sol +7 -7
- package/core/Pipeline.sol +19 -23
- package/core/Settlement.sol +2 -1
- package/core/Types.sol +1 -0
- package/execution/Budget.sol +2 -3
- package/execution/Execution.sol +270 -511
- package/guards/Base.sol +1 -1
- package/guards/Revoke.sol +7 -7
- package/package.json +1 -1
- package/ports/Allowance.sol +3 -3
- package/ports/Assets.sol +7 -7
- package/ports/Base.sol +1 -1
- package/ports/Credit.sol +3 -3
- package/ports/Debit.sol +3 -3
- package/ports/Dispatch.sol +3 -3
- package/ports/Pipe.sol +3 -3
- package/ports/Post.sol +3 -3
- package/ports/Redeem.sol +3 -3
- package/queries/Assets.sol +3 -3
- package/queries/Balances.sol +3 -3
- package/queries/Base.sol +1 -1
- package/utils/Accounts.sol +17 -10
- package/utils/Actions.sol +2 -0
- package/utils/Assets.sol +1 -10
- package/utils/Cursors.sol +60 -116
- package/utils/Errors.sol +56 -0
- package/utils/Ids.sol +2 -5
- package/utils/Lanes.sol +0 -2
- package/utils/Nodes.sol +1 -3
- package/utils/Utils.sol +2 -9
- package/codec/Readers.sol +0 -190
package/commands/Provision.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {Execution, Executions, CommandBase, Flags, HostAmount,
|
|
4
|
+
import {Execution, Executions, CommandBase, Flags, HostAmount, Specs} from "./Base.sol";
|
|
5
5
|
using Executions for Execution;
|
|
6
6
|
|
|
7
7
|
/// @notice Shared provision hook used by `Provision`.
|
|
@@ -32,25 +32,25 @@ abstract contract Provision is CommandBase, ProvisionHook {
|
|
|
32
32
|
uint private immutable descriptor;
|
|
33
33
|
|
|
34
34
|
constructor() {
|
|
35
|
-
(, descriptor) = command("provision", Specs.Empty, Specs.Allocation, Specs.Custody, 0
|
|
35
|
+
(, descriptor) = command("provision", Specs.Empty, Specs.Allocation, Specs.Custody, 0);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/// @notice Provision ALLOCATION input blocks and output matching CUSTODY state blocks.
|
|
39
39
|
/// @param context Command context carrying the ALLOCATION input stream.
|
|
40
40
|
/// @return CUSTODY block stream matching the provisioned allocations.
|
|
41
|
-
/// @return
|
|
41
|
+
/// @return Zero native budget credit.
|
|
42
42
|
function provision(
|
|
43
43
|
bytes calldata context
|
|
44
|
-
) external onlyCommand returns (bytes memory,
|
|
45
|
-
Execution memory exec = openCommand(context, descriptor
|
|
44
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
45
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
46
46
|
|
|
47
47
|
while (exec.more()) {
|
|
48
|
-
HostAmount memory allocation = exec.unpackAllocationValue(
|
|
48
|
+
HostAmount memory allocation = exec.unpackAllocationValue();
|
|
49
49
|
provision(exec.account, allocation);
|
|
50
50
|
exec.outputCustody(allocation);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
return
|
|
53
|
+
return exec.close();
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -62,25 +62,25 @@ abstract contract ProvisionPayable is CommandBase, ProvisionPayableHook {
|
|
|
62
62
|
uint private immutable descriptor;
|
|
63
63
|
|
|
64
64
|
constructor() {
|
|
65
|
-
(, descriptor) = command("provisionPayable", Specs.Empty, Specs.Allocation, Specs.Custody,
|
|
65
|
+
(, descriptor) = command("provisionPayable", Specs.Empty, Specs.Allocation, Specs.Custody, Flags.Funded);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/// @notice Provision ALLOCATION input blocks with access to a mutable native-value budget.
|
|
69
69
|
/// @param context Command context carrying the ALLOCATION input stream.
|
|
70
70
|
/// @return CUSTODY block stream matching the provisioned allocations.
|
|
71
|
-
/// @return
|
|
71
|
+
/// @return Native value to add to the caller's budget.
|
|
72
72
|
function provisionPayable(
|
|
73
73
|
bytes calldata context
|
|
74
|
-
) external payable onlyCommand returns (bytes memory,
|
|
75
|
-
Execution memory exec = openCommand(context, descriptor
|
|
74
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
75
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
76
76
|
|
|
77
77
|
while (exec.more()) {
|
|
78
|
-
HostAmount memory allocation = exec.unpackAllocationValue(
|
|
78
|
+
HostAmount memory allocation = exec.unpackAllocationValue();
|
|
79
79
|
provision(exec.account, allocation, exec);
|
|
80
80
|
exec.outputCustody(allocation);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
return
|
|
83
|
+
return exec.close();
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
package/commands/Recover.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {Execution, Executions, CommandBase, Flags,
|
|
4
|
+
import {Execution, Executions, CommandBase, Flags, Specs} from "./Base.sol";
|
|
5
5
|
|
|
6
6
|
using Executions for Execution;
|
|
7
7
|
|
|
@@ -31,23 +31,23 @@ abstract contract RecoverPayable is CommandBase, RecoverPayableHook {
|
|
|
31
31
|
uint private immutable descriptor;
|
|
32
32
|
|
|
33
33
|
constructor() {
|
|
34
|
-
(, descriptor) = command("recoverPayable", Specs.Empty, Specs.Recover, Specs.Empty,
|
|
34
|
+
(, descriptor) = command("recoverPayable", Specs.Empty, Specs.Recover, Specs.Empty, Flags.Funded);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/// @notice Recover each recover block in the command input.
|
|
38
38
|
/// @param context Command context carrying the RECOVER input stream.
|
|
39
39
|
/// @return Empty output state.
|
|
40
|
-
/// @return
|
|
40
|
+
/// @return Native value to add to the caller's budget.
|
|
41
41
|
function recoverPayable(
|
|
42
42
|
bytes calldata context
|
|
43
|
-
) external payable onlyCommand returns (bytes memory,
|
|
44
|
-
Execution memory exec = openCommand(context, descriptor
|
|
43
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
44
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
45
45
|
|
|
46
46
|
while (exec.more()) {
|
|
47
|
-
(uint handler, uint resources, bytes32 key, bytes calldata witness) = exec.unpackRecover(
|
|
47
|
+
(uint handler, uint resources, bytes32 key, bytes calldata witness) = exec.unpackRecover();
|
|
48
48
|
recover(handler, resources, key, witness, exec);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
return
|
|
51
|
+
return exec.close();
|
|
52
52
|
}
|
|
53
53
|
}
|
package/commands/Relay.sol
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {Execution, Executions, CommandBase, Flags,
|
|
4
|
+
import {Execution, Executions, CommandBase, Flags, Specs} from "./Base.sol";
|
|
5
5
|
|
|
6
6
|
using Executions for Execution;
|
|
7
7
|
|
|
8
8
|
/// @notice Hook implemented by hosts that relay command contexts.
|
|
9
9
|
abstract contract RelayPayableHook {
|
|
10
10
|
/// @notice Override to relay a command context to `portal`.
|
|
11
|
+
/// @dev Relay hooks may forward only EMPTY or BALANCE state. They must not
|
|
12
|
+
/// relay DEBT, POSITION, or other state whose destination handling can fail:
|
|
13
|
+
/// the source state is consumed before destination success is known.
|
|
11
14
|
/// @param portal Destination portal implementation's host ID. Implementations
|
|
12
15
|
/// may validate or resolve it for their transport.
|
|
13
16
|
/// @param resources Chain-specific destination resources. EVM adapters
|
|
14
17
|
/// may interpret this as packed execution gas and destination value.
|
|
15
18
|
/// @param account Destination command account.
|
|
19
|
+
/// @param state Complete state forwarded into the destination context.
|
|
16
20
|
/// @param input Input forwarded into the destination context.
|
|
17
|
-
/// @param
|
|
18
|
-
///
|
|
21
|
+
/// @param funds Execution carrying value available for transport fees and
|
|
22
|
+
/// destination resource funding.
|
|
19
23
|
function relay(
|
|
20
24
|
uint portal,
|
|
21
25
|
uint resources,
|
|
22
26
|
bytes32 account,
|
|
27
|
+
bytes calldata state,
|
|
23
28
|
bytes calldata input,
|
|
24
|
-
Execution memory
|
|
29
|
+
Execution memory funds
|
|
25
30
|
) internal virtual;
|
|
26
31
|
}
|
|
27
32
|
|
|
@@ -31,18 +36,15 @@ abstract contract RelayPayable is CommandBase, RelayPayableHook {
|
|
|
31
36
|
uint private immutable descriptor;
|
|
32
37
|
|
|
33
38
|
constructor() {
|
|
34
|
-
(, descriptor) = command("relayPayable", Specs.Empty, Specs.Relay, Specs.Empty,
|
|
39
|
+
(, descriptor) = command("relayPayable", Specs.Empty, Specs.Relay, Specs.Empty, Flags.Funded);
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
/// @notice Relay one RELAY input block with the command account and empty state.
|
|
38
|
-
function relayPayable(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
relay(portal, resources, exec.account, input, exec);
|
|
44
|
-
|
|
45
|
-
return closeCommand(exec);
|
|
43
|
+
function relayPayable(bytes calldata context) external payable onlyCommand returns (bytes memory, uint) {
|
|
44
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
45
|
+
(uint portal, uint resources, bytes calldata input) = exec.oninput().unpackRelay();
|
|
46
|
+
relay(portal, resources, exec.account, context[0:0], input, exec);
|
|
47
|
+
return exec.close();
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -55,20 +57,17 @@ abstract contract RelayBalancePayable is CommandBase, RelayPayableHook {
|
|
|
55
57
|
uint private immutable descriptor;
|
|
56
58
|
|
|
57
59
|
constructor() {
|
|
58
|
-
(, descriptor) = command("relayBalancePayable", Specs.Balance, Specs.Relay, Specs.Empty,
|
|
60
|
+
(, descriptor) = command("relayBalancePayable", Specs.Balance, Specs.Relay, Specs.Empty, Flags.Funded);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/// @notice Relay one RELAY input block with the command account and current state.
|
|
62
64
|
/// @param context Command context carrying state and exactly one RELAY input block.
|
|
63
65
|
/// @return Empty output state.
|
|
64
|
-
/// @return
|
|
65
|
-
function relayBalancePayable(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
relay(portal, resources, exec.account, input, exec);
|
|
71
|
-
|
|
72
|
-
return closeCommand(exec);
|
|
66
|
+
/// @return Native value to add to the caller's budget.
|
|
67
|
+
function relayBalancePayable(bytes calldata context) external payable onlyCommand returns (bytes memory, uint) {
|
|
68
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
69
|
+
(uint portal, uint resources, bytes calldata input) = exec.oninput().unpackRelay();
|
|
70
|
+
relay(portal, resources, exec.account, exec.takeRawState(), input, exec);
|
|
71
|
+
return exec.close();
|
|
73
72
|
}
|
|
74
73
|
}
|
package/commands/Repay.sol
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {Execution, Executions, CommandBase, Flags,
|
|
4
|
+
import {Execution, Executions, CommandBase, Flags, Specs} from "./Base.sol";
|
|
5
5
|
import {RepayHook} from "../core/Settlement.sol";
|
|
6
6
|
import {Action} from "../annotations/Action.sol";
|
|
7
7
|
import {Actions} from "../utils/Actions.sol";
|
|
8
|
-
import {Blocks} from "../codec/Blocks.sol";
|
|
9
|
-
import {
|
|
8
|
+
import {Blocks, Memory} from "../codec/Blocks.sol";
|
|
9
|
+
import {Sizes} from "../codec/Specs.sol";
|
|
10
|
+
import {UnexpectedInput} from "../utils/Errors.sol";
|
|
10
11
|
|
|
11
12
|
using Executions for Execution;
|
|
12
|
-
using Readers for Reader;
|
|
13
13
|
|
|
14
14
|
/// @notice Hook implemented by hosts that repay liabilities using native value.
|
|
15
15
|
abstract contract RepayPayableHook {
|
|
@@ -28,7 +28,7 @@ abstract contract Repay is CommandBase, RepayHook, Action {
|
|
|
28
28
|
uint private immutable id;
|
|
29
29
|
|
|
30
30
|
constructor() {
|
|
31
|
-
(id, descriptor) = command("repay", Specs.Debt, Specs.Empty, Specs.Empty, 0
|
|
31
|
+
(id, descriptor) = command("repay", Specs.Debt, Specs.Empty, Specs.Empty, 0);
|
|
32
32
|
action(id, Actions.Repay);
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -40,18 +40,18 @@ abstract contract Repay is CommandBase, RepayHook, Action {
|
|
|
40
40
|
/// @notice Repay each liability in the DEBT state stream.
|
|
41
41
|
/// @param context Command context carrying the DEBT state stream.
|
|
42
42
|
/// @return Empty output state.
|
|
43
|
-
/// @return
|
|
43
|
+
/// @return Zero native budget credit.
|
|
44
44
|
function repay(
|
|
45
45
|
bytes calldata context
|
|
46
|
-
) external onlyCommand returns (bytes memory,
|
|
47
|
-
Execution memory exec = openCommand(context, descriptor
|
|
46
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
47
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
48
48
|
|
|
49
49
|
while (exec.more()) {
|
|
50
|
-
(bytes32 liability, uint debt) = exec.unpackDebt(
|
|
50
|
+
(bytes32 liability, uint debt) = exec.unpackDebt();
|
|
51
51
|
repay(exec.account, liability, debt);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
return
|
|
54
|
+
return exec.close();
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -62,25 +62,25 @@ abstract contract RepayPayable is CommandBase, RepayPayableHook, Action {
|
|
|
62
62
|
|
|
63
63
|
constructor() {
|
|
64
64
|
uint id;
|
|
65
|
-
(id, descriptor) = command("repayPayable", Specs.Debt, Specs.Empty, Specs.Empty,
|
|
65
|
+
(id, descriptor) = command("repayPayable", Specs.Debt, Specs.Empty, Specs.Empty, Flags.Funded);
|
|
66
66
|
action(id, Actions.Repay);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/// @notice Repay each liability in the DEBT state stream.
|
|
70
70
|
/// @param context Command context carrying the DEBT state stream.
|
|
71
71
|
/// @return Empty output state.
|
|
72
|
-
/// @return
|
|
72
|
+
/// @return Native value to add to the caller's budget.
|
|
73
73
|
function repayPayable(
|
|
74
74
|
bytes calldata context
|
|
75
|
-
) external payable onlyCommand returns (bytes memory,
|
|
76
|
-
Execution memory exec = openCommand(context, descriptor
|
|
75
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
76
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
77
77
|
|
|
78
78
|
while (exec.more()) {
|
|
79
|
-
(bytes32 liability, uint debt) = exec.unpackDebt(
|
|
79
|
+
(bytes32 liability, uint debt) = exec.unpackDebt();
|
|
80
80
|
repay(exec.account, liability, debt, exec);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
return
|
|
83
|
+
return exec.close();
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -91,26 +91,26 @@ abstract contract RepayPosition is CommandBase, RepayHook, Action {
|
|
|
91
91
|
|
|
92
92
|
constructor() {
|
|
93
93
|
uint id;
|
|
94
|
-
(id, descriptor) = command("repayPosition", Specs.Position, Specs.Empty, Specs.Balance, 0
|
|
94
|
+
(id, descriptor) = command("repayPosition", Specs.Position, Specs.Empty, Specs.Balance, 0);
|
|
95
95
|
action(id, Actions.Repay);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/// @notice Repay each POSITION liability and return its asset as BALANCE state.
|
|
99
99
|
/// @param context Command context carrying the POSITION state stream.
|
|
100
100
|
/// @return BALANCE output state containing each released asset side.
|
|
101
|
-
/// @return
|
|
101
|
+
/// @return Zero native budget credit.
|
|
102
102
|
function repayPosition(
|
|
103
103
|
bytes calldata context
|
|
104
|
-
) external onlyCommand returns (bytes memory,
|
|
105
|
-
Execution memory exec = openCommand(context, descriptor
|
|
104
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
105
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
106
106
|
|
|
107
107
|
while (exec.more()) {
|
|
108
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
108
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
109
109
|
repay(exec.account, liability, debt);
|
|
110
110
|
exec.outputBalance(asset, amount);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
return
|
|
113
|
+
return exec.close();
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -122,7 +122,7 @@ abstract contract RepayPositionPayable is CommandBase, RepayPayableHook, Action
|
|
|
122
122
|
constructor() {
|
|
123
123
|
uint id;
|
|
124
124
|
(id, descriptor) = command(
|
|
125
|
-
"repayPositionPayable", Specs.Position, Specs.Empty, Specs.Balance,
|
|
125
|
+
"repayPositionPayable", Specs.Position, Specs.Empty, Specs.Balance, Flags.Funded
|
|
126
126
|
);
|
|
127
127
|
action(id, Actions.Repay);
|
|
128
128
|
}
|
|
@@ -130,19 +130,19 @@ abstract contract RepayPositionPayable is CommandBase, RepayPayableHook, Action
|
|
|
130
130
|
/// @notice Repay each POSITION liability and return its asset as BALANCE state.
|
|
131
131
|
/// @param context Command context carrying the POSITION state stream.
|
|
132
132
|
/// @return BALANCE output state containing each released asset side.
|
|
133
|
-
/// @return
|
|
133
|
+
/// @return Native value to add to the caller's budget.
|
|
134
134
|
function repayPositionPayable(
|
|
135
135
|
bytes calldata context
|
|
136
|
-
) external payable onlyCommand returns (bytes memory,
|
|
137
|
-
Execution memory exec = openCommand(context, descriptor
|
|
136
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
137
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
138
138
|
|
|
139
139
|
while (exec.more()) {
|
|
140
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
140
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
141
141
|
repay(exec.account, liability, debt, exec);
|
|
142
142
|
exec.outputBalance(asset, amount);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
return
|
|
145
|
+
return exec.close();
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -157,23 +157,26 @@ abstract contract RepayInternal is Repay {
|
|
|
157
157
|
/// @param input Empty input required by the command schema.
|
|
158
158
|
/// @param value Native value assigned to the command; must be zero.
|
|
159
159
|
/// @return output Empty output state.
|
|
160
|
-
/// @return
|
|
160
|
+
/// @return credit Zero native budget credit.
|
|
161
161
|
function executeRepay(
|
|
162
162
|
bytes32 account,
|
|
163
163
|
bytes memory state,
|
|
164
164
|
bytes calldata input,
|
|
165
165
|
uint128 value
|
|
166
|
-
) internal returns (bytes memory,
|
|
166
|
+
) internal returns (bytes memory, uint) {
|
|
167
167
|
if (value != 0) revert ValueNotAllowed();
|
|
168
|
-
if (input.length != 0) revert
|
|
168
|
+
if (input.length != 0) revert UnexpectedInput();
|
|
169
169
|
if (state.length == 0) revert Blocks.EmptyRun();
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
while (
|
|
173
|
-
(bytes32 liability, uint debt) =
|
|
171
|
+
(uint abs, uint end) = Memory.bounds(state, Sizes.Debt);
|
|
172
|
+
while (abs < end) {
|
|
173
|
+
(bytes32 liability, uint debt) = Memory.unpackDebt(abs);
|
|
174
174
|
repay(account, liability, debt);
|
|
175
|
+
unchecked {
|
|
176
|
+
abs += Sizes.Debt;
|
|
177
|
+
}
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
return ("",
|
|
180
|
+
return ("", 0);
|
|
178
181
|
}
|
|
179
182
|
}
|
package/commands/Settle.sol
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {Execution, Executions, CommandBase, Flags,
|
|
4
|
+
import {Execution, Executions, CommandBase, Flags, Specs} from "./Base.sol";
|
|
5
5
|
import {SettleHook} from "../core/Settlement.sol";
|
|
6
6
|
import {Action} from "../annotations/Action.sol";
|
|
7
7
|
import {Actions} from "../utils/Actions.sol";
|
|
8
|
-
import {Blocks} from "../codec/Blocks.sol";
|
|
9
|
-
import {
|
|
8
|
+
import {Blocks, Memory} from "../codec/Blocks.sol";
|
|
9
|
+
import {Sizes} from "../codec/Specs.sol";
|
|
10
|
+
import {UnexpectedInput} from "../utils/Errors.sol";
|
|
10
11
|
|
|
11
12
|
using Executions for Execution;
|
|
12
|
-
using Readers for Reader;
|
|
13
13
|
|
|
14
14
|
/// @notice Hook implemented by hosts that settle positions using native value.
|
|
15
15
|
abstract contract SettlePayableHook {
|
|
@@ -37,7 +37,7 @@ abstract contract Settle is CommandBase, SettleHook, Action {
|
|
|
37
37
|
uint private immutable id;
|
|
38
38
|
|
|
39
39
|
constructor() {
|
|
40
|
-
(id, descriptor) = command("settle", Specs.Position, Specs.Empty, Specs.Empty, 0
|
|
40
|
+
(id, descriptor) = command("settle", Specs.Position, Specs.Empty, Specs.Empty, 0);
|
|
41
41
|
action(id, Actions.Settle);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -49,18 +49,18 @@ abstract contract Settle is CommandBase, SettleHook, Action {
|
|
|
49
49
|
/// @notice Settle each POSITION block from the command state.
|
|
50
50
|
/// @param context Command context carrying the POSITION state stream.
|
|
51
51
|
/// @return Empty output state.
|
|
52
|
-
/// @return
|
|
52
|
+
/// @return Zero native budget credit.
|
|
53
53
|
function settle(
|
|
54
54
|
bytes calldata context
|
|
55
|
-
) external onlyCommand returns (bytes memory,
|
|
56
|
-
Execution memory exec = openCommand(context, descriptor
|
|
55
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
56
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
57
57
|
|
|
58
58
|
while (exec.more()) {
|
|
59
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
59
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
60
60
|
settle(exec.account, asset, amount, liability, debt);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
return
|
|
63
|
+
return exec.close();
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -71,25 +71,25 @@ abstract contract SettlePayable is CommandBase, SettlePayableHook, Action {
|
|
|
71
71
|
|
|
72
72
|
constructor() {
|
|
73
73
|
uint id;
|
|
74
|
-
(id, descriptor) = command("settlePayable", Specs.Position, Specs.Empty, Specs.Empty,
|
|
74
|
+
(id, descriptor) = command("settlePayable", Specs.Position, Specs.Empty, Specs.Empty, Flags.Funded);
|
|
75
75
|
action(id, Actions.Settle);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/// @notice Settle each POSITION block with access to a shared native-value budget.
|
|
79
79
|
/// @param context Command context carrying the POSITION state stream.
|
|
80
80
|
/// @return Empty output state.
|
|
81
|
-
/// @return
|
|
81
|
+
/// @return Native value to add to the caller's budget.
|
|
82
82
|
function settlePayable(
|
|
83
83
|
bytes calldata context
|
|
84
|
-
) external payable onlyCommand returns (bytes memory,
|
|
85
|
-
Execution memory exec = openCommand(context, descriptor
|
|
84
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
85
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
86
86
|
|
|
87
87
|
while (exec.more()) {
|
|
88
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
88
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
89
89
|
settle(exec.account, asset, amount, liability, debt, exec);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
return
|
|
92
|
+
return exec.close();
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -104,23 +104,26 @@ abstract contract SettleInternal is Settle {
|
|
|
104
104
|
/// @param input Empty input required by the command schema.
|
|
105
105
|
/// @param value Native value assigned to the command; must be zero.
|
|
106
106
|
/// @return output Empty output state.
|
|
107
|
-
/// @return
|
|
107
|
+
/// @return credit Zero native budget credit.
|
|
108
108
|
function executeSettle(
|
|
109
109
|
bytes32 account,
|
|
110
110
|
bytes memory state,
|
|
111
111
|
bytes calldata input,
|
|
112
112
|
uint128 value
|
|
113
|
-
) internal returns (bytes memory,
|
|
113
|
+
) internal returns (bytes memory, uint) {
|
|
114
114
|
if (value != 0) revert ValueNotAllowed();
|
|
115
|
-
if (input.length != 0) revert
|
|
115
|
+
if (input.length != 0) revert UnexpectedInput();
|
|
116
116
|
if (state.length == 0) revert Blocks.EmptyRun();
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
while (
|
|
120
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) =
|
|
118
|
+
(uint abs, uint end) = Memory.bounds(state, Sizes.Position);
|
|
119
|
+
while (abs < end) {
|
|
120
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = Memory.unpackPosition(abs);
|
|
121
121
|
settle(account, asset, amount, liability, debt);
|
|
122
|
+
unchecked {
|
|
123
|
+
abs += Sizes.Position;
|
|
124
|
+
}
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
return ("",
|
|
127
|
+
return ("", 0);
|
|
125
128
|
}
|
|
126
129
|
}
|
package/commands/Withdraw.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {Execution, Executions, CommandBase,
|
|
4
|
+
import {Execution, Executions, CommandBase, Specs} from "./Base.sol";
|
|
5
5
|
import {Action} from "../annotations/Action.sol";
|
|
6
6
|
import {Actions} from "../utils/Actions.sol";
|
|
7
7
|
using Executions for Execution;
|
|
@@ -25,24 +25,24 @@ abstract contract Withdraw is CommandBase, WithdrawHook, Action {
|
|
|
25
25
|
|
|
26
26
|
constructor() {
|
|
27
27
|
uint id;
|
|
28
|
-
(id, descriptor) = command("withdraw", Specs.Balance, Specs.Empty, Specs.Empty, 0
|
|
28
|
+
(id, descriptor) = command("withdraw", Specs.Balance, Specs.Empty, Specs.Empty, 0);
|
|
29
29
|
action(id, Actions.Withdraw);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/// @notice Withdraw each BALANCE block from the command state to the command account.
|
|
33
33
|
/// @param context Command context carrying the BALANCE state stream.
|
|
34
34
|
/// @return Empty output state.
|
|
35
|
-
/// @return
|
|
35
|
+
/// @return Zero native budget credit.
|
|
36
36
|
function withdraw(
|
|
37
37
|
bytes calldata context
|
|
38
|
-
) external onlyCommand returns (bytes memory,
|
|
39
|
-
Execution memory exec = openCommand(context, descriptor
|
|
38
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
39
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
40
40
|
|
|
41
41
|
while (exec.more()) {
|
|
42
|
-
(bytes32 asset, uint amount) = exec.unpackBalance(
|
|
42
|
+
(bytes32 asset, uint amount) = exec.unpackBalance();
|
|
43
43
|
withdraw(exec.account, asset, amount);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
return
|
|
46
|
+
return exec.close();
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import { AdminBase, Execution, Executions, Flags,
|
|
4
|
+
import { AdminBase, Execution, Executions, Flags, Specs } from "./Base.sol";
|
|
5
5
|
using Executions for Execution;
|
|
6
6
|
|
|
7
7
|
/// @notice Hook implemented by hosts that allow assets.
|
|
@@ -19,24 +19,24 @@ abstract contract AllowAssets is AdminBase, AllowAssetsHook {
|
|
|
19
19
|
uint private immutable descriptor;
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
|
-
(, descriptor) = command("allowAssets", Specs.Empty, Specs.Asset, Specs.Empty,
|
|
22
|
+
(, descriptor) = command("allowAssets", Specs.Empty, Specs.Asset, Specs.Empty, Flags.Admin);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/// @notice Allow each ASSET block in the admin input.
|
|
26
26
|
/// @param context Admin command context carrying the ASSET input stream.
|
|
27
27
|
/// @return Empty output state.
|
|
28
|
-
/// @return
|
|
28
|
+
/// @return Zero native budget credit.
|
|
29
29
|
function allowAssets(
|
|
30
30
|
bytes calldata context
|
|
31
|
-
) external returns (bytes memory,
|
|
32
|
-
Execution memory exec = openAdminCommand(context, descriptor
|
|
31
|
+
) external returns (bytes memory, uint) {
|
|
32
|
+
Execution memory exec = openAdminCommand(context, descriptor);
|
|
33
33
|
|
|
34
34
|
while (exec.more()) {
|
|
35
|
-
bytes32 asset = exec.unpackAsset(
|
|
35
|
+
bytes32 asset = exec.unpackAsset();
|
|
36
36
|
allowAsset(asset);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
return
|
|
39
|
+
return exec.close();
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {AdminBase, Execution, Executions, Flags,
|
|
4
|
+
import {AdminBase, Execution, Executions, Flags, Specs} from "./Base.sol";
|
|
5
5
|
using Executions for Execution;
|
|
6
6
|
|
|
7
7
|
/// @notice Hook implemented by hosts that configure peer asset allowances.
|
|
@@ -23,23 +23,23 @@ abstract contract Allowance is AdminBase, AllowanceHook {
|
|
|
23
23
|
uint private immutable descriptor;
|
|
24
24
|
|
|
25
25
|
constructor() {
|
|
26
|
-
(, descriptor) = command("allowance", Specs.Empty, Specs.Allowance, Specs.Empty,
|
|
26
|
+
(, descriptor) = command("allowance", Specs.Empty, Specs.Allowance, Specs.Empty, Flags.Admin);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/// @notice Apply each ALLOWANCE block in the admin input.
|
|
30
30
|
/// @param context Admin command context carrying the ALLOWANCE input stream.
|
|
31
31
|
/// @return Empty output state.
|
|
32
|
-
/// @return
|
|
32
|
+
/// @return Zero native budget credit.
|
|
33
33
|
function allowance(
|
|
34
34
|
bytes calldata context
|
|
35
|
-
) external returns (bytes memory,
|
|
36
|
-
Execution memory exec = openAdminCommand(context, descriptor
|
|
35
|
+
) external returns (bytes memory, uint) {
|
|
36
|
+
Execution memory exec = openAdminCommand(context, descriptor);
|
|
37
37
|
|
|
38
38
|
while (exec.more()) {
|
|
39
|
-
(uint peer, bytes32 asset, uint amount) = exec.unpackAllowance(
|
|
39
|
+
(uint peer, bytes32 asset, uint amount) = exec.unpackAllowance();
|
|
40
40
|
allowance(peer, asset, amount);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
return
|
|
43
|
+
return exec.close();
|
|
44
44
|
}
|
|
45
45
|
}
|