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

delvtech / hyperdrive / 9927927593

14 Jul 2024 12:26PM UTC coverage: 92.277%. First build
9927927593

Pull #1081

github

web-flow
Merge e5af82277 into 683f2f7cd
Pull Request #1081: Added an Aave integration

120 of 142 new or added lines in 33 files covered. (84.51%)

2115 of 2292 relevant lines covered (92.28%)

376654.76 hits per line

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

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

4
import { IERC20 } from "../interfaces/IERC20.sol";
5
import { IHyperdrive } from "../interfaces/IHyperdrive.sol";
6
import { IHyperdriveRead } from "../interfaces/IHyperdriveRead.sol";
7
import { HyperdriveAdmin } from "../internal/HyperdriveAdmin.sol";
8
import { HyperdriveCheckpoint } from "../internal/HyperdriveCheckpoint.sol";
9
import { HyperdriveLong } from "../internal/HyperdriveLong.sol";
10
import { HyperdriveLP } from "../internal/HyperdriveLP.sol";
11
import { HyperdriveMultiToken } from "../internal/HyperdriveMultiToken.sol";
12
import { HyperdriveShort } from "../internal/HyperdriveShort.sol";
13
import { HyperdriveStorage } from "../internal/HyperdriveStorage.sol";
14
import { AssetId } from "../libraries/AssetId.sol";
15
import { VERSION } from "../libraries/Constants.sol";
16
import { FixedPointMath } from "../libraries/FixedPointMath.sol";
17
import { LPMath } from "../libraries/LPMath.sol";
18

19
/// @author DELV
20
/// @title HyperdriveTarget0
21
/// @notice Hyperdrive's target 0 logic contract.
22
/// @custom:disclaimer The language used in this code is for coding convenience
23
///                    only, and is not intended to, and does not, have any
24
///                    particular legal or regulatory significance.
25
abstract contract HyperdriveTarget0 is
26
    IHyperdriveRead,
27
    HyperdriveAdmin,
28
    HyperdriveMultiToken,
29
    HyperdriveLP,
30
    HyperdriveLong,
31
    HyperdriveShort,
32
    HyperdriveCheckpoint
33
{
34
    using FixedPointMath for uint256;
35

36
    /// @notice Instantiates target0.
37
    /// @param _config The configuration of the Hyperdrive pool.
38
    constructor(
39
        IHyperdrive.PoolConfig memory _config
40
    ) HyperdriveStorage(_config) {}
41

42
    /// Admin ///
43

44
    /// @notice This function collects the governance fees accrued by the pool.
45
    /// @param _options The options that configure how the fees are settled.
46
    /// @return proceeds The governance fees collected. The units of this
47
    ///         quantity are either base or vault shares, depending on the value
48
    ///         of `_options.asBase`.
49
    function collectGovernanceFee(
50
        IHyperdrive.Options calldata _options
51
    ) external returns (uint256 proceeds) {
52
        return _collectGovernanceFee(_options);
5✔
53
    }
54

55
    /// @notice Allows an authorized address to pause this contract.
56
    /// @param _status True to pause all deposits and false to unpause them.
57
    function pause(bool _status) external {
58
        _pause(_status);
10✔
59
    }
60

61
    /// @notice Allows governance to change the fee collector.
62
    /// @param _who The new fee collector address.
63
    function setFeeCollector(address _who) external {
64
        _setFeeCollector(_who);
2✔
65
    }
66

67
    /// @notice Allows governance to change the sweep collector.
68
    /// @param _who The new sweep collector address.
69
    function setSweepCollector(address _who) external {
70
        _setSweepCollector(_who);
2✔
71
    }
72

73
    /// @dev Allows governance to transfer the checkpoint rewarder.
74
    /// @param _checkpointRewarder The new checkpoint rewarder.
75
    function setCheckpointRewarder(address _checkpointRewarder) external {
76
        _setCheckpointRewarder(_checkpointRewarder);
4✔
77
    }
78

79
    /// @notice Allows governance to change governance.
80
    /// @param _who The new governance address.
81
    function setGovernance(address _who) external {
82
        _setGovernance(_who);
1,751✔
83
    }
84

85
    /// @notice Allows governance to change the pauser status of an address.
86
    /// @param who The address to change.
87
    /// @param status The new pauser status.
88
    function setPauser(address who, bool status) external {
89
        _setPauser(who, status);
2,382✔
90
    }
91

92
    /// @notice Transfers the contract's balance of a target token to the sweep
93
    ///         collector address.
94
    /// @dev WARN: It is unlikely but possible that there is a selector overlap
95
    ///      with 'transfer'. Any integrating contracts should be checked
96
    ///      for that, as it may result in an unexpected call from this address.
97
    /// @param _target The target token to sweep.
98
    function sweep(IERC20 _target) external {
99
        _sweep(_target);
24✔
100
    }
101

102
    /// MultiToken ///
103

104
    /// @notice Transfers an amount of assets from the source to the destination.
105
    /// @param tokenID The token identifier.
106
    /// @param from The address whose balance will be reduced.
107
    /// @param to The address whose balance will be increased.
108
    /// @param amount The amount of token to move.
109
    function transferFrom(
110
        uint256 tokenID,
111
        address from,
112
        address to,
113
        uint256 amount
114
    ) external {
115
        // Forward to our internal version
116
        _transferFrom(tokenID, from, to, amount, msg.sender);
3✔
117
    }
118

119
    /// @notice Permissioned transfer for the bridge to access, only callable by
120
    ///         the ERC20 linking bridge.
121
    /// @param tokenID The token identifier.
122
    /// @param from The address whose balance will be reduced.
123
    /// @param to The address whose balance will be increased.
124
    /// @param amount The amount of token to move.
125
    /// @param caller The msg.sender from the bridge.
126
    function transferFromBridge(
127
        uint256 tokenID,
128
        address from,
129
        address to,
130
        uint256 amount,
131
        address caller
132
    ) external onlyLinker(tokenID) {
133
        // Route to our internal transfer
134
        _transferFrom(tokenID, from, to, amount, caller);
101✔
135
    }
136

137
    /// @notice Allows the compatibility linking contract to forward calls to
138
    ///         set asset approvals.
139
    /// @param tokenID The asset to approve the use of.
140
    /// @param operator The address who will be able to use the tokens.
141
    /// @param amount The max tokens the approved person can use, setting to
142
    ///        uint256.max will cause the value to never decrement [saving gas
143
    ///        on transfer].
144
    /// @param caller The eth address which called the linking contract.
145
    function setApprovalBridge(
146
        uint256 tokenID,
147
        address operator,
148
        uint256 amount,
149
        address caller
150
    ) external onlyLinker(tokenID) {
151
        _setApproval(tokenID, operator, amount, caller);
4✔
152
    }
153

154
    /// @notice Allows a user to approve an operator to use all of their assets.
155
    /// @param operator The eth address which can access the caller's assets.
156
    /// @param approved True to approve, false to remove approval.
157
    function setApprovalForAll(address operator, bool approved) external {
158
        // set the appropriate state
159
        _isApprovedForAll[msg.sender][operator] = approved;
60✔
160
        // Emit an event to track approval
161
        emit ApprovalForAll(msg.sender, operator, approved);
60✔
162
    }
163

164
    /// @notice Allows a user to set an approval for an individual asset with
165
    ///         specific amount.
166
    /// @param tokenID The asset to approve the use of.
167
    /// @param operator The address who will be able to use the tokens.
168
    /// @param amount The max tokens the approved person can use, setting to
169
    ///        uint256.max will cause the value to never decrement (saving gas
170
    ///        on transfer).
171
    function setApproval(
172
        uint256 tokenID,
173
        address operator,
174
        uint256 amount
175
    ) external {
176
        _setApproval(tokenID, operator, amount, msg.sender);
45✔
177
    }
178

179
    /// @notice Transfers several assets from one account to another.
180
    /// @param from The source account.
181
    /// @param to The destination account.
182
    /// @param ids The array of token ids of the asset to transfer.
183
    /// @param values The amount of each token to transfer.
184
    function batchTransferFrom(
185
        address from,
186
        address to,
187
        uint256[] calldata ids,
188
        uint256[] calldata values
189
    ) external {
190
        _batchTransferFrom(from, to, ids, values);
6✔
191
    }
192

193
    /// @notice Allows a caller who is not the owner of an account to execute
194
    ///         the functionality of 'approve' for all assets with the owner's
195
    ///         signature.
196
    /// @param domainSeparator The EIP712 domain separator of the contract.
197
    /// @param permitTypeHash The EIP712 domain separator of the contract.
198
    /// @param owner The owner of the account which is having the new approval set.
199
    /// @param spender The address which will be allowed to spend owner's tokens.
200
    /// @param _approved A boolean of the approval status to set to.
201
    /// @param deadline The timestamp which the signature must be submitted by
202
    ///        to be valid.
203
    /// @param v Extra ECDSA data which allows public key recovery from
204
    ///        signature assumed to be 27 or 28.
205
    /// @param r The r component of the ECDSA signature.
206
    /// @param s The s component of the ECDSA signature.
207
    /// @dev The signature for this function follows EIP 712 standard and should
208
    ///      be generated with the eth_signTypedData JSON RPC call instead of
209
    ///      the eth_sign JSON RPC call. If using out of date parity signing
210
    ///      libraries the v component may need to be adjusted. Also it is very
211
    ///      rare but possible for v to be other values, those values are not
212
    ///      supported.
213
    function permitForAll(
214
        bytes32 domainSeparator,
215
        bytes32 permitTypeHash,
216
        address owner,
217
        address spender,
218
        bool _approved,
219
        uint256 deadline,
220
        uint8 v,
221
        bytes32 r,
222
        bytes32 s
223
    ) external {
224
        _permitForAll(
8✔
225
            domainSeparator,
226
            permitTypeHash,
227
            owner,
228
            spender,
229
            _approved,
230
            deadline,
231
            v,
232
            r,
233
            s
234
        );
235
    }
236

237
    /// Getters ///
238

239
    /// @notice Gets the instance's name.
240
    /// @return The instance's name.
241
    function name() external view returns (string memory) {
242
        _revert(abi.encode(_name));
93✔
243
    }
244

245
    /// @notice Gets the instance's kind.
246
    /// @return The instance's kind.
247
    function kind() external pure virtual returns (string memory);
248

249
    /// @notice Gets the instance's version.
250
    /// @return The instance's version.
251
    function version() external pure returns (string memory) {
252
        _revert(abi.encode(VERSION));
80✔
253
    }
254

255
    /// @notice Gets the pauser status of an address.
256
    /// @param _account The account to check.
257
    /// @return The pauser status.
258
    function isPauser(address _account) external view returns (bool) {
259
        _revert(abi.encode(_pausers[_account]));
1✔
260
    }
261

262
    /// @notice Gets the base token.
263
    /// @return The base token address.
264
    function baseToken() external view returns (address) {
265
        _revert(abi.encode(_baseToken));
1,868✔
266
    }
267

268
    /// @notice Gets the vault shares token.
269
    /// @return The vault shares token address.
270
    function vaultSharesToken() external view returns (address) {
271
        _revert(abi.encode(_vaultSharesToken));
28✔
272
    }
273

274
    /// @notice Gets a specified checkpoint.
275
    /// @param _checkpointTime The checkpoint time.
276
    /// @return The checkpoint.
277
    function getCheckpoint(
278
        uint256 _checkpointTime
279
    ) external view returns (IHyperdrive.Checkpoint memory) {
280
        _revert(abi.encode(_checkpoints[_checkpointTime]));
267✔
281
    }
282

283
    /// @notice Gets the checkpoint exposure at a specified time.
284
    /// @param _checkpointTime The checkpoint time.
285
    /// @return The checkpoint exposure.
286
    function getCheckpointExposure(
287
        uint256 _checkpointTime
288
    ) external view returns (int256) {
289
        _revert(
19,884✔
290
            abi.encode(_nonNettedLongs(_checkpointTime + _positionDuration))
291
        );
292
    }
293

294
    /// @notice Gets the pool's configuration parameters.
295
    /// @dev These parameters are immutable, so this should only need to be
296
    ///      called once.
297
    /// @return The PoolConfig struct.
298
    function getPoolConfig()
299
        external
300
        view
301
        returns (IHyperdrive.PoolConfig memory)
302
    {
303
        _revert(
1,429,989✔
304
            abi.encode(
305
                IHyperdrive.PoolConfig({
306
                    baseToken: _baseToken,
307
                    vaultSharesToken: _vaultSharesToken,
308
                    linkerFactory: _linkerFactory,
309
                    linkerCodeHash: _linkerCodeHash,
310
                    initialVaultSharePrice: _initialVaultSharePrice,
311
                    minimumShareReserves: _minimumShareReserves,
312
                    minimumTransactionAmount: _minimumTransactionAmount,
313
                    circuitBreakerDelta: _circuitBreakerDelta,
314
                    positionDuration: _positionDuration,
315
                    checkpointDuration: _checkpointDuration,
316
                    timeStretch: _timeStretch,
317
                    governance: _governance,
318
                    feeCollector: _feeCollector,
319
                    sweepCollector: _sweepCollector,
320
                    checkpointRewarder: _checkpointRewarder,
321
                    fees: IHyperdrive.Fees(
322
                        _curveFee,
323
                        _flatFee,
324
                        _governanceLPFee,
325
                        _governanceZombieFee
326
                    )
327
                })
328
            )
329
        );
330
    }
331

332
    /// @notice Gets info about the pool's reserves and other state that is
333
    ///         important to evaluate potential trades.
334
    /// @return The pool info.
335
    function getPoolInfo() external view returns (IHyperdrive.PoolInfo memory) {
336
        uint256 vaultSharePrice = _pricePerVaultShare();
140,273✔
337
        uint256 lpTotalSupply = _totalSupply[AssetId._LP_ASSET_ID] +
140,273✔
338
            _totalSupply[AssetId._WITHDRAWAL_SHARE_ASSET_ID] -
339
            _withdrawPool.readyToWithdraw;
340
        uint256 presentValue;
140,273✔
341
        if (vaultSharePrice > 0) {
140,273✔
342
            (presentValue, ) = LPMath.calculatePresentValueSafe(
139,673✔
343
                _getPresentValueParams(vaultSharePrice)
344
            );
345
            presentValue = presentValue.mulDown(vaultSharePrice);
139,673✔
346
        }
347
        IHyperdrive.PoolInfo memory poolInfo = IHyperdrive.PoolInfo({
140,273✔
348
            shareReserves: _marketState.shareReserves,
349
            shareAdjustment: _marketState.shareAdjustment,
350
            zombieBaseProceeds: _marketState.zombieBaseProceeds,
351
            zombieShareReserves: _marketState.zombieShareReserves,
352
            bondReserves: _marketState.bondReserves,
353
            vaultSharePrice: vaultSharePrice,
354
            longsOutstanding: _marketState.longsOutstanding,
355
            longAverageMaturityTime: _marketState.longAverageMaturityTime,
356
            shortsOutstanding: _marketState.shortsOutstanding,
357
            shortAverageMaturityTime: _marketState.shortAverageMaturityTime,
358
            lpTotalSupply: lpTotalSupply,
359
            lpSharePrice: lpTotalSupply == 0
360
                ? 0
361
                : presentValue.divDown(lpTotalSupply),
362
            withdrawalSharesReadyToWithdraw: _withdrawPool.readyToWithdraw,
363
            withdrawalSharesProceeds: _withdrawPool.proceeds,
364
            longExposure: _marketState.longExposure
365
        });
366
        _revert(abi.encode(poolInfo));
140,273✔
367
    }
368

369
    /// @notice Gets information about the withdrawal pool.
370
    /// @return Hyperdrive's withdrawal pool information.
371
    function getWithdrawPool()
372
        external
373
        view
374
        returns (IHyperdrive.WithdrawPool memory)
375
    {
376
        _revert(
2✔
377
            abi.encode(
378
                IHyperdrive.WithdrawPool({
379
                    readyToWithdraw: _withdrawPool.readyToWithdraw,
380
                    proceeds: _withdrawPool.proceeds
381
                })
382
            )
383
        );
384
    }
385

386
    /// @notice Gets info about the fees presently accrued by the pool.
387
    /// @return Governance fees denominated in shares yet to be collected.
388
    function getUncollectedGovernanceFees() external view returns (uint256) {
389
        _revert(abi.encode(_governanceFeesAccrued));
305✔
390
    }
391

392
    /// @notice Gets the market state.
393
    /// @return The market state.
394
    function getMarketState()
395
        external
396
        view
397
        returns (IHyperdrive.MarketState memory)
398
    {
399
        _revert(abi.encode(_marketState));
13✔
400
    }
401

402
    /// @notice Allows plugin data libs to provide getters or other complex
403
    ///         logic instead of the main.
404
    /// @param _slots The storage slots the caller wants the data from.
405
    /// @return A raw array of loaded data.
406
    function load(
407
        uint256[] calldata _slots
408
    ) external view returns (bytes32[] memory) {
409
        bytes32[] memory loaded = new bytes32[](_slots.length);
1✔
410

411
        // Iterate on requested loads and then do them.
412
        for (uint256 i = 0; i < _slots.length; ) {
1✔
413
            uint256 slot = _slots[i];
1✔
414
            bytes32 data;
1✔
415
            assembly ("memory-safe") {
416
                data := sload(slot)
1✔
417
            }
418
            loaded[i] = data;
1✔
419
            unchecked {
420
                ++i;
1✔
421
            }
422
        }
423

424
        _revert(abi.encode(loaded));
1✔
425
    }
426

427
    /// @notice Convert an amount of vault shares to an amount of base.
428
    /// @param _shareAmount The vault shares amount.
429
    /// @return baseAmount The base amount.
430
    function convertToBase(
431
        uint256 _shareAmount
432
    ) external view returns (uint256) {
NEW
433
        return _convertToBase(_shareAmount);
×
434
    }
435

436
    /// @notice Convert an amount of base to an amount of vault shares.
437
    /// @param _baseAmount The base amount.
438
    /// @return shareAmount The vault shares amount.
439
    function convertToShares(
440
        uint256 _baseAmount
441
    ) external view returns (uint256) {
NEW
442
        return _convertToShares(_baseAmount);
×
443
    }
444

445
    /// @notice Gets an account's balance of a sub-token.
446
    /// @param tokenId The sub-token id.
447
    /// @param account The account.
448
    /// @return The balance.
449
    function balanceOf(
450
        uint256 tokenId,
451
        address account
452
    ) external view returns (uint256) {
453
        _revert(abi.encode(_balanceOf[tokenId][account]));
3,892✔
454
    }
455

456
    /// @notice Gets the total supply of a sub-token.
457
    /// @param tokenId The sub-token id.
458
    /// @return The total supply.
459
    function totalSupply(uint256 tokenId) external view returns (uint256) {
460
        _revert(abi.encode(_totalSupply[tokenId]));
42,260✔
461
    }
462

463
    /// @notice Gets the approval status of an operator for an account.
464
    /// @param account The account.
465
    /// @param operator The operator.
466
    /// @return The approval status.
467
    function isApprovedForAll(
468
        address account,
469
        address operator
470
    ) external view returns (bool) {
471
        _revert(abi.encode(_isApprovedForAll[account][operator]));
10✔
472
    }
473

474
    /// @notice Gets the approval status of an operator for an account.
475
    /// @param tokenId The sub-token id.
476
    /// @param account The account.
477
    /// @param spender The spender.
478
    /// @return The approval status.
479
    function perTokenApprovals(
480
        uint256 tokenId,
481
        address account,
482
        address spender
483
    ) external view returns (uint256) {
484
        _revert(abi.encode(_perTokenApprovals[tokenId][account][spender]));
72✔
485
    }
486

487
    /// @notice Gets the decimals of the MultiToken. This is the same as the
488
    ///         decimals used by the base token.
489
    /// @return The decimals of the MultiToken.
490
    function decimals() external view virtual returns (uint8) {
491
        _revert(abi.encode(_baseToken.decimals()));
4✔
492
    }
493

494
    /// @notice Gets the name of a sub-token.
495
    /// @param tokenId The sub-token id.
496
    /// @return The name.
497
    function name(uint256 tokenId) external pure returns (string memory) {
498
        _revert(abi.encode(AssetId.assetIdToName(tokenId)));
2✔
499
    }
500

501
    /// @notice Gets the symbol of a sub-token.
502
    /// @param tokenId The sub-token id.
503
    /// @return The symbol.
504
    function symbol(uint256 tokenId) external pure returns (string memory) {
505
        _revert(abi.encode(AssetId.assetIdToSymbol(tokenId)));
2✔
506
    }
507

508
    /// @notice Gets the permitForAll signature nonce for an account.
509
    /// @param account The account.
510
    /// @return The signature nonce.
511
    function nonces(address account) external view returns (uint256) {
512
        _revert(abi.encode(_nonces[account]));
9✔
513
    }
514

515
    /// Helpers ///
516

517
    /// @dev Reverts with the provided bytes. This is useful in getters used
518
    ///      with the force-revert delegatecall pattern.
519
    /// @param _bytes The bytes to revert with.
520
    function _revert(bytes memory _bytes) internal pure {
521
        revert IHyperdrive.ReturnData(_bytes);
1,640,976✔
522
    }
523
}
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