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

delvtech / hyperdrive / 10078266229

24 Jul 2024 02:09PM UTC coverage: 91.041% (-0.6%) from 91.602%
10078266229

Pull #1110

github

web-flow
Merge b0abc7ad6 into 2514eecb1
Pull Request #1110: etherfi yield source

49 of 68 new or added lines in 10 files covered. (72.06%)

1 existing line in 1 file now uncovered.

2195 of 2411 relevant lines covered (91.04%)

360130.92 hits per line

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

97.96
/contracts/src/external/Hyperdrive.sol
1
// SPDX-License-Identifier: Apache-2.0
2
pragma solidity 0.8.20;
3

4
import { IERC20 } from "../interfaces/IERC20.sol";
5
import { HyperdriveTarget0 } from "../external/HyperdriveTarget0.sol";
6
import { IHyperdrive } from "../interfaces/IHyperdrive.sol";
7
import { IHyperdriveCore } from "../interfaces/IHyperdriveCore.sol";
8
import { IMultiTokenCore } from "../interfaces/IMultiTokenCore.sol";
9
import { HyperdriveAdmin } from "../internal/HyperdriveAdmin.sol";
10
import { HyperdriveCheckpoint } from "../internal/HyperdriveCheckpoint.sol";
11
import { HyperdriveLong } from "../internal/HyperdriveLong.sol";
12
import { HyperdriveLP } from "../internal/HyperdriveLP.sol";
13
import { HyperdriveShort } from "../internal/HyperdriveShort.sol";
14
import { HyperdriveStorage } from "../internal/HyperdriveStorage.sol";
15

16
///      ______  __                           _________      _____
17
///      ___  / / /____  ___________________________  /_________(_)__   ______
18
///      __  /_/ /__  / / /__  __ \  _ \_  ___/  __  /__  ___/_  /__ | / /  _ \
19
///      _  __  / _  /_/ /__  /_/ /  __/  /   / /_/ / _  /   _  / __ |/ //  __/
20
///      /_/ /_/  _\__, / _   ___/\___//_/    \__,_/  /_/    /_/  _____/ \___/
21
///               /____/   /_/
22
///                     XXX          ++          ++          XXX
23
///     ############   XXXXX        ++0+        +0++        XXXXX   ###########
24
///   ##////////////########       ++00++      ++00++       ########///////////##
25
///  ##////////////##########      ++000++    ++000++      ##########///////////##
26
///  ##%%%%%%/////      ######     ++0000+    +0000++     ######     /////%%%%%%##
27
///    %%%%%%%%&&             ##   ++0000+    +0000++   ##           &&%%%%%%%%%
28
///         %&&&                ##  +o000+    +000o+  ##              &&&%
29
///                              ## ++00+-    -+00++ ##
30
///                               #% ++0+      +0++ %#
31
///                               ###-:Oo.++++.oO:-###
32
///                                ##: 00++++++00 :##
33
///                    #S###########* 0++00+++00++0 *##########S#
34
///                  #S               % $ 0+++0 $ %              S#
35
///                #S   ----------   %+++++:#:+++++%-----------    S#
36
///              #S   ------------- %++++: ### :++++%------------    S#
37
///             S    ---------------%++++*\ | /*++++%-------------     S
38
///           #S     --------------- %++++ ~W~ ++++%666--o UUUU o-      S#
39
///         #S?      ---------------  %+++++~+++++%&&&8 o  \  /  o       ?S#
40
///        ?*????**+++;::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::;+++**????*?
41
///      #?+////////////////////////////////////////////////////////////////+?#
42
///    #;;;;;//////////////////////////////////////////////////////////////;;;;;#
43
///  S;;;;;;;;;//////////////////////////////////////////////////////////;;;;;;;;;S
44
/// /;;;;;;;;;;;///////////////////////////////////////////////////////;;;;;;;;;;;;\
45
/// |||OOOOOOOO||OOOOOOOO=========== __  ___        ===========OOOOOOOO||OOOOOOOO|||
46
/// |||OOOOOOOO||OOOOOOOO===========|  \[__ |   \  /===========OOOOOOOO||OOOOOOOO|||
47
/// |||OOOOOOOO||OOOOOOOO===========|__/[___|___ \/ ===========OOOOOOOO||OOOOOOOO|||
48
/// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
49
/// |||////////000000000000\\\\\\\\|:::::::::::::::|////////00000000000\\\\\\\\\\|||
50
/// SSS\\\\\\\\000000000000////////|:::::0x666:::::|\\\\\\\\00000000000//////////SSS
51
/// SSS|||||||||||||||||||||||||||||:::::::::::::::||||||||||||||||||||||||||||||SSS
52
/// SSSSSSSS|_______________|______________||_______________|______________|SSSSSSSS
53
/// SSSSSSSS                                                                SSSSSSSS
54
/// SSSSSSSS                                                                SSSSSSSS
55
///
56
/// @author DELV
57
/// @title Hyperdrive
58
/// @notice A fixed-rate AMM that mints bonds on demand for longs and shorts.
59
/// @custom:disclaimer The language used in this code is for coding convenience
60
///                    only, and is not intended to, and does not, have any
61
///                    particular legal or regulatory significance.
62
abstract contract Hyperdrive is
63
    IHyperdriveCore,
