@rootzero/contracts 1.13.0 → 1.14.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 +45 -3
- package/Codec.sol +21 -0
- package/Commands.sol +14 -0
- package/Core.sol +2 -3
- package/Endpoints.sol +1 -5
- package/README.md +34 -30
- package/Utils.sol +2 -4
- package/codec/Blocks.sol +1606 -0
- package/codec/Buffers.sol +165 -0
- package/codec/Decoders.sol +558 -0
- package/codec/Descriptors.sol +124 -0
- package/{blocks → codec}/Keys.sol +4 -16
- package/codec/Readers.sol +114 -0
- package/{blocks → codec}/Schema.sol +38 -80
- package/codec/Specs.sol +218 -0
- package/codec/Writers.sol +487 -0
- package/commands/Allocate.sol +21 -20
- package/commands/Base.sol +71 -37
- package/commands/Burn.sol +18 -13
- package/commands/Credit.sol +21 -20
- package/commands/Debit.sol +25 -28
- package/commands/Deposit.sol +34 -35
- package/commands/Payout.sol +21 -15
- package/commands/Provision.sol +37 -38
- package/commands/Recover.sol +20 -19
- package/commands/Relay.sol +24 -22
- package/commands/Withdraw.sol +15 -18
- package/commands/admin/AllowAssets.sol +19 -16
- package/commands/admin/Allowance.sol +18 -13
- package/commands/admin/Appoint.sol +17 -15
- package/commands/admin/Authorize.sol +23 -14
- package/commands/admin/Base.sol +1 -1
- package/commands/admin/DenyAssets.sol +19 -16
- package/commands/admin/Dismiss.sol +17 -15
- package/commands/admin/Execute.sol +20 -19
- package/commands/admin/Label.sol +17 -13
- package/commands/admin/Schemas.sol +18 -14
- package/commands/admin/Unauthorize.sol +23 -14
- package/core/Calls.sol +3 -11
- package/core/Endpoint.sol +42 -127
- package/core/Pipeline.sol +16 -15
- package/core/Types.sol +1 -1
- package/docs/Schema.md +35 -29
- package/events/Endpoint.sol +2 -2
- package/events/Schema.sol +5 -5
- package/execution/Budget.sol +40 -0
- package/execution/Execution.sol +1083 -0
- package/guards/Base.sol +8 -9
- package/guards/Revoke.sol +11 -9
- package/package.json +1 -1
- package/ports/AllowAssets.sol +12 -15
- package/ports/Allowance.sol +11 -9
- package/ports/Base.sol +18 -11
- package/ports/Credit.sol +11 -9
- package/ports/Debit.sol +11 -9
- package/ports/DenyAssets.sol +10 -13
- package/ports/Dispatch.sol +13 -15
- package/ports/Pipe.sol +14 -12
- package/ports/Redeem.sol +12 -9
- package/ports/Settle.sol +11 -9
- package/queries/Assets.sol +15 -15
- package/queries/Balances.sol +17 -17
- package/queries/Base.sol +11 -12
- package/utils/Actions.sol +1 -0
- package/utils/Cursors.sol +308 -0
- package/utils/Lanes.sol +14 -0
- package/utils/Selectors.sol +2 -2
- package/utils/Utils.sol +46 -0
- package/Cursors.sol +0 -16
- package/blocks/Cursors.sol +0 -1529
- package/blocks/Writers.sol +0 -1036
- package/core/Payable.sol +0 -53
- package/utils/Value.sol +0 -43
package/core/Payable.sol
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {Budget, Values} from "../utils/Value.sol";
|
|
5
|
-
import {Cursors} from "../Cursors.sol";
|
|
6
|
-
import {ReceivedEvent} from "../events/Received.sol";
|
|
7
|
-
import {Actions} from "../utils/Actions.sol";
|
|
8
|
-
import {NativeAsset} from "./Runtime.sol";
|
|
9
|
-
import {max128} from "../utils/Utils.sol";
|
|
10
|
-
|
|
11
|
-
/// @title Payable
|
|
12
|
-
/// @notice Abstract mixin for entrypoints that accept native value (`msg.value`).
|
|
13
|
-
/// Provides shared helpers for mutable native-value budgets.
|
|
14
|
-
abstract contract Payable is NativeAsset, ReceivedEvent {
|
|
15
|
-
/// @notice Open a native-value budget from the current call's `msg.value`.
|
|
16
|
-
/// @return Budget initialized with the full `msg.value`.
|
|
17
|
-
function openValue() internal view returns (Budget memory) {
|
|
18
|
-
return Budget({remaining: msg.value});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/// @notice Return the current call's native value as a checked uint128.
|
|
22
|
-
/// @return value Current `msg.value` in wei.
|
|
23
|
-
function msgValue() internal view returns (uint128 value) {
|
|
24
|
-
return uint128(max128(msg.value));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// @notice Deduct the EVM value lane from a packed resource word and return it.
|
|
28
|
-
/// @dev EVM resources use the low 128 bits as native value/endowment.
|
|
29
|
-
/// @param budget Mutable budget to deduct from.
|
|
30
|
-
/// @param resources Packed resources.
|
|
31
|
-
/// @return value Native value to forward in wei.
|
|
32
|
-
function useValue(Budget memory budget, uint resources) internal pure returns (uint128 value) {
|
|
33
|
-
value = uint128(resources);
|
|
34
|
-
Values.use(budget, value);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/// @notice Drain a native-value budget into a credit-only TRANSACTION block.
|
|
38
|
-
/// @dev Emits `Received` with `Actions.Refund` when a transaction is created.
|
|
39
|
-
/// @param budget Mutable budget whose remaining value is drained.
|
|
40
|
-
/// @param account Destination account to credit with the remaining native value.
|
|
41
|
-
/// @return transaction Encoded TRANSACTION block, or empty bytes when the budget is empty.
|
|
42
|
-
function closeValue(
|
|
43
|
-
Budget memory budget,
|
|
44
|
-
bytes32 account
|
|
45
|
-
) internal returns (bytes memory transaction) {
|
|
46
|
-
uint amount = Values.drain(budget);
|
|
47
|
-
if (amount == 0) return "";
|
|
48
|
-
|
|
49
|
-
transaction = Cursors.toTransactionBlock(bytes32(0), account, nativeAsset, amount);
|
|
50
|
-
emit Received(account, nativeAsset, amount, Actions.Refund, 0);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
package/utils/Value.sol
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
/// @notice Mutable native-value budget drawn down as sub-calls consume ETH.
|
|
5
|
-
struct Budget {
|
|
6
|
-
/// @dev Remaining unspent native value in wei.
|
|
7
|
-
uint remaining;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/// @title Values
|
|
11
|
-
/// @notice Native-value budget mutation helpers.
|
|
12
|
-
library Values {
|
|
13
|
-
/// @dev Thrown when a call attempts to spend more native value than remains in the budget.
|
|
14
|
-
error InsufficientValue();
|
|
15
|
-
|
|
16
|
-
/// @notice Deduct `amount` from the budget and return it.
|
|
17
|
-
/// Reverts if `amount` exceeds `budget.remaining`.
|
|
18
|
-
/// @param budget Mutable budget to deduct from.
|
|
19
|
-
/// @param amount Native value to spend in wei.
|
|
20
|
-
/// @return The same `amount`, ready to forward to a callee.
|
|
21
|
-
function use(Budget memory budget, uint amount) internal pure returns (uint) {
|
|
22
|
-
if (amount > budget.remaining) revert InsufficientValue();
|
|
23
|
-
budget.remaining -= amount;
|
|
24
|
-
return amount;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// @notice Drain the remaining native value from `budget` and return it.
|
|
28
|
-
/// @param budget Mutable budget to drain.
|
|
29
|
-
/// @return value Native value removed from the budget, in wei.
|
|
30
|
-
function drain(Budget memory budget) internal pure returns (uint value) {
|
|
31
|
-
value = budget.remaining;
|
|
32
|
-
budget.remaining = 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/// @notice Deduct `amount` from the budget and return it as a new sub-budget.
|
|
36
|
-
/// Reverts if `amount` exceeds `budget.remaining`.
|
|
37
|
-
/// @param budget Mutable parent budget to deduct from.
|
|
38
|
-
/// @param amount Native value to assign to the sub-budget, in wei.
|
|
39
|
-
/// @return A new budget with `amount` remaining.
|
|
40
|
-
function allocate(Budget memory budget, uint amount) internal pure returns (Budget memory) {
|
|
41
|
-
return Budget({remaining: use(budget, amount)});
|
|
42
|
-
}
|
|
43
|
-
}
|