@rootzero/contracts 1.13.0 → 1.15.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 +87 -3
- package/Codec.sol +21 -0
- package/Commands.sol +14 -0
- package/Core.sol +8 -6
- package/Endpoints.sol +2 -7
- package/Events.sol +1 -2
- package/README.md +70 -37
- package/Utils.sol +2 -4
- package/annotations/Action.sol +17 -0
- package/annotations/Label.sol +23 -0
- package/annotations/Schema.sol +53 -0
- package/codec/Blocks.sol +1643 -0
- package/codec/Buffers.sol +165 -0
- package/codec/Decoders.sol +570 -0
- package/codec/Descriptors.sol +124 -0
- package/{blocks → codec}/Keys.sol +10 -18
- package/codec/Readers.sol +114 -0
- package/{blocks → codec}/Schema.sol +43 -80
- package/codec/Specs.sol +240 -0
- package/codec/Writers.sol +485 -0
- package/commands/Allocate.sol +21 -20
- package/commands/Base.sol +83 -45
- package/commands/Burn.sol +23 -14
- package/commands/Credit.sol +21 -20
- package/commands/Debit.sol +25 -28
- package/commands/Deposit.sol +41 -36
- package/commands/Payout.sol +26 -16
- package/commands/Provision.sol +37 -38
- package/commands/Recover.sol +20 -19
- package/commands/Relay.sol +24 -22
- package/commands/Withdraw.sol +20 -19
- package/commands/admin/AllowAssets.sol +19 -16
- package/commands/admin/Allowance.sol +18 -13
- package/commands/admin/Annotate.sol +36 -0
- package/commands/admin/Appoint.sol +19 -16
- package/commands/admin/Authorize.sol +23 -14
- package/commands/admin/Base.sol +9 -2
- package/commands/admin/DenyAssets.sol +19 -16
- package/commands/admin/Dismiss.sol +19 -16
- package/commands/admin/Execute.sol +21 -19
- package/commands/admin/Unauthorize.sol +23 -14
- package/core/Access.sol +91 -49
- package/core/Calls.sol +30 -33
- package/core/Endpoint.sol +46 -143
- package/core/Host.sol +63 -21
- package/core/Pipeline.sol +16 -15
- package/core/Types.sol +1 -1
- package/docs/Schema.md +48 -31
- package/events/Annotation.sol +24 -0
- package/events/Endpoint.sol +2 -2
- package/events/Guardian.sol +2 -2
- package/events/Introduction.sol +3 -2
- package/execution/Budget.sol +40 -0
- package/execution/Execution.sol +1104 -0
- package/guards/Base.sol +11 -12
- 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 +35 -16
- 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 +16 -10
- package/queries/Assets.sol +15 -15
- package/queries/Balances.sol +17 -17
- package/queries/Base.sol +26 -12
- package/utils/Accounts.sol +0 -23
- package/utils/Actions.sol +1 -0
- package/utils/Cursors.sol +367 -0
- package/utils/Lanes.sol +14 -0
- package/utils/Layout.sol +0 -2
- 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/commands/admin/Label.sol +0 -32
- package/commands/admin/Schemas.sol +0 -32
- package/core/Payable.sol +0 -53
- package/events/Labeled.sol +0 -21
- package/events/Schema.sol +0 -23
- package/utils/Value.sol +0 -43
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
/// @notice Mutable native-value budget shared across internal calls.
|
|
5
|
+
struct Budget {
|
|
6
|
+
/// @dev Remaining unspent native value in wei.
|
|
7
|
+
uint remaining;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// @title Budgets
|
|
11
|
+
/// @notice Opening and mutation helpers for standalone native-value budgets.
|
|
12
|
+
library Budgets {
|
|
13
|
+
/// @dev Thrown when an operation attempts to spend more value than remains.
|
|
14
|
+
error InsufficientValue();
|
|
15
|
+
|
|
16
|
+
/// @notice Open a standalone budget containing the current call value.
|
|
17
|
+
/// @return budget Budget initialized with `msg.value`.
|
|
18
|
+
function open() internal view returns (Budget memory budget) {
|
|
19
|
+
budget.remaining = msg.value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// @notice Deduct the EVM value lane of `resources` from `budget`.
|
|
23
|
+
/// @dev EVM resources use the low 128 bits as native value/endowment.
|
|
24
|
+
/// @param budget Mutable budget to debit.
|
|
25
|
+
/// @param resources Packed resources whose low 128 bits contain native value.
|
|
26
|
+
/// @return value Native value to forward in wei.
|
|
27
|
+
function use(Budget memory budget, uint resources) internal pure returns (uint128 value) {
|
|
28
|
+
value = uint128(resources);
|
|
29
|
+
if (value > budget.remaining) revert InsufficientValue();
|
|
30
|
+
budget.remaining -= value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// @notice Remove and return all remaining value from `budget`.
|
|
34
|
+
/// @param budget Mutable budget to drain.
|
|
35
|
+
/// @return value Native value removed from the budget.
|
|
36
|
+
function drain(Budget memory budget) internal pure returns (uint value) {
|
|
37
|
+
value = budget.remaining;
|
|
38
|
+
budget.remaining = 0;
|
|
39
|
+
}
|
|
40
|
+
}
|