64
    HyperdriveAdmin,
65
    HyperdriveLP,
66
    HyperdriveLong,
67
    HyperdriveShort,
68
    HyperdriveCheckpoint
69
{
70
    /// @notice The target0 address. This is a logic contract that contains all
71
    ///         of the getters for the Hyperdrive pool as well as some stateful
72
    ///         functions.
73
    address public immutable target0;
74

75
    /// @notice The target1 address. This is a logic contract that contains
76
    ///         stateful functions.
77
    address public immutable target1;
78

79
    /// @notice The target2 address. This is a logic contract that contains
80
    ///         stateful functions.
81
    address public immutable target2;
82

83
    /// @notice The target3 address. This is a logic contract that contains
84
    ///         stateful functions.
85
    address public immutable target3;
86

87
    /// @notice The target4 address. This is a logic contract that contains
88
    ///         stateful functions.
89
    address public immutable target4;
90

91
    /// @notice The typehash used to calculate the EIP712 hash for `permitForAll`.
92
    bytes32 public constant PERMIT_TYPEHASH =
93
        keccak256(
94
            "PermitForAll(address owner,address spender,bool _approved,uint256 nonce,uint256 deadline)"
95
        );
96

97
    /// @notice Instantiates a Hyperdrive pool.
98
    /// @param __name The pool's name.
99
    /// @param _config The configuration of the pool.
100
    /// @param _target0 The target0 address.
101
    /// @param _target1 The target1 address.
102
    /// @param _target2 The target2 address.
103
    /// @param _target3 The target3 address.
104
    /// @param _target4 The target4 address.
105
    constructor(
106
        string memory __name,
107
        IHyperdrive.PoolConfig memory _config,
108
        address _target0,
109
        address _target1,
110
        address _target2,
111
        address _target3,
112
        address _target4
113
    ) HyperdriveStorage(_config) {
114
        // NOTE: This is initialized here rather than in `HyperdriveStorage` to
115
        // avoid needing to set the name in all of the target contracts. Since
116
        // this is a storage value, it will still be accessible.
117
        //
118
        // Initialize the pool's name.
119
        _name = __name;
244,933✔
120

121
        // Initialize the target contracts.
122
        target0 = _target0;
57,936✔
123
        target1 = _target1;
525,221✔
124
        target2 = _target2;
525,123✔
125
        target3 = _target3;
11,359✔
126
        target4 = _target4;
58,074✔
127
    }
128

129
    /// @notice If we get to the fallback function, we make a read-only
130
    ///         delegatecall to the target0 contract. This target contains all
131
    ///         of the getters for the Hyperdrive pool.
132
    /// @param _data The data to be passed to the data provider.
133
    /// @return The return data from the data provider.
134
    fallback(bytes calldata _data) external returns (bytes memory) {
135
        // We use a force-revert delegatecall pattern to ensure that no state
136
        // changes were made during the read call.
137
        (bool success, bytes memory returndata) = target0.delegatecall(_data);
1,650,168✔
138
        if (success) {
1,650,168✔
139
            revert IHyperdrive.UnexpectedSuccess();
1✔
140
        }
141
        bytes4 selector = bytes4(returndata);
1,650,167✔
142
        if (selector != IHyperdrive.ReturnData.selector) {
1,650,167✔
143
            assembly {
UNCOV
144
                revert(add(returndata, 32), mload(returndata))
×
145
            }
146
        }
147

148
        // Read calls return their data inside of a `ReturnData(bytes)` error.
149
        // We unwrap the error and return the contents.
150
        assembly {
151
            mstore(add(returndata, 0x4), sub(mload(returndata), 4))
1,650,167✔
152
            returndata := add(returndata, 0x4)
1,650,167✔
153
        }
154
        returndata = abi.decode(returndata, (bytes));
1,650,167✔
155

156
        return returndata;
1,650,167✔
157
    }
158

159
    /// Longs ///
160

161
    /// @inheritdoc IHyperdriveCore
162
    function openLong(
163
        uint256,
164
        uint256,
165
        uint256,
166
        IHyperdrive.Options calldata
167
    ) external payable returns (uint256, uint256) {
168
        _delegate(target2);
20,761✔
169
    }
170

171
    /// @inheritdoc IHyperdriveCore
172
    function closeLong(
173
        uint256,
174
        uint256,
175
        uint256,
176
        IHyperdrive.Options calldata
177
    ) external returns (uint256) {
178
        _delegate(target1);
12,816✔
179
    }
180

181
    /// Shorts ///
182

183
    /// @inheritdoc IHyperdriveCore
184
    function openShort(
185
        uint256,
186
        uint256,
187
        uint256,
188
        IHyperdrive.Options calldata
189
    ) external payable returns (uint256, uint256) {
190
        _delegate(target2);
19,427✔
191
    }
192

193
    /// @inheritdoc IHyperdriveCore
194
    function closeShort(
195
        uint256,
196
        uint256,
197
        uint256,
198
        IHyperdrive.Options calldata
199
    ) external returns (uint256) {
200
        _delegate(target1);
13,477✔
201
    }
202

203
    /// LPs ///
204

205
    /// @inheritdoc IHyperdriveCore
206
    function initialize(
207
        uint256,
208
        uint256,
209
        IHyperdrive.Options calldata
210
    ) external payable returns (uint256) {
211
        _delegate(target3);
13,962✔
212
    }
213

214
    /// @inheritdoc IHyperdriveCore
215
    function addLiquidity(
216
        uint256,
217
        uint256,
218
        uint256,
219
        uint256,
220
        IHyperdrive.Options calldata
221
    ) external payable returns (uint256) {
222
        _delegate(target3);
4,137✔
223
    }
224

225
    /// @inheritdoc IHyperdriveCore
226
    function removeLiquidity(
227
        uint256,
228
        uint256,
229
        IHyperdrive.Options calldata
230
    ) external returns (uint256, uint256) {
231
        _delegate(target4);
3,780✔
232
    }
233

234
    /// @inheritdoc IHyperdriveCore
235
    function redeemWithdrawalShares(
236
        uint256,
237
        uint256,
238
        IHyperdrive.Options calldata
239
    ) external returns (uint256, uint256) {
240
        _delegate(target4);
1,892✔
241
    }
242

243
    /// Checkpoints ///
244

245
    /// @inheritdoc IHyperdriveCore
246
    function checkpoint(uint256, uint256) external {
247
        _delegate(target4);
1,073,954✔
248
    }
249

250
    /// Admin ///
251

252
    /// @inheritdoc IHyperdriveCore
253
    function collectGovernanceFee(
254
        IHyperdrive.Options calldata
255
    ) external returns (uint256) {
256
        _delegate(target0);
5✔
257
    }
258

259
    /// @inheritdoc IHyperdriveCore
260
    function pause(bool) external {
261
        _delegate(target0);
10✔
262
    }
263

264
    /// @inheritdoc IHyperdriveCore
265
    function setFeeCollector(address) external {
266
        _delegate(target0);
2✔
267
    }
268

269
    /// @inheritdoc IHyperdriveCore
270
    function setSweepCollector(address) external {
271
        _delegate(target0);
2✔
272
    }
273

274
    /// @inheritdoc IHyperdriveCore
275
    function setCheckpointRewarder(address) external {
276
        _delegate(target0);
4✔
277
    }
278

279
    /// @inheritdoc IHyperdriveCore
280
    function setGovernance(address) external {
281
        _delegate(target0);
1,745✔
282
    }
283

284
    /// @inheritdoc IHyperdriveCore
285
    function setPauser(address, bool) external {
286
        _delegate(target0);
2,422✔
287
    }
288

289
    /// @inheritdoc IHyperdriveCore
290
    function sweep(IERC20) external {
291
        _delegate(target0);
27✔
292
    }
293

294
    /// MultiToken ///
295

296
    /// @inheritdoc IMultiTokenCore
297
    function transferFrom(uint256, address, address, uint256) external {
298
        _delegate(target0);
3✔
299
    }
300

301
    /// @inheritdoc IMultiTokenCore
302
    function transferFromBridge(
303
        uint256,
304
        address,
305
        address,
306
        uint256,
307
        address
308
    ) external {
309
        _delegate(target0);
101✔
310
    }
311

312
    /// @inheritdoc IMultiTokenCore
313
    function setApprovalBridge(uint256, address, uint256, address) external {
314
        _delegate(target0);
4✔
315
    }
316

317
    /// @inheritdoc IMultiTokenCore
318
    function setApprovalForAll(address, bool) external {
319
        _delegate(target0);
60✔
320
    }
321

322
    /// @inheritdoc IMultiTokenCore
323
    function setApproval(uint256, address, uint256) external {
324
        _delegate(target0);
45✔
325
    }
326

327
    /// @inheritdoc IMultiTokenCore
328
    function batchTransferFrom(
329
        address,
330
        address,
331
        uint256[] calldata,
332
        uint256[] calldata
333
    ) external {
334
        _delegate(target0);
6✔
335
    }
336

337
    /// @notice Allows a caller who is not the owner of an account to execute the
338
    ///      functionality of 'approve' for all assets with the owners signature.
339
    /// @param owner The owner of the account which is having the new approval set.
340
    /// @param spender The address which will be allowed to spend owner's tokens.
341
    /// @param _approved A boolean of the approval status to set to.
342
    /// @param deadline The timestamp which the signature must be submitted by
343
    ///        to be valid.
344
    /// @param v Extra ECDSA data which allows public key recovery from
345
    ///        signature assumed to be 27 or 28.
346
    /// @param r The r component of the ECDSA signature.
347
    /// @param s The s component of the ECDSA signature.
348
    /// @dev The signature for this function follows EIP 712 standard and should
349
    ///      be generated with the eth_signTypedData JSON RPC call instead of
350
    ///      the eth_sign JSON RPC call. If using out of date parity signing
351
    ///      libraries the v component may need to be adjusted. Also it is very
352
    ///      rare but possible for v to be other values, those values are not
353
    ///      supported.
354
    function permitForAll(
355
        address owner,
356
        address spender,
357
        bool _approved,
358
        uint256 deadline,
359
        uint8 v,
360
        bytes32 r,
361
        bytes32 s
362
    ) external {
363
        (bool success, bytes memory result) = target0.delegatecall(
8✔
364
            abi.encodeCall(
365
                HyperdriveTarget0.permitForAll,
366
                (
367
                    domainSeparator(),
368
                    PERMIT_TYPEHASH,
369
                    owner,
370
                    spender,
371
                    _approved,
372
                    deadline,
373
                    v,
374
                    r,
375
                    s
376
                )
377
            )
378
        );
379
        if (!success) {
8✔
380
            assembly {
381
                revert(add(result, 32), mload(result))
4✔
382
            }
383
        }
384
        assembly {
385
            return(add(result, 32), mload(result))
4✔
386
        }
387
    }
388

389
    /// EIP712
390

391
    /// @notice Computes the EIP712 domain separator which prevents user signed
392
    ///         messages for this contract to be replayed in other contracts:
393
    ///         https://eips.ethereum.org/EIPS/eip-712.
394
    /// @return The EIP712 domain separator.
395
    function domainSeparator() public view returns (bytes32) {
396
        return
16✔
397
            keccak256(
16✔
398
                abi.encode(
399
                    keccak256(
400
                        "EIP712Domain(string version,uint256 chainId,address verifyingContract)"
401
                    ),
402
                    keccak256(bytes("1")),
403
                    block.chainid,
404
                    address(this)
405
                )
406
            );
407
    }
408

409
    /// Helpers ///
410

411
    /// @dev Makes a delegatecall to the extras contract with the provided
412
    ///      calldata. This will revert if the call is unsuccessful.
413
    /// @param _target The target of the delegatecall.
414
    /// @return The returndata of the delegatecall.
415
    function _delegate(address _target) internal returns (bytes memory) {
416
        (bool success, bytes memory result) = _target.delegatecall(msg.data);
1,168,642✔
417
        if (!success) {
1,168,642✔
418
            assembly {
419
                revert(add(result, 32), mload(result))
3,100✔
420
            }
421
        }
422
        assembly {
423
            return(add(result, 32), mload(result))
1,165,542✔
424
        }
425
    }
426
}
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