@rootzero/contracts 0.5.1 → 0.6.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/Commands.sol +7 -5
- package/Utils.sol +2 -2
- package/commands/Base.sol +28 -0
- package/commands/Borrow.sol +5 -4
- package/commands/Burn.sol +3 -2
- package/commands/Create.sol +3 -2
- package/commands/Credit.sol +3 -2
- package/commands/Debit.sol +3 -2
- package/commands/Deposit.sol +52 -5
- package/commands/Liquidate.sol +5 -4
- package/commands/Liquidity.sol +9 -8
- package/commands/Mint.sol +3 -2
- package/commands/Pipe.sol +17 -20
- package/commands/Provision.sol +64 -23
- package/commands/Reclaim.sol +3 -2
- package/commands/Redeem.sol +5 -4
- package/commands/Remove.sol +3 -2
- package/commands/Repay.sol +5 -4
- package/commands/Settle.sol +3 -2
- package/commands/Stake.sol +7 -6
- package/commands/Supply.sol +3 -2
- package/commands/Swap.sol +5 -4
- package/commands/Transfer.sol +3 -2
- package/commands/Unstake.sol +3 -2
- package/commands/Withdraw.sol +3 -2
- package/commands/admin/Allocate.sol +3 -2
- package/commands/admin/AllowAssets.sol +3 -2
- package/commands/admin/Authorize.sol +3 -2
- package/commands/admin/DenyAssets.sol +3 -2
- package/commands/admin/Destroy.sol +3 -2
- package/commands/admin/Init.sol +3 -2
- package/commands/admin/Relocate.sol +13 -9
- package/commands/admin/Unauthorize.sol +3 -2
- package/core/Host.sol +3 -3
- package/events/Command.sol +12 -5
- package/events/Peer.sol +4 -2
- package/package.json +1 -1
- package/peer/AllowAssets.sol +2 -2
- package/peer/DenyAssets.sol +2 -2
- package/peer/Pull.sol +2 -2
- package/peer/Push.sol +2 -2
- package/peer/Settle.sol +2 -2
- package/utils/Utils.sol +8 -0
- package/utils/Value.sol +15 -6
package/commands/Provision.sol
CHANGED
|
@@ -1,57 +1,96 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {CommandContext, CommandBase, State} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur, Schemas, Writer, Writers} from "../Cursors.sol";
|
|
4
|
+
import {CommandContext, CommandBase, CommandPayable, State} from "./Base.sol";
|
|
5
|
+
import {Cursors, Cur, HostAmount, Schemas, Writer, Writers} from "../Cursors.sol";
|
|
6
|
+
import {Budget, Values} from "../utils/Value.sol";
|
|
6
7
|
using Cursors for Cur;
|
|
7
8
|
using Writers for Writer;
|
|
8
9
|
|
|
9
10
|
string constant PROVISION = "provision";
|
|
11
|
+
string constant PP = "provisionPayable";
|
|
10
12
|
string constant PFB = "provisionFromBalance";
|
|
11
13
|
|
|
12
|
-
string constant INPUT = string.concat(Schemas.Node, "&", Schemas.Amount);
|
|
13
|
-
|
|
14
14
|
/// @notice Shared provision hook used by both `Provision` and `ProvisionFromBalance`.
|
|
15
15
|
abstract contract ProvisionHook {
|
|
16
|
-
/// @notice Override to send or provision
|
|
16
|
+
/// @notice Override to send or provision a custody value.
|
|
17
|
+
/// Called once per provisioned asset. Implementations should perform only the
|
|
18
|
+
/// side effect (e.g. transfer or record); output blocks are written by the caller.
|
|
19
|
+
/// @param account Caller's account identifier.
|
|
20
|
+
/// @param custody Destination host plus asset amount to provision.
|
|
21
|
+
function provision(bytes32 account, HostAmount memory custody) internal virtual;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// @notice Shared provision hook used by `ProvisionPayable`.
|
|
25
|
+
abstract contract ProvisionPayableHook {
|
|
26
|
+
/// @notice Override to send or provision a custody value.
|
|
17
27
|
/// Called once per provisioned asset. Implementations should perform only the
|
|
18
28
|
/// side effect (e.g. transfer or record); output blocks are written by the caller.
|
|
19
29
|
/// @param account Caller's account identifier.
|
|
20
|
-
/// @param
|
|
21
|
-
/// @param
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
/// @param custody Destination host plus asset amount to provision.
|
|
31
|
+
/// @param budget Mutable native-value budget drawn from `msg.value`.
|
|
32
|
+
function provision(
|
|
33
|
+
bytes32 account,
|
|
34
|
+
HostAmount memory custody,
|
|
35
|
+
Budget memory budget
|
|
36
|
+
) internal virtual;
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/// @title Provision
|
|
28
|
-
/// @notice Command that provisions assets to remote hosts from
|
|
29
|
-
/// Each
|
|
40
|
+
/// @notice Command that provisions assets to remote hosts from CUSTODY request blocks.
|
|
41
|
+
/// Each request block supplies the target host plus an asset amount; the output is a CUSTODY state stream.
|
|
30
42
|
abstract contract Provision is CommandBase, ProvisionHook {
|
|
31
43
|
uint internal immutable provisionId = commandId(PROVISION);
|
|
32
44
|
|
|
33
45
|
constructor() {
|
|
34
|
-
emit Command(host, PROVISION,
|
|
46
|
+
emit Command(host, PROVISION, Schemas.Custody, provisionId, State.Empty, State.Custodies, false);
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
function provision(
|
|
38
50
|
CommandContext calldata c
|
|
39
|
-
) external
|
|
51
|
+
) external onlyCommand(provisionId, c.target) returns (bytes memory) {
|
|
40
52
|
(Cur memory request, uint count, ) = cursor(c.request, 1);
|
|
41
53
|
Writer memory writer = Writers.allocCustodies(count);
|
|
42
54
|
|
|
43
55
|
while (request.i < request.bound) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
provision(c.account, toHost, asset, meta, amount);
|
|
48
|
-
writer.appendCustody(toHost, asset, meta, amount);
|
|
56
|
+
HostAmount memory custody = request.unpackCustodyValue();
|
|
57
|
+
provision(c.account, custody);
|
|
58
|
+
writer.appendCustody(custody);
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
return request.complete(writer);
|
|
52
62
|
}
|
|
53
63
|
}
|
|
54
64
|
|
|
65
|
+
/// @title ProvisionPayable
|
|
66
|
+
/// @notice Command that provisions assets to remote hosts from CUSTODY request blocks.
|
|
67
|
+
/// Each request block supplies the target host plus an asset amount; the output is a CUSTODY state stream.
|
|
68
|
+
/// The hook receives a mutable native-value budget drawn from `msg.value`.
|
|
69
|
+
abstract contract ProvisionPayable is CommandPayable, ProvisionPayableHook {
|
|
70
|
+
uint internal immutable provisionPayableId = commandId(PP);
|
|
71
|
+
|
|
72
|
+
constructor() {
|
|
73
|
+
emit Command(host, PP, Schemas.Custody, provisionPayableId, State.Empty, State.Custodies, true);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function provisionPayable(
|
|
77
|
+
CommandContext calldata c
|
|
78
|
+
) external payable onlyCommand(provisionPayableId, c.target) returns (bytes memory) {
|
|
79
|
+
(Cur memory request, uint count, ) = cursor(c.request, 1);
|
|
80
|
+
Writer memory writer = Writers.allocCustodies(count);
|
|
81
|
+
Budget memory budget = Values.fromMsg();
|
|
82
|
+
|
|
83
|
+
while (request.i < request.bound) {
|
|
84
|
+
HostAmount memory custody = request.unpackCustodyValue();
|
|
85
|
+
provision(c.account, custody, budget);
|
|
86
|
+
writer.appendCustody(custody);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
settleValue(c.account, budget);
|
|
90
|
+
return request.complete(writer);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
55
94
|
/// @title ProvisionFromBalance
|
|
56
95
|
/// @notice Command that converts BALANCE state into CUSTODY state for a destination host.
|
|
57
96
|
/// The destination node is read from an optional NODE trailing block; reverts if absent.
|
|
@@ -59,12 +98,12 @@ abstract contract ProvisionFromBalance is CommandBase, ProvisionHook {
|
|
|
59
98
|
uint internal immutable provisionFromBalanceId = commandId(PFB);
|
|
60
99
|
|
|
61
100
|
constructor() {
|
|
62
|
-
emit Command(host, PFB, Schemas.Node, provisionFromBalanceId, State.Balances, State.Custodies);
|
|
101
|
+
emit Command(host, PFB, Schemas.Node, provisionFromBalanceId, State.Balances, State.Custodies, false);
|
|
63
102
|
}
|
|
64
103
|
|
|
65
104
|
function provisionFromBalance(
|
|
66
105
|
CommandContext calldata c
|
|
67
|
-
) external
|
|
106
|
+
) external onlyCommand(provisionFromBalanceId, c.target) returns (bytes memory) {
|
|
68
107
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
69
108
|
Cur memory request = cursor(c.request);
|
|
70
109
|
Writer memory writer = Writers.allocCustodies(stateCount);
|
|
@@ -73,10 +112,12 @@ abstract contract ProvisionFromBalance is CommandBase, ProvisionHook {
|
|
|
73
112
|
|
|
74
113
|
while (state.i < state.bound) {
|
|
75
114
|
(bytes32 asset, bytes32 meta, uint amount) = state.unpackBalance();
|
|
76
|
-
|
|
77
|
-
|
|
115
|
+
HostAmount memory custody = HostAmount(toHost, asset, meta, amount);
|
|
116
|
+
provision(c.account, custody);
|
|
117
|
+
writer.appendCustody(custody);
|
|
78
118
|
}
|
|
79
119
|
|
|
80
120
|
return state.complete(writer);
|
|
81
121
|
}
|
|
82
122
|
}
|
|
123
|
+
|
package/commands/Reclaim.sol
CHANGED
|
@@ -19,7 +19,7 @@ abstract contract ReclaimToBalances is CommandBase {
|
|
|
19
19
|
|
|
20
20
|
constructor(string memory input, uint scaledRatio) {
|
|
21
21
|
outScale = scaledRatio;
|
|
22
|
-
emit Command(host, NAME, input, reclaimToBalancesId, State.Empty, State.Balances);
|
|
22
|
+
emit Command(host, NAME, input, reclaimToBalancesId, State.Empty, State.Balances, false);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/// @dev Override to reclaim balances described by the current `input`
|
|
@@ -36,7 +36,7 @@ abstract contract ReclaimToBalances is CommandBase {
|
|
|
36
36
|
|
|
37
37
|
function reclaimToBalances(
|
|
38
38
|
CommandContext calldata c
|
|
39
|
-
) external
|
|
39
|
+
) external onlyCommand(reclaimToBalancesId, c.target) returns (bytes memory) {
|
|
40
40
|
(Cur memory request, uint count, ) = cursor(c.request, 1);
|
|
41
41
|
Writer memory writer = Writers.allocScaledBalances(count, outScale);
|
|
42
42
|
|
|
@@ -52,3 +52,4 @@ abstract contract ReclaimToBalances is CommandBase {
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
|
package/commands/Redeem.sol
CHANGED
|
@@ -19,7 +19,7 @@ abstract contract RedeemFromBalanceToBalances is CommandBase {
|
|
|
19
19
|
|
|
20
20
|
constructor(string memory input, uint scaledRatio) {
|
|
21
21
|
outScale = scaledRatio;
|
|
22
|
-
emit Command(host, RDBTB, input, redeemFromBalanceToBalancesId, State.Balances, State.Balances);
|
|
22
|
+
emit Command(host, RDBTB, input, redeemFromBalanceToBalancesId, State.Balances, State.Balances, false);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/// @dev Override to redeem a balance position into balances.
|
|
@@ -36,7 +36,7 @@ abstract contract RedeemFromBalanceToBalances is CommandBase {
|
|
|
36
36
|
|
|
37
37
|
function redeemFromBalanceToBalances(
|
|
38
38
|
CommandContext calldata c
|
|
39
|
-
) external
|
|
39
|
+
) external onlyCommand(redeemFromBalanceToBalancesId, c.target) returns (bytes memory) {
|
|
40
40
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
41
41
|
Cur memory request = cursor(c.request);
|
|
42
42
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -59,7 +59,7 @@ abstract contract RedeemFromCustodyToBalances is CommandBase {
|
|
|
59
59
|
|
|
60
60
|
constructor(string memory input, uint scaledRatio) {
|
|
61
61
|
outScale = scaledRatio;
|
|
62
|
-
emit Command(host, RDCTB, input, redeemFromCustodyToBalancesId, State.Custodies, State.Balances);
|
|
62
|
+
emit Command(host, RDCTB, input, redeemFromCustodyToBalancesId, State.Custodies, State.Balances, false);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/// @dev Override to redeem a custody position into balances.
|
|
@@ -76,7 +76,7 @@ abstract contract RedeemFromCustodyToBalances is CommandBase {
|
|
|
76
76
|
|
|
77
77
|
function redeemFromCustodyToBalances(
|
|
78
78
|
CommandContext calldata c
|
|
79
|
-
) external
|
|
79
|
+
) external onlyCommand(redeemFromCustodyToBalancesId, c.target) returns (bytes memory) {
|
|
80
80
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
81
81
|
Cur memory request = cursor(c.request);
|
|
82
82
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -96,3 +96,4 @@ abstract contract RedeemFromCustodyToBalances is CommandBase {
|
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
|
package/commands/Remove.sol
CHANGED
|
@@ -16,14 +16,14 @@ abstract contract Remove is CommandBase {
|
|
|
16
16
|
uint internal immutable removeId = commandId(NAME);
|
|
17
17
|
|
|
18
18
|
constructor(string memory input) {
|
|
19
|
-
emit Command(host, NAME, input, removeId, State.Empty, State.Empty);
|
|
19
|
+
emit Command(host, NAME, input, removeId, State.Empty, State.Empty, false);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/// @dev Override to remove or dismantle an object described by `input`.
|
|
23
23
|
/// Called once per top-level request item.
|
|
24
24
|
function remove(bytes32 account, Cur memory input) internal virtual;
|
|
25
25
|
|
|
26
|
-
function remove(CommandContext calldata c) external
|
|
26
|
+
function remove(CommandContext calldata c) external onlyCommand(removeId, c.target) returns (bytes memory) {
|
|
27
27
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
28
28
|
|
|
29
29
|
while (request.i < request.bound) {
|
|
@@ -39,3 +39,4 @@ abstract contract Remove is CommandBase {
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
+
|
package/commands/Repay.sol
CHANGED
|
@@ -19,7 +19,7 @@ abstract contract RepayFromBalanceToBalances is CommandBase {
|
|
|
19
19
|
|
|
20
20
|
constructor(string memory input, uint scaledRatio) {
|
|
21
21
|
outScale = scaledRatio;
|
|
22
|
-
emit Command(host, RFBTB, input, repayFromBalanceToBalancesId, State.Balances, State.Balances);
|
|
22
|
+
emit Command(host, RFBTB, input, repayFromBalanceToBalancesId, State.Balances, State.Balances, false);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/// @dev Override to repay debt using a balance amount.
|
|
@@ -36,7 +36,7 @@ abstract contract RepayFromBalanceToBalances is CommandBase {
|
|
|
36
36
|
|
|
37
37
|
function repayFromBalanceToBalances(
|
|
38
38
|
CommandContext calldata c
|
|
39
|
-
) external
|
|
39
|
+
) external onlyCommand(repayFromBalanceToBalancesId, c.target) returns (bytes memory) {
|
|
40
40
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
41
41
|
Cur memory request = cursor(c.request);
|
|
42
42
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -59,7 +59,7 @@ abstract contract RepayFromCustodyToBalances is CommandBase {
|
|
|
59
59
|
|
|
60
60
|
constructor(string memory input, uint scaledRatio) {
|
|
61
61
|
outScale = scaledRatio;
|
|
62
|
-
emit Command(host, RFCTB, input, repayFromCustodyToBalancesId, State.Custodies, State.Balances);
|
|
62
|
+
emit Command(host, RFCTB, input, repayFromCustodyToBalancesId, State.Custodies, State.Balances, false);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/// @dev Override to repay debt using a custody amount.
|
|
@@ -76,7 +76,7 @@ abstract contract RepayFromCustodyToBalances is CommandBase {
|
|
|
76
76
|
|
|
77
77
|
function repayFromCustodyToBalances(
|
|
78
78
|
CommandContext calldata c
|
|
79
|
-
) external
|
|
79
|
+
) external onlyCommand(repayFromCustodyToBalancesId, c.target) returns (bytes memory) {
|
|
80
80
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
81
81
|
Cur memory request = cursor(c.request);
|
|
82
82
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -96,3 +96,4 @@ abstract contract RepayFromCustodyToBalances is CommandBase {
|
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
|
package/commands/Settle.sol
CHANGED
|
@@ -15,10 +15,10 @@ abstract contract Settle is CommandBase, TransferHook {
|
|
|
15
15
|
uint internal immutable settleId = commandId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Command(host, NAME, "", settleId, State.Transactions, State.Empty);
|
|
18
|
+
emit Command(host, NAME, "", settleId, State.Transactions, State.Empty, false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function settle(CommandContext calldata c) external
|
|
21
|
+
function settle(CommandContext calldata c) external onlyCommand(settleId, c.target) returns (bytes memory) {
|
|
22
22
|
(Cur memory state, , ) = cursor(c.state, 1);
|
|
23
23
|
|
|
24
24
|
while (state.i < state.bound) {
|
|
@@ -35,3 +35,4 @@ abstract contract Settle is CommandBase, TransferHook {
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
|
package/commands/Stake.sol
CHANGED
|
@@ -20,7 +20,7 @@ abstract contract StakeBalanceToBalances is CommandBase {
|
|
|
20
20
|
|
|
21
21
|
constructor(string memory input, uint scaledRatio) {
|
|
22
22
|
outScale = scaledRatio;
|
|
23
|
-
emit Command(host, SBTB, input, stakeBalanceToBalancesId, State.Balances, State.Balances);
|
|
23
|
+
emit Command(host, SBTB, input, stakeBalanceToBalancesId, State.Balances, State.Balances, false);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/// @dev Override to stake a balance position and append resulting balances
|
|
@@ -37,7 +37,7 @@ abstract contract StakeBalanceToBalances is CommandBase {
|
|
|
37
37
|
|
|
38
38
|
function stakeBalanceToBalances(
|
|
39
39
|
CommandContext calldata c
|
|
40
|
-
) external
|
|
40
|
+
) external onlyCommand(stakeBalanceToBalancesId, c.target) returns (bytes memory) {
|
|
41
41
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
42
42
|
Cur memory request = cursor(c.request);
|
|
43
43
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -60,7 +60,7 @@ abstract contract StakeCustodyToBalances is CommandBase {
|
|
|
60
60
|
|
|
61
61
|
constructor(string memory input, uint scaledRatio) {
|
|
62
62
|
outScale = scaledRatio;
|
|
63
|
-
emit Command(host, SCTB, input, stakeCustodyToBalancesId, State.Custodies, State.Balances);
|
|
63
|
+
emit Command(host, SCTB, input, stakeCustodyToBalancesId, State.Custodies, State.Balances, false);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/// @dev Override to stake a custody position and append resulting balances
|
|
@@ -77,7 +77,7 @@ abstract contract StakeCustodyToBalances is CommandBase {
|
|
|
77
77
|
|
|
78
78
|
function stakeCustodyToBalances(
|
|
79
79
|
CommandContext calldata c
|
|
80
|
-
) external
|
|
80
|
+
) external onlyCommand(stakeCustodyToBalancesId, c.target) returns (bytes memory) {
|
|
81
81
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
82
82
|
Cur memory request = cursor(c.request);
|
|
83
83
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -98,7 +98,7 @@ abstract contract StakeCustodyToPosition is CommandBase {
|
|
|
98
98
|
uint internal immutable stakeCustodyToPositionId = commandId(SCTP);
|
|
99
99
|
|
|
100
100
|
constructor(string memory input) {
|
|
101
|
-
emit Command(host, SCTP, input, stakeCustodyToPositionId, State.Custodies, State.Empty);
|
|
101
|
+
emit Command(host, SCTP, input, stakeCustodyToPositionId, State.Custodies, State.Empty, false);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/// @dev Override to stake a custody position into a non-balance setup
|
|
@@ -107,7 +107,7 @@ abstract contract StakeCustodyToPosition is CommandBase {
|
|
|
107
107
|
|
|
108
108
|
function stakeCustodyToPosition(
|
|
109
109
|
CommandContext calldata c
|
|
110
|
-
) external
|
|
110
|
+
) external onlyCommand(stakeCustodyToPositionId, c.target) returns (bytes memory) {
|
|
111
111
|
(Cur memory state, , ) = cursor(c.state, 1);
|
|
112
112
|
Cur memory request = cursor(c.request);
|
|
113
113
|
|
|
@@ -127,3 +127,4 @@ abstract contract StakeCustodyToPosition is CommandBase {
|
|
|
127
127
|
|
|
128
128
|
|
|
129
129
|
|
|
130
|
+
|
package/commands/Supply.sol
CHANGED
|
@@ -15,7 +15,7 @@ abstract contract Supply is CommandBase {
|
|
|
15
15
|
uint internal immutable supplyId = commandId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Command(host, NAME, "", supplyId, State.Custodies, State.Empty);
|
|
18
|
+
emit Command(host, NAME, "", supplyId, State.Custodies, State.Empty, false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Override to consume or supply a single custody position.
|
|
@@ -25,7 +25,7 @@ abstract contract Supply is CommandBase {
|
|
|
25
25
|
function supply(bytes32 account, HostAmount memory value) internal virtual;
|
|
26
26
|
|
|
27
27
|
/// @notice Execute the supply command.
|
|
28
|
-
function supply(CommandContext calldata c) external
|
|
28
|
+
function supply(CommandContext calldata c) external onlyCommand(supplyId, c.target) returns (bytes memory) {
|
|
29
29
|
(Cur memory state, , ) = cursor(c.state, 1);
|
|
30
30
|
|
|
31
31
|
while (state.i < state.bound) {
|
|
@@ -38,3 +38,4 @@ abstract contract Supply is CommandBase {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
|
package/commands/Swap.sol
CHANGED
|
@@ -16,7 +16,7 @@ abstract contract SwapExactBalanceToBalance is CommandBase {
|
|
|
16
16
|
uint internal immutable swapExactBalanceToBalanceId = commandId(SEBTB);
|
|
17
17
|
|
|
18
18
|
constructor(string memory input) {
|
|
19
|
-
emit Command(host, SEBTB, input, swapExactBalanceToBalanceId, State.Balances, State.Balances);
|
|
19
|
+
emit Command(host, SEBTB, input, swapExactBalanceToBalanceId, State.Balances, State.Balances, false);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/// @dev Override to swap an exact balance input into a balance output.
|
|
@@ -30,7 +30,7 @@ abstract contract SwapExactBalanceToBalance is CommandBase {
|
|
|
30
30
|
|
|
31
31
|
function swapExactBalanceToBalance(
|
|
32
32
|
CommandContext calldata c
|
|
33
|
-
) external
|
|
33
|
+
) external onlyCommand(swapExactBalanceToBalanceId, c.target) returns (bytes memory) {
|
|
34
34
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
35
35
|
Cur memory request = cursor(c.request);
|
|
36
36
|
Writer memory writer = Writers.allocBalances(stateCount);
|
|
@@ -52,7 +52,7 @@ abstract contract SwapExactCustodyToBalance is CommandBase {
|
|
|
52
52
|
uint internal immutable swapExactCustodyToBalanceId = commandId(SECTB);
|
|
53
53
|
|
|
54
54
|
constructor(string memory input) {
|
|
55
|
-
emit Command(host, SECTB, input, swapExactCustodyToBalanceId, State.Custodies, State.Balances);
|
|
55
|
+
emit Command(host, SECTB, input, swapExactCustodyToBalanceId, State.Custodies, State.Balances, false);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/// @dev Override to swap an exact custody input into a balance output.
|
|
@@ -66,7 +66,7 @@ abstract contract SwapExactCustodyToBalance is CommandBase {
|
|
|
66
66
|
|
|
67
67
|
function swapExactCustodyToBalance(
|
|
68
68
|
CommandContext calldata c
|
|
69
|
-
) external
|
|
69
|
+
) external onlyCommand(swapExactCustodyToBalanceId, c.target) returns (bytes memory) {
|
|
70
70
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
71
71
|
Cur memory request = cursor(c.request);
|
|
72
72
|
Writer memory writer = Writers.allocBalances(stateCount);
|
|
@@ -87,3 +87,4 @@ abstract contract SwapExactCustodyToBalance is CommandBase {
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
|
|
90
|
+
|
package/commands/Transfer.sol
CHANGED
|
@@ -24,7 +24,7 @@ abstract contract Transfer is CommandBase, TransferHook {
|
|
|
24
24
|
uint internal immutable transferId = commandId(NAME);
|
|
25
25
|
|
|
26
26
|
constructor() {
|
|
27
|
-
emit Command(host, NAME, INPUT, transferId, State.Empty, State.Empty);
|
|
27
|
+
emit Command(host, NAME, INPUT, transferId, State.Empty, State.Empty, false);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/// @notice Override to customize request parsing or batching for transfers.
|
|
@@ -50,7 +50,7 @@ abstract contract Transfer is CommandBase, TransferHook {
|
|
|
50
50
|
|
|
51
51
|
function transfer(
|
|
52
52
|
CommandContext calldata c
|
|
53
|
-
) external
|
|
53
|
+
) external onlyCommand(transferId, c.target) returns (bytes memory) {
|
|
54
54
|
return transfer(c.account, c.request);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -60,3 +60,4 @@ abstract contract Transfer is CommandBase, TransferHook {
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
|
package/commands/Unstake.sol
CHANGED
|
@@ -18,7 +18,7 @@ abstract contract UnstakeBalanceToBalances is CommandBase {
|
|
|
18
18
|
|
|
19
19
|
constructor(string memory input, uint scaledRatio) {
|
|
20
20
|
outScale = scaledRatio;
|
|
21
|
-
emit Command(host, UBTB, input, unstakeBalanceToBalancesId, State.Balances, State.Balances);
|
|
21
|
+
emit Command(host, UBTB, input, unstakeBalanceToBalancesId, State.Balances, State.Balances, false);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/// @dev Override to unstake or redeem a balance position.
|
|
@@ -35,7 +35,7 @@ abstract contract UnstakeBalanceToBalances is CommandBase {
|
|
|
35
35
|
|
|
36
36
|
function unstakeBalanceToBalances(
|
|
37
37
|
CommandContext calldata c
|
|
38
|
-
) external
|
|
38
|
+
) external onlyCommand(unstakeBalanceToBalancesId, c.target) returns (bytes memory) {
|
|
39
39
|
(Cur memory state, uint stateCount, ) = cursor(c.state, 1);
|
|
40
40
|
Cur memory request = cursor(c.request);
|
|
41
41
|
Writer memory writer = Writers.allocScaledBalances(stateCount, outScale);
|
|
@@ -55,3 +55,4 @@ abstract contract UnstakeBalanceToBalances is CommandBase {
|
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
|
package/commands/Withdraw.sol
CHANGED
|
@@ -15,7 +15,7 @@ abstract contract Withdraw is CommandBase {
|
|
|
15
15
|
uint internal immutable withdrawId = commandId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Command(host, NAME, Schemas.Recipient, withdrawId, State.Balances, State.Empty);
|
|
18
|
+
emit Command(host, NAME, Schemas.Recipient, withdrawId, State.Balances, State.Empty, false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Override to send funds to `account`.
|
|
@@ -28,7 +28,7 @@ abstract contract Withdraw is CommandBase {
|
|
|
28
28
|
|
|
29
29
|
function withdraw(
|
|
30
30
|
CommandContext calldata c
|
|
31
|
-
) external
|
|
31
|
+
) external onlyCommand(withdrawId, c.target) returns (bytes memory) {
|
|
32
32
|
(Cur memory state, , ) = cursor(c.state, 1);
|
|
33
33
|
Cur memory request = cursor(c.request);
|
|
34
34
|
bytes32 to = request.recipientAfter(c.account);
|
|
@@ -47,3 +47,4 @@ abstract contract Withdraw is CommandBase {
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
|
|
@@ -14,14 +14,14 @@ abstract contract Allocate is CommandBase {
|
|
|
14
14
|
uint internal immutable allocateId = commandId(NAME);
|
|
15
15
|
|
|
16
16
|
constructor() {
|
|
17
|
-
emit Command(host, NAME, Schemas.Allocation, allocateId, State.Empty, State.Empty);
|
|
17
|
+
emit Command(host, NAME, Schemas.Allocation, allocateId, State.Empty, State.Empty, false);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// @dev Override to apply a single allocation entry.
|
|
21
21
|
/// Called once per ALLOCATION block in the request.
|
|
22
22
|
function allocate(uint host, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
23
23
|
|
|
24
|
-
function allocate(CommandContext calldata c) external
|
|
24
|
+
function allocate(CommandContext calldata c) external onlyAdmin(c.account) onlyCommand(allocateId, c.target) returns (bytes memory) {
|
|
25
25
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
26
26
|
|
|
27
27
|
while (request.i < request.bound) {
|
|
@@ -38,3 +38,4 @@ abstract contract Allocate is CommandBase {
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
|
|
@@ -14,7 +14,7 @@ abstract contract AllowAssets is CommandBase {
|
|
|
14
14
|
uint internal immutable allowAssetsId = commandId(NAME);
|
|
15
15
|
|
|
16
16
|
constructor() {
|
|
17
|
-
emit Command(host, NAME, Schemas.Asset, allowAssetsId, State.Empty, State.Empty);
|
|
17
|
+
emit Command(host, NAME, Schemas.Asset, allowAssetsId, State.Empty, State.Empty, false);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// @dev Override to allow a single asset/meta pair.
|
|
@@ -23,7 +23,7 @@ abstract contract AllowAssets is CommandBase {
|
|
|
23
23
|
|
|
24
24
|
function allowAssets(
|
|
25
25
|
CommandContext calldata c
|
|
26
|
-
) external
|
|
26
|
+
) external onlyAdmin(c.account) onlyCommand(allowAssetsId, c.target) returns (bytes memory) {
|
|
27
27
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
28
28
|
|
|
29
29
|
while (request.i < request.bound) {
|
|
@@ -40,3 +40,4 @@ abstract contract AllowAssets is CommandBase {
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
|
|
@@ -15,12 +15,12 @@ abstract contract Authorize is CommandBase {
|
|
|
15
15
|
uint internal immutable authorizeId = commandId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Command(host, NAME, Schemas.Node, authorizeId, State.Empty, State.Empty);
|
|
18
|
+
emit Command(host, NAME, Schemas.Node, authorizeId, State.Empty, State.Empty, false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function authorize(
|
|
22
22
|
CommandContext calldata c
|
|
23
|
-
) external
|
|
23
|
+
) external onlyAdmin(c.account) onlyCommand(authorizeId, c.target) returns (bytes memory) {
|
|
24
24
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
25
25
|
|
|
26
26
|
while (request.i < request.bound) {
|
|
@@ -36,3 +36,4 @@ abstract contract Authorize is CommandBase {
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
|
|
@@ -14,7 +14,7 @@ abstract contract DenyAssets is CommandBase {
|
|
|
14
14
|
uint internal immutable denyAssetsId = commandId(NAME);
|
|
15
15
|
|
|
16
16
|
constructor() {
|
|
17
|
-
emit Command(host, NAME, Schemas.Asset, denyAssetsId, State.Empty, State.Empty);
|
|
17
|
+
emit Command(host, NAME, Schemas.Asset, denyAssetsId, State.Empty, State.Empty, false);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// @dev Override to deny a single asset/meta pair.
|
|
@@ -23,7 +23,7 @@ abstract contract DenyAssets is CommandBase {
|
|
|
23
23
|
|
|
24
24
|
function denyAssets(
|
|
25
25
|
CommandContext calldata c
|
|
26
|
-
) external
|
|
26
|
+
) external onlyAdmin(c.account) onlyCommand(denyAssetsId, c.target) returns (bytes memory) {
|
|
27
27
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
28
28
|
|
|
29
29
|
while (request.i < request.bound) {
|
|
@@ -40,3 +40,4 @@ abstract contract DenyAssets is CommandBase {
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
|
|
@@ -15,7 +15,7 @@ abstract contract Destroy is CommandBase {
|
|
|
15
15
|
uint internal immutable destroyId = commandId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor(string memory input) {
|
|
18
|
-
emit Command(host, NAME, input, destroyId, State.Empty, State.Empty);
|
|
18
|
+
emit Command(host, NAME, input, destroyId, State.Empty, State.Empty, false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Override to run host teardown or destruction logic.
|
|
@@ -24,7 +24,7 @@ abstract contract Destroy is CommandBase {
|
|
|
24
24
|
|
|
25
25
|
function destroy(
|
|
26
26
|
CommandContext calldata c
|
|
27
|
-
) external
|
|
27
|
+
) external onlyAdmin(c.account) onlyCommand(destroyId, c.target) returns (bytes memory) {
|
|
28
28
|
Cur memory input = cursor(c.request);
|
|
29
29
|
destroy(input);
|
|
30
30
|
return "";
|
|
@@ -36,3 +36,4 @@ abstract contract Destroy is CommandBase {
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
|
package/commands/admin/Init.sol
CHANGED
|
@@ -15,7 +15,7 @@ abstract contract Init is CommandBase {
|
|
|
15
15
|
uint internal immutable initId = commandId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor(string memory input) {
|
|
18
|
-
emit Command(host, NAME, input, initId, State.Empty, State.Empty);
|
|
18
|
+
emit Command(host, NAME, input, initId, State.Empty, State.Empty, false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Override to run host initialization logic.
|
|
@@ -24,7 +24,7 @@ abstract contract Init is CommandBase {
|
|
|
24
24
|
|
|
25
25
|
function init(
|
|
26
26
|
CommandContext calldata c
|
|
27
|
-
) external
|
|
27
|
+
) external onlyAdmin(c.account) onlyCommand(initId, c.target) returns (bytes memory) {
|
|
28
28
|
Cur memory input = cursor(c.request);
|
|
29
29
|
init(input);
|
|
30
30
|
return "";
|
|
@@ -36,3 +36,4 @@ abstract contract Init is CommandBase {
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
|