• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RigoBlock / v3-contracts / 13261352678

11 Feb 2025 10:59AM UTC coverage: 84.94% (+2.6%) from 82.368%
13261352678

Pull #622

github

web-flow
Merge f22d260e3 into 08bd3b51b
Pull Request #622: feat: automated nav

761 of 962 branches covered (79.11%)

Branch coverage included in aggregate %.

523 of 711 new or added lines in 28 files covered. (73.56%)

18 existing lines in 5 files now uncovered.

1698 of 1933 relevant lines covered (87.84%)

44.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/contracts/protocol/libraries/TransientSlot.sol
1
// SPDX-License-Identifier: MIT
2
// OpenZeppelin Contracts (last updated v5.1.0) (utils/TransientSlot.sol)
3
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
4

5
pragma solidity ^0.8.24;
6

7
/**
8
 * @dev Library for reading and writing value-types to specific transient storage slots.
9
 *
10
 * Transient slots are often used to store temporary values that are removed after the current transaction.
11
 * This library helps with reading and writing to such slots without the need for inline assembly.
12
 *
13
 *  * Example reading and writing values using transient storage:
14
 * ```solidity
15
 * contract Lock {
16
 *     using TransientSlot for *;
17
 *
18
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
19
 *     bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
20
 *
21
 *     modifier locked() {
22
 *         require(!_LOCK_SLOT.asBoolean().tload());
23
 *
24
 *         _LOCK_SLOT.asBoolean().tstore(true);
25
 *         _;
26
 *         _LOCK_SLOT.asBoolean().tstore(false);
27
 *     }
28
 * }
29
 * ```
30
 *
31
 * TIP: Consider using this library along with {SlotDerivation}.
32
 */
33
library TransientSlot {
34
    /**
35
     * @dev UDVT that represent a slot holding a address.
36
     */
37
    type AddressSlot is bytes32;
38

39
    /**
40
     * @dev Cast an arbitrary slot to a AddressSlot.
41
     */
42
    function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
NEW
43
        return AddressSlot.wrap(slot);
×
44
    }
45

46
    /**
47
     * @dev UDVT that represent a slot holding a bool.
48
     */
49
    type BooleanSlot is bytes32;
50

51
    /**
52
     * @dev Cast an arbitrary slot to a BooleanSlot.
53
     */
54
    function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
55
        return BooleanSlot.wrap(slot);
308✔
56
    }
57

58
    /**
59
     * @dev UDVT that represent a slot holding a bytes32.
60
     */
61
    type Bytes32Slot is bytes32;
62

63
    /**
64
     * @dev Cast an arbitrary slot to a Bytes32Slot.
65
     */
66
    function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
NEW
67
        return Bytes32Slot.wrap(slot);
×
68
    }
69

70
    /**
71
     * @dev UDVT that represent a slot holding a uint256.
72
     */
73
    type Uint256Slot is bytes32;
74

75
    /**
76
     * @dev Cast an arbitrary slot to a Uint256Slot.
77
     */
78
    function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
NEW
79
        return Uint256Slot.wrap(slot);
×
80
    }
81

82
    /**
83
     * @dev UDVT that represent a slot holding a int256.
84
     */
85
    type Int256Slot is bytes32;
86

87
    /**
88
     * @dev Cast an arbitrary slot to a Int256Slot.
89
     */
90
    function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
91
        return Int256Slot.wrap(slot);
277✔
92
    }
93

94
    /**
95
     * @dev Load the value held at location `slot` in transient storage.
96
     */
97
    function tload(AddressSlot slot) internal view returns (address value) {
NEW
98
        assembly ("memory-safe") {
×
99
            value := tload(slot)
100
        }
101
    }
102

103
    /**
104
     * @dev Store `value` at location `slot` in transient storage.
105
     */
106
    function tstore(AddressSlot slot, address value) internal {
NEW
107
        assembly ("memory-safe") {
×
108
            tstore(slot, value)
109
        }
110
    }
111

112
    /**
113
     * @dev Load the value held at location `slot` in transient storage.
114
     */
115
    function tload(BooleanSlot slot) internal view returns (bool value) {
116
        assembly ("memory-safe") {
113✔
117
            value := tload(slot)
118
        }
119
    }
120

121
    /**
122
     * @dev Store `value` at location `slot` in transient storage.
123
     */
124
    function tstore(BooleanSlot slot, bool value) internal {
125
        assembly ("memory-safe") {
195✔
126
            tstore(slot, value)
127
        }
128
    }
129

130
    /**
131
     * @dev Load the value held at location `slot` in transient storage.
132
     */
133
    function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
NEW
134
        assembly ("memory-safe") {
×
135
            value := tload(slot)
136
        }
137
    }
138

139
    /**
140
     * @dev Store `value` at location `slot` in transient storage.
141
     */
142
    function tstore(Bytes32Slot slot, bytes32 value) internal {
NEW
143
        assembly ("memory-safe") {
×
144
            tstore(slot, value)
145
        }
146
    }
147

148
    /**
149
     * @dev Load the value held at location `slot` in transient storage.
150
     */
151
    function tload(Uint256Slot slot) internal view returns (uint256 value) {
NEW
152
        assembly ("memory-safe") {
×
153
            value := tload(slot)
154
        }
155
    }
156

157
    /**
158
     * @dev Store `value` at location `slot` in transient storage.
159
     */
160
    function tstore(Uint256Slot slot, uint256 value) internal {
NEW
161
        assembly ("memory-safe") {
×
162
            tstore(slot, value)
163
        }
164
    }
165

166
    /**
167
     * @dev Load the value held at location `slot` in transient storage.
168
     */
169
    function tload(Int256Slot slot) internal view returns (int256 value) {
170
        assembly ("memory-safe") {
168✔
171
            value := tload(slot)
172
        }
173
    }
174

175
    /**
176
     * @dev Store `value` at location `slot` in transient storage.
177
     */
178
    function tstore(Int256Slot slot, int256 value) internal {
179
        assembly ("memory-safe") {
109✔
180
            tstore(slot, value)
181
        }
182
    }
183
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc