@rootzero/contracts 1.25.0 → 1.26.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 +101 -0
- package/Codec.sol +1 -2
- package/Endpoints.sol +2 -0
- package/README.md +61 -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 +5 -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 +95 -0
- package/commands/Burn.sol +7 -7
- package/commands/Cashout.sol +85 -0
- package/commands/Credit.sol +18 -16
- package/commands/Debit.sol +23 -19
- 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 +36 -34
- package/commands/Settle.sol +24 -22
- 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/Calls.sol +3 -3
- package/core/Endpoint.sol +7 -7
- package/core/Pipeline.sol +19 -20
- package/execution/Budget.sol +2 -3
- package/execution/Execution.sol +271 -509
- 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 +1 -3
- package/utils/Actions.sol +2 -0
- package/utils/Assets.sol +1 -10
- package/utils/Cursors.sol +60 -116
- package/utils/Errors.sol +50 -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/Payout.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
|
|
|
@@ -26,24 +26,24 @@ abstract contract Payout is CommandBase, PayoutHook, Action {
|
|
|
26
26
|
|
|
27
27
|
constructor() {
|
|
28
28
|
uint id;
|
|
29
|
-
(id, descriptor) = command("payout", Specs.Balance, Specs.Account, Specs.Empty, 0
|
|
29
|
+
(id, descriptor) = command("payout", Specs.Balance, Specs.Account, Specs.Empty, 0);
|
|
30
30
|
action(id, Actions.Payout);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/// @notice Pay out BALANCE state blocks to matching ACCOUNT input blocks.
|
|
34
34
|
/// @param context Command context carrying BALANCE state and matching ACCOUNT input.
|
|
35
35
|
/// @return Empty output state.
|
|
36
|
-
/// @return
|
|
36
|
+
/// @return Zero native budget credit.
|
|
37
37
|
function payout(
|
|
38
38
|
bytes calldata context
|
|
39
|
-
) external onlyCommand returns (bytes memory,
|
|
40
|
-
Execution memory exec = openCommand(context, descriptor
|
|
39
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
40
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
41
41
|
|
|
42
42
|
while (exec.more()) {
|
|
43
|
-
(bytes32 asset, uint amount) = exec.unpackBalance(
|
|
44
|
-
payout(exec.account, exec.unpackAccount(
|
|
43
|
+
(bytes32 asset, uint amount) = exec.onstate().unpackBalance();
|
|
44
|
+
payout(exec.account, exec.oninput().unpackAccount(), asset, amount);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
return
|
|
47
|
+
return exec.close();
|
|
48
48
|
}
|
|
49
49
|
}
|
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,14 @@
|
|
|
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
10
|
|
|
11
11
|
using Executions for Execution;
|
|
12
|
-
using Readers for Reader;
|
|
13
12
|
|
|
14
13
|
/// @notice Hook implemented by hosts that repay liabilities using native value.
|
|
15
14
|
abstract contract RepayPayableHook {
|
|
@@ -28,7 +27,7 @@ abstract contract Repay is CommandBase, RepayHook, Action {
|
|
|
28
27
|
uint private immutable id;
|
|
29
28
|
|
|
30
29
|
constructor() {
|
|
31
|
-
(id, descriptor) = command("repay", Specs.Debt, Specs.Empty, Specs.Empty, 0
|
|
30
|
+
(id, descriptor) = command("repay", Specs.Debt, Specs.Empty, Specs.Empty, 0);
|
|
32
31
|
action(id, Actions.Repay);
|
|
33
32
|
}
|
|
34
33
|
|
|
@@ -40,18 +39,18 @@ abstract contract Repay is CommandBase, RepayHook, Action {
|
|
|
40
39
|
/// @notice Repay each liability in the DEBT state stream.
|
|
41
40
|
/// @param context Command context carrying the DEBT state stream.
|
|
42
41
|
/// @return Empty output state.
|
|
43
|
-
/// @return
|
|
42
|
+
/// @return Zero native budget credit.
|
|
44
43
|
function repay(
|
|
45
44
|
bytes calldata context
|
|
46
|
-
) external onlyCommand returns (bytes memory,
|
|
47
|
-
Execution memory exec = openCommand(context, descriptor
|
|
45
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
46
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
48
47
|
|
|
49
48
|
while (exec.more()) {
|
|
50
|
-
(bytes32 liability, uint debt) = exec.unpackDebt(
|
|
49
|
+
(bytes32 liability, uint debt) = exec.unpackDebt();
|
|
51
50
|
repay(exec.account, liability, debt);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
return
|
|
53
|
+
return exec.close();
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
|
|
@@ -62,25 +61,25 @@ abstract contract RepayPayable is CommandBase, RepayPayableHook, Action {
|
|
|
62
61
|
|
|
63
62
|
constructor() {
|
|
64
63
|
uint id;
|
|
65
|
-
(id, descriptor) = command("repayPayable", Specs.Debt, Specs.Empty, Specs.Empty,
|
|
64
|
+
(id, descriptor) = command("repayPayable", Specs.Debt, Specs.Empty, Specs.Empty, Flags.Funded);
|
|
66
65
|
action(id, Actions.Repay);
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
/// @notice Repay each liability in the DEBT state stream.
|
|
70
69
|
/// @param context Command context carrying the DEBT state stream.
|
|
71
70
|
/// @return Empty output state.
|
|
72
|
-
/// @return
|
|
71
|
+
/// @return Native value to add to the caller's budget.
|
|
73
72
|
function repayPayable(
|
|
74
73
|
bytes calldata context
|
|
75
|
-
) external payable onlyCommand returns (bytes memory,
|
|
76
|
-
Execution memory exec = openCommand(context, descriptor
|
|
74
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
75
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
77
76
|
|
|
78
77
|
while (exec.more()) {
|
|
79
|
-
(bytes32 liability, uint debt) = exec.unpackDebt(
|
|
78
|
+
(bytes32 liability, uint debt) = exec.unpackDebt();
|
|
80
79
|
repay(exec.account, liability, debt, exec);
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
return
|
|
82
|
+
return exec.close();
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
|
|
@@ -91,26 +90,26 @@ abstract contract RepayPosition is CommandBase, RepayHook, Action {
|
|
|
91
90
|
|
|
92
91
|
constructor() {
|
|
93
92
|
uint id;
|
|
94
|
-
(id, descriptor) = command("repayPosition", Specs.Position, Specs.Empty, Specs.Balance, 0
|
|
93
|
+
(id, descriptor) = command("repayPosition", Specs.Position, Specs.Empty, Specs.Balance, 0);
|
|
95
94
|
action(id, Actions.Repay);
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
/// @notice Repay each POSITION liability and return its asset as BALANCE state.
|
|
99
98
|
/// @param context Command context carrying the POSITION state stream.
|
|
100
99
|
/// @return BALANCE output state containing each released asset side.
|
|
101
|
-
/// @return
|
|
100
|
+
/// @return Zero native budget credit.
|
|
102
101
|
function repayPosition(
|
|
103
102
|
bytes calldata context
|
|
104
|
-
) external onlyCommand returns (bytes memory,
|
|
105
|
-
Execution memory exec = openCommand(context, descriptor
|
|
103
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
104
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
106
105
|
|
|
107
106
|
while (exec.more()) {
|
|
108
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
107
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
109
108
|
repay(exec.account, liability, debt);
|
|
110
109
|
exec.outputBalance(asset, amount);
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
return
|
|
112
|
+
return exec.close();
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
115
|
|
|
@@ -122,7 +121,7 @@ abstract contract RepayPositionPayable is CommandBase, RepayPayableHook, Action
|
|
|
122
121
|
constructor() {
|
|
123
122
|
uint id;
|
|
124
123
|
(id, descriptor) = command(
|
|
125
|
-
"repayPositionPayable", Specs.Position, Specs.Empty, Specs.Balance,
|
|
124
|
+
"repayPositionPayable", Specs.Position, Specs.Empty, Specs.Balance, Flags.Funded
|
|
126
125
|
);
|
|
127
126
|
action(id, Actions.Repay);
|
|
128
127
|
}
|
|
@@ -130,19 +129,19 @@ abstract contract RepayPositionPayable is CommandBase, RepayPayableHook, Action
|
|
|
130
129
|
/// @notice Repay each POSITION liability and return its asset as BALANCE state.
|
|
131
130
|
/// @param context Command context carrying the POSITION state stream.
|
|
132
131
|
/// @return BALANCE output state containing each released asset side.
|
|
133
|
-
/// @return
|
|
132
|
+
/// @return Native value to add to the caller's budget.
|
|
134
133
|
function repayPositionPayable(
|
|
135
134
|
bytes calldata context
|
|
136
|
-
) external payable onlyCommand returns (bytes memory,
|
|
137
|
-
Execution memory exec = openCommand(context, descriptor
|
|
135
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
136
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
138
137
|
|
|
139
138
|
while (exec.more()) {
|
|
140
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
139
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
141
140
|
repay(exec.account, liability, debt, exec);
|
|
142
141
|
exec.outputBalance(asset, amount);
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
return
|
|
144
|
+
return exec.close();
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
|
|
@@ -157,23 +156,26 @@ abstract contract RepayInternal is Repay {
|
|
|
157
156
|
/// @param input Empty input required by the command schema.
|
|
158
157
|
/// @param value Native value assigned to the command; must be zero.
|
|
159
158
|
/// @return output Empty output state.
|
|
160
|
-
/// @return
|
|
159
|
+
/// @return credit Zero native budget credit.
|
|
161
160
|
function executeRepay(
|
|
162
161
|
bytes32 account,
|
|
163
162
|
bytes memory state,
|
|
164
163
|
bytes calldata input,
|
|
165
164
|
uint128 value
|
|
166
|
-
) internal returns (bytes memory,
|
|
165
|
+
) internal returns (bytes memory, uint) {
|
|
167
166
|
if (value != 0) revert ValueNotAllowed();
|
|
168
167
|
if (input.length != 0) revert Executions.ZeroStride();
|
|
169
168
|
if (state.length == 0) revert Blocks.EmptyRun();
|
|
170
169
|
|
|
171
|
-
|
|
172
|
-
while (
|
|
173
|
-
(bytes32 liability, uint debt) =
|
|
170
|
+
(uint abs, uint end) = Memory.bounds(state, Sizes.Debt);
|
|
171
|
+
while (abs < end) {
|
|
172
|
+
(bytes32 liability, uint debt) = Memory.unpackDebt(abs);
|
|
174
173
|
repay(account, liability, debt);
|
|
174
|
+
unchecked {
|
|
175
|
+
abs += Sizes.Debt;
|
|
176
|
+
}
|
|
175
177
|
}
|
|
176
178
|
|
|
177
|
-
return ("",
|
|
179
|
+
return ("", 0);
|
|
178
180
|
}
|
|
179
181
|
}
|
package/commands/Settle.sol
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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
10
|
|
|
11
11
|
using Executions for Execution;
|
|
12
|
-
using Readers for Reader;
|
|
13
12
|
|
|
14
13
|
/// @notice Hook implemented by hosts that settle positions using native value.
|
|
15
14
|
abstract contract SettlePayableHook {
|
|
@@ -37,7 +36,7 @@ abstract contract Settle is CommandBase, SettleHook, Action {
|
|
|
37
36
|
uint private immutable id;
|
|
38
37
|
|
|
39
38
|
constructor() {
|
|
40
|
-
(id, descriptor) = command("settle", Specs.Position, Specs.Empty, Specs.Empty, 0
|
|
39
|
+
(id, descriptor) = command("settle", Specs.Position, Specs.Empty, Specs.Empty, 0);
|
|
41
40
|
action(id, Actions.Settle);
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -49,18 +48,18 @@ abstract contract Settle is CommandBase, SettleHook, Action {
|
|
|
49
48
|
/// @notice Settle each POSITION block from the command state.
|
|
50
49
|
/// @param context Command context carrying the POSITION state stream.
|
|
51
50
|
/// @return Empty output state.
|
|
52
|
-
/// @return
|
|
51
|
+
/// @return Zero native budget credit.
|
|
53
52
|
function settle(
|
|
54
53
|
bytes calldata context
|
|
55
|
-
) external onlyCommand returns (bytes memory,
|
|
56
|
-
Execution memory exec = openCommand(context, descriptor
|
|
54
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
55
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
57
56
|
|
|
58
57
|
while (exec.more()) {
|
|
59
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
58
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
60
59
|
settle(exec.account, asset, amount, liability, debt);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
return
|
|
62
|
+
return exec.close();
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
|
|
@@ -71,25 +70,25 @@ abstract contract SettlePayable is CommandBase, SettlePayableHook, Action {
|
|
|
71
70
|
|
|
72
71
|
constructor() {
|
|
73
72
|
uint id;
|
|
74
|
-
(id, descriptor) = command("settlePayable", Specs.Position, Specs.Empty, Specs.Empty,
|
|
73
|
+
(id, descriptor) = command("settlePayable", Specs.Position, Specs.Empty, Specs.Empty, Flags.Funded);
|
|
75
74
|
action(id, Actions.Settle);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/// @notice Settle each POSITION block with access to a shared native-value budget.
|
|
79
78
|
/// @param context Command context carrying the POSITION state stream.
|
|
80
79
|
/// @return Empty output state.
|
|
81
|
-
/// @return
|
|
80
|
+
/// @return Native value to add to the caller's budget.
|
|
82
81
|
function settlePayable(
|
|
83
82
|
bytes calldata context
|
|
84
|
-
) external payable onlyCommand returns (bytes memory,
|
|
85
|
-
Execution memory exec = openCommand(context, descriptor
|
|
83
|
+
) external payable onlyCommand returns (bytes memory, uint) {
|
|
84
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
86
85
|
|
|
87
86
|
while (exec.more()) {
|
|
88
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(
|
|
87
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition();
|
|
89
88
|
settle(exec.account, asset, amount, liability, debt, exec);
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
return
|
|
91
|
+
return exec.close();
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
|
|
@@ -104,23 +103,26 @@ abstract contract SettleInternal is Settle {
|
|
|
104
103
|
/// @param input Empty input required by the command schema.
|
|
105
104
|
/// @param value Native value assigned to the command; must be zero.
|
|
106
105
|
/// @return output Empty output state.
|
|
107
|
-
/// @return
|
|
106
|
+
/// @return credit Zero native budget credit.
|
|
108
107
|
function executeSettle(
|
|
109
108
|
bytes32 account,
|
|
110
109
|
bytes memory state,
|
|
111
110
|
bytes calldata input,
|
|
112
111
|
uint128 value
|
|
113
|
-
) internal returns (bytes memory,
|
|
112
|
+
) internal returns (bytes memory, uint) {
|
|
114
113
|
if (value != 0) revert ValueNotAllowed();
|
|
115
114
|
if (input.length != 0) revert Executions.ZeroStride();
|
|
116
115
|
if (state.length == 0) revert Blocks.EmptyRun();
|
|
117
116
|
|
|
118
|
-
|
|
119
|
-
while (
|
|
120
|
-
(bytes32 asset, uint amount, bytes32 liability, uint debt) =
|
|
117
|
+
(uint abs, uint end) = Memory.bounds(state, Sizes.Position);
|
|
118
|
+
while (abs < end) {
|
|
119
|
+
(bytes32 asset, uint amount, bytes32 liability, uint debt) = Memory.unpackPosition(abs);
|
|
121
120
|
settle(account, asset, amount, liability, debt);
|
|
121
|
+
unchecked {
|
|
122
|
+
abs += Sizes.Position;
|
|
123
|
+
}
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
return ("",
|
|
126
|
+
return ("", 0);
|
|
125
127
|
}
|
|
126
128
|
}
|
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
|
|