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

delvtech / hyperdrive / 13146439166

04 Feb 2025 10:58PM UTC coverage: 89.245% (-0.2%) from 89.489%
13146439166

Pull #1238

github

jalextowle
Fixed the code size issue
Pull Request #1238: ERC1155 Compatibility

70 of 82 new or added lines in 6 files covered. (85.37%)

1 existing line in 1 file now uncovered.

3037 of 3403 relevant lines covered (89.24%)

325484.76 hits per line

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

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

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

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

39
    /// @notice Instantiates target0.
40
    /// @param _config The configuration of the Hyperdrive pool.
41
    /// @param __adminController The admin controller that will specify the
42
    ///        admin parameters for this contract.
43
    constructor(
44
        IHyperdrive.PoolConfig memory _config,
45
        IHyperdriveAdminController __adminController
46
    ) HyperdriveStorage(_config, __adminController) {}
47

48
    /// Admin ///
49

50
    // TODO: This function doesn't do anything anymore and is only here for
51
    // backwards compatability. This can be removed when the factory is upgraded.
52
    //
53
    /// @notice A stub for the old setPauser functions that doesn't do anything
54
    ///         anymore.
55
    /// @dev Don't call this. It doesn't do anything.
56
    function setGovernance(address) external {}
57

58
    // TODO: This function doesn't do anything anymore and is only here for
59
    // backwards compatability. This can be removed when the factory is upgraded.
60
    //
61
    /// @notice A stub for the old setPauser functions that doesn't do anything
62
    ///         anymore.
63
    /// @dev Don't call this. It doesn't do anything.
64
    function setPauser(address, bool) external {}
65

66
    /// @notice This function collects the governance fees accrued by the pool.
67
    /// @param _options The options that configure how the fees are settled.
68
    /// @return proceeds The governance fees collected. The units of this
69
    ///         quantity are either base or vault shares, depending on the value
70
    ///         of `_options.asBase`.
71
    function collectGovernanceFee(
72
        IHyperdrive.Options calldata _options
73
    ) external returns (uint256 proceeds) {
74
        return _collectGovernanceFee(_options);
5✔
75
    }
76

77
    /// @notice Allows an authorized address to pause this contract.
78
    /// @param _status True to pause all deposits and false to unpause them.
79
    function pause(bool _status) external {
80
        _pause(_status);
11✔
81
    }
82

83
    /// @notice Transfers the contract's balance of a target token to the sweep
84
    ///         collector address.
85
    /// @dev WARN: It is unlikely but possible that there is a selector overlap
86
    ///      with 'transfer'. Any integrating contracts should be checked
87
    ///      for that, as it may result in an unexpected call from this address.
88
    /// @param _target The target token to sweep.
89
    function sweep(IERC20 _target) external {
90
        _sweep(_target);
77✔
91
    }
92

93
    /// MultiToken ///
94

95
    /// @notice Permissioned transfer for the bridge to access, only callable by
96
    ///         the ERC20 linking bridge.
97
    /// @param tokenID The token identifier.
98
    /// @param from The address whose balance will be reduced.
99
    /// @param to The address whose balance will be increased.
100
    /// @param amount The amount of token to move.
101
    /// @param caller The msg.sender from the bridge.
102
    function transferFromBridge(
103
        uint256 tokenID,
104
        address from,
105
        address to,
106
        uint256 amount,
107
        address caller
108
    ) external onlyLinker(tokenID) {
109
        // Route to our internal transfer
110
        _transferFrom(tokenID, from, to, amount, caller);
101✔
111
    }
112

113
    /// @notice Allows the compatibility linking contract to forward calls to
114
    ///         set asset approvals.
115
    /// @param tokenID The asset to approve the use of.
116
    /// @param operator The address who will be able to use the tokens.
117
    /// @param amount The max tokens the approved person can use, setting to
118
    ///        uint256.max will cause the value to never decrement [saving gas
119
    ///        on transfer].
120
    /// @param caller The eth address which called the linking contract.
121
    function setApprovalBridge(
122
        uint256 tokenID,
123
        address operator,
124
        uint256 amount,
125
        address caller
126
    ) external onlyLinker(tokenID) {
127
        _setApproval(tokenID, operator, amount, caller);
4✔
128
    }
129

130
    /// @notice Allows a user to approve an operator to use all of their assets.
131
    /// @param operator The eth address which can access the caller's assets.
132
    /// @param approved True to approve, false to remove approval.
133
    function setApprovalForAll(address operator, bool approved) external {
134
        // set the appropriate state
135
        _isApprovedForAll[msg.sender][operator] = approved;
66✔
136
        // Emit an event to track approval
137
        emit ApprovalForAll(msg.sender, operator, approved);
66✔
138
    }
139

140
    /// @notice Allows a user to set an approval for an individual asset with
141
    ///         specific amount.
142
    /// @param tokenID The asset to approve the use of.
143
    /// @param operator The address who will be able to use the tokens.
144
    /// @param amount The max tokens the approved person can use, setting to
145
    ///        uint256.max will cause the value to never decrement (saving gas
146
    ///        on transfer).
147
    function setApproval(
148
        uint256 tokenID,
149
        address operator,
150
        uint256 amount
151
    ) external {
152
        _setApproval(tokenID, operator, amount, msg.sender);
189✔
153
    }
154

155
    /// @dev Safely transfers multiple tokens in a batch.
156
    /// @param _from The source address.
157
    /// @param _to The destination address.
158
    /// @param _ids Array of token identifiers.
159
    /// @param _amounts Array of amounts to transfer for each token.
160
    /// @param _data Additional data to pass to recipient if it's a contract.
161
    function safeBatchTransferFrom(
162
        address _from,
163
        address _to,
164
        uint256[] calldata _ids,
165
        uint256[] calldata _amounts,
166
        bytes calldata _data
167
    ) external {
168
        _safeBatchTransferFrom(_from, _to, _ids, _amounts, _data);
10✔
169
    }
170

171
    /// @notice Allows a caller who is not the owner of an account to execute
172
    ///         the functionality of 'approve' for all assets with the owner's
173
    ///         signature.
174
    /// @param domainSeparator The EIP712 domain separator of the contract.
175
    /// @param permitTypeHash The EIP712 domain separator of the contract.
176
    /// @param owner The owner of the account which is having the new approval set.
177
    /// @param spender The address which will be allowed to spend owner's tokens.
178
    /// @param _approved A boolean of the approval status to set to.
179
    /// @param deadline The timestamp which the signature must be submitted by
180
    ///        to be valid.
181
    /// @param v Extra ECDSA data which allows public key recovery from
182
    ///        signature assumed to be 27 or 28.
183
    /// @param r The r component of the ECDSA signature.
184
    /// @param s The s component of the ECDSA signature.
185
    /// @dev The signature for this function follows EIP 712 standard and should
186
    ///      be generated with the eth_signTypedData JSON RPC call instead of
187
    ///      the eth_sign JSON RPC call. If using out of date parity signing
188
    ///      libraries the v component may need to be adjusted. Also it is very
189
    ///      rare but possible for v to be other values, those values are not
190
    ///      supported.
191
    function permitForAll(
192
        bytes32 domainSeparator,
193
        bytes32 permitTypeHash,
194
        address owner,
195
        address spender,
196
        bool _approved,
197
        uint256 deadline,
198
        uint8 v,
199
        bytes32 r,
200
        bytes32 s
201
    ) external {
202
        _permitForAll(
8✔
203
            domainSeparator,
204
            permitTypeHash,
205
            owner,
206
            spender,
207
            _approved,
208
            deadline,
209
            v,
210
            r,
211
            s
212
        );
213
    }
214

215
    /// Getters ///
216

217
    /// @notice Gets the instance's name.
218
    /// @return The instance's name.
219
    function name() external view returns (string memory) {
220
        _revert(abi.encode(_name));
171✔
221
    }
222

223
    /// @notice Gets the instance's kind.
224
    /// @return The instance's kind.
225
    function kind() external pure virtual returns (string memory);
226

227
    /// @notice Gets the instance's version.
228
    /// @return The instance's version.
229
    function version() external pure returns (string memory) {
230
        _revert(abi.encode(VERSION));
111✔
231
    }
232

233
    /// @notice Gets the address that contains the admin configuration for this
234
    ///         instance.
235
    /// @return The admin controller address.
236
    function adminController() external view returns (address) {
237
        _revert(abi.encode(_adminController));
×
238
    }
239

240
    /// @notice Gets the pauser status of an address.
241
    /// @param _account The account to check.
242
    /// @return The pauser status.
243
    function isPauser(address _account) external view returns (bool) {
244
        _revert(abi.encode(_isPauser(_account)));
5✔
245
    }
246

247
    /// @notice Gets the base token.
248
    /// @return The base token address.
249
    function baseToken() external view returns (address) {
250
        _revert(abi.encode(_baseToken));
16,765✔
251
    }
252

253
    /// @notice Gets the vault shares token.
254
    /// @return The vault shares token address.
255
    function vaultSharesToken() external view returns (address) {
256
        _revert(abi.encode(_vaultSharesToken));
5,859✔
257
    }
258

259
    /// @notice Gets a specified checkpoint.
260
    /// @param _checkpointTime The checkpoint time.
261
    /// @return The checkpoint.
262
    function getCheckpoint(
263
        uint256 _checkpointTime
264
    ) external view returns (IHyperdrive.Checkpoint memory) {
265
        _revert(abi.encode(_checkpoints[_checkpointTime]));
21,422✔
266
    }
267

268
    /// @notice Gets the checkpoint exposure at a specified time.
269
    /// @param _checkpointTime The checkpoint time.
270
    /// @return The checkpoint exposure.
271
    function getCheckpointExposure(
272
        uint256 _checkpointTime
273
    ) external view returns (int256) {
274
        _revert(
69,515✔
275
            abi.encode(_nonNettedLongs(_checkpointTime + _positionDuration))
276
        );
277
    }
278

279
    /// @notice Gets the pool's configuration parameters.
280
    /// @dev These parameters are immutable, so this should only need to be
281
    ///      called once.
282
    /// @return The PoolConfig struct.
283
    function getPoolConfig()
284
        external
285
        view
286
        returns (IHyperdrive.PoolConfig memory)
287
    {
288
        _revert(
2,092,768✔
289
            abi.encode(
290
                IHyperdrive.PoolConfig({
291
                    baseToken: _baseToken,
292
                    vaultSharesToken: _vaultSharesToken,
293
                    linkerFactory: _linkerFactory,
294
                    linkerCodeHash: _linkerCodeHash,
295
                    initialVaultSharePrice: _initialVaultSharePrice,
296
                    minimumShareReserves: _minimumShareReserves,
297
                    minimumTransactionAmount: _minimumTransactionAmount,
298
                    circuitBreakerDelta: _circuitBreakerDelta,
299
                    positionDuration: _positionDuration,
300
                    checkpointDuration: _checkpointDuration,
301
                    timeStretch: _timeStretch,
302
                    governance: _adminController.hyperdriveGovernance(),
303
                    feeCollector: _adminController.feeCollector(),
304
                    sweepCollector: _adminController.sweepCollector(),
305
                    checkpointRewarder: _adminController.checkpointRewarder(),
306
                    fees: IHyperdrive.Fees(
307
                        _curveFee,
308
                        _flatFee,
309
                        _governanceLPFee,
310
                        _governanceZombieFee
311
                    )
312
                })
313
            )
314
        );
315
    }
316

317
    /// @notice Gets info about the pool's reserves and other state that is
318
    ///         important to evaluate potential trades.
319
    /// @return The pool info.
320
    function getPoolInfo() external view returns (IHyperdrive.PoolInfo memory) {
321
        uint256 vaultSharePrice = _pricePerVaultShare();
242,763✔
322
        uint256 lpTotalSupply = _totalSupply[AssetId._LP_ASSET_ID] +
242,763✔
323
            _totalSupply[AssetId._WITHDRAWAL_SHARE_ASSET_ID] -
324
            _withdrawPool.readyToWithdraw;
325
        uint256 presentValue;
242,763✔
326
        if (vaultSharePrice > 0) {
242,763✔
327
            (presentValue, ) = LPMath.calculatePresentValueSafe(
242,163✔
328
                _getPresentValueParams(vaultSharePrice)
329
            );
330
            presentValue = presentValue.mulDown(vaultSharePrice);
242,163✔
331
        }
332
        IHyperdrive.PoolInfo memory poolInfo = IHyperdrive.PoolInfo({
242,763✔
333
            shareReserves: _marketState.shareReserves,
334
            shareAdjustment: _marketState.shareAdjustment,
335
            zombieBaseProceeds: _marketState.zombieBaseProceeds,
336
            zombieShareReserves: _marketState.zombieShareReserves,
337
            bondReserves: _marketState.bondReserves,
338
            vaultSharePrice: vaultSharePrice,
339
            longsOutstanding: _marketState.longsOutstanding,
340
            longAverageMaturityTime: _marketState.longAverageMaturityTime,
341
            shortsOutstanding: _marketState.shortsOutstanding,
342
            shortAverageMaturityTime: _marketState.shortAverageMaturityTime,
343
            lpTotalSupply: lpTotalSupply,
344
            lpSharePrice: lpTotalSupply == 0
345
                ? 0
346
                : presentValue.divDown(lpTotalSupply),
347
            withdrawalSharesReadyToWithdraw: _withdrawPool.readyToWithdraw,
348
            withdrawalSharesProceeds: _withdrawPool.proceeds,
349
            longExposure: _marketState.longExposure
350
        });
351
        _revert(abi.encode(poolInfo));
242,763✔
352
    }
353

354
    /// @notice Gets information about the withdrawal pool.
355
    /// @return Hyperdrive's withdrawal pool information.
356
    function getWithdrawPool()
357
        external
358
        view
359
        returns (IHyperdrive.WithdrawPool memory)
360
    {
361
        _revert(
2✔
362
            abi.encode(
363
                IHyperdrive.WithdrawPool({
364
                    readyToWithdraw: _withdrawPool.readyToWithdraw,
365
                    proceeds: _withdrawPool.proceeds
366
                })
367
            )
368
        );
369
    }
370

371
    /// @notice Gets info about the fees presently accrued by the pool.
372
    /// @return Governance fees denominated in shares yet to be collected.
373
    function getUncollectedGovernanceFees() external view returns (uint256) {
374
        _revert(abi.encode(_governanceFeesAccrued));
3,425✔
375
    }
376

377
    /// @notice Gets the market state.
378
    /// @return The market state.
379
    function getMarketState()
380
        external
381
        view
382
        returns (IHyperdrive.MarketState memory)
383
    {
384
        _revert(abi.encode(_marketState));
13✔
385
    }
386

387
    /// @notice Allows plugin data libs to provide getters or other complex
388
    ///         logic instead of the main.
389
    /// @param _slots The storage slots the caller wants the data from.
390
    /// @return A raw array of loaded data.
391
    function load(
392
        uint256[] calldata _slots
393
    ) external view returns (bytes32[] memory) {
394
        bytes32[] memory loaded = new bytes32[](_slots.length);
1✔
395

396
        // Iterate on requested loads and then do them.
397
        for (uint256 i = 0; i < _slots.length; i++) {
1✔
398
            uint256 slot = _slots[i];
2✔
399
            bytes32 data;
2✔
400
            assembly ("memory-safe") {
401
                data := sload(slot)
2✔
402
            }
403
            loaded[i] = data;
2✔
404
        }
405

406
        _revert(abi.encode(loaded));
1✔
407
    }
408

409
    /// @notice Convert an amount of vault shares to an amount of base.
410
    /// @dev This is a convenience method that allows developers to convert from
411
    ///      vault shares to base without knowing the specifics of the
412
    ///      integration.
413
    /// @param _shareAmount The vault shares amount.
414
    /// @return baseAmount The base amount.
415
    function convertToBase(
416
        uint256 _shareAmount
417
    ) external view returns (uint256) {
418
        _revert(abi.encode(_convertToBase(_shareAmount)));
32,314✔
419
    }
420

421
    /// @notice Convert an amount of base to an amount of vault shares.
422
    /// @dev This is a convenience method that allows developers to convert from
423
    ///      base to vault shares without knowing the specifics of the
424
    ///      integration.
425
    /// @param _baseAmount The base amount.
426
    /// @return shareAmount The vault shares amount.
427
    function convertToShares(
428
        uint256 _baseAmount
429
    ) external view returns (uint256) {
430
        _revert(abi.encode(_convertToShares(_baseAmount)));
50,498✔
431
    }
432

433
    /// @notice Gets the total amount of vault shares held by Hyperdrive.
434
    /// @dev This is a convenience method that allows developers to get the
435
    ///      total amount of vault shares without knowing the specifics of the
436
    ///      integration.
437
    /// @return The total amount of vault shares held by Hyperdrive.
438
    function totalShares() external view returns (uint256) {
439
        _revert(abi.encode(_totalShares()));
3,034✔
440
    }
441

442
    /// @notice Gets an account's balance of a sub-token.
443
    /// @param _tokenId The sub-token id.
444
    /// @param _account The account.
445
    /// @return The balance.
446
    function balanceOf(
447
        uint256 _tokenId,
448
        address _account
449
    ) external view returns (uint256) {
450
        _revert(abi.encode(_balanceOf[_tokenId][_account]));
26,044✔
451
    }
452

453
    /// @notice Gets multiple accounts' balances for multiple token IDs.
454
    /// @param _accounts Array of addresses to check balances for.
455
    /// @param _ids Array of token IDs to check balances of.
456
    /// @return Array of token balances.
457
    function balanceOfBatch(
458
        address[] calldata _accounts,
459
        uint256[] calldata _ids
460
    ) external view returns (uint256[] memory) {
461
        // Check that input arrays match in length.
NEW
462
        if (_accounts.length != _ids.length) {
×
NEW
463
            revert IHyperdrive.BatchInputLengthMismatch();
×
464
        }
465

466
        // Load the balances.
NEW
467
        uint256[] memory batchBalances = new uint256[](_accounts.length);
×
NEW
468
        uint256 length = _accounts.length;
×
NEW
469
        for (uint256 i = 0; i < length; ++i) {
×
NEW
470
            batchBalances[i] = _balanceOf[_ids[i]][_accounts[i]];
×
471
        }
472

NEW
473
        _revert(abi.encode(batchBalances));
×
474
    }
475

476
    /// @notice Gets the total supply of a sub-token.
477
    /// @param tokenId The sub-token id.
478
    /// @return The total supply.
479
    function totalSupply(uint256 tokenId) external view returns (uint256) {
480
        _revert(abi.encode(_totalSupply[tokenId]));
46,461✔
481
    }
482

483
    /// @notice Gets the approval status of an operator for an account.
484
    /// @param account The account.
485
    /// @param operator The operator.
486
    /// @return The approval status.
487
    function isApprovedForAll(
488
        address account,
489
        address operator
490
    ) external view returns (bool) {
491
        _revert(abi.encode(_isApprovedForAll[account][operator]));
10✔
492
    }
493

494
    /// @notice Gets the approval status of an operator for an account.
495
    /// @param tokenId The sub-token id.
496
    /// @param account The account.
497
    /// @param spender The spender.
498
    /// @return The approval status.
499
    function perTokenApprovals(
500
        uint256 tokenId,
501
        address account,
502
        address spender
503
    ) external view returns (uint256) {
504
        _revert(abi.encode(_perTokenApprovals[tokenId][account][spender]));
72✔
505
    }
506

507
    /// @notice Gets the decimals of the MultiToken. This is the same as the
508
    ///         decimals used by the base token.
509
    /// @return The decimals of the MultiToken.
510
    function decimals() external view virtual returns (uint8) {
511
        _revert(abi.encode(_baseToken.decimals()));
44✔
512
    }
513

514
    /// @notice Gets the name of a sub-token.
515
    /// @param tokenId The sub-token id.
516
    /// @return The name.
517
    function name(uint256 tokenId) external pure returns (string memory) {
518
        _revert(abi.encode(AssetId.assetIdToName(tokenId)));
2✔
519
    }
520

521
    /// @notice Gets the symbol of a sub-token.
522
    /// @param tokenId The sub-token id.
523
    /// @return The symbol.
524
    function symbol(uint256 tokenId) external pure returns (string memory) {
525
        _revert(abi.encode(AssetId.assetIdToSymbol(tokenId)));
2✔
526
    }
527

528
    /// @notice Gets the permitForAll signature nonce for an account.
529
    /// @param account The account.
530
    /// @return The signature nonce.
531
    function nonces(address account) external view returns (uint256) {
532
        _revert(abi.encode(_nonces[account]));
9✔
533
    }
534

535
    /// Helpers ///
536

537
    /// @dev Reverts with the provided bytes. This is useful in getters used
538
    ///      with the force-revert delegatecall pattern.
539
    /// @param _bytes The bytes to revert with.
540
    function _revert(bytes memory _bytes) internal pure {
541
        revert IHyperdrive.ReturnData(_bytes);
2,613,322✔
542
    }
543
}
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

© 2026 Coveralls, Inc