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

delvtech / hyperdrive / 11114579983

30 Sep 2024 09:40PM UTC coverage: 88.982%. First build
11114579983

Pull #1182

github

web-flow
Merge babf4ec52 into 6cdccd111
Pull Request #1182: Staking USDS Integrations

47 of 60 new or added lines in 11 files covered. (78.33%)

2447 of 2750 relevant lines covered (88.98%)

343559.18 hits per line

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

82.35
/contracts/src/instances/staking-usds/StakingUSDSBase.sol
1
// SPDX-License-Identifier: Apache-2.0
2
pragma solidity 0.8.22;
3

4
import { ERC20 } from "openzeppelin/token/ERC20/ERC20.sol";
5
import { SafeERC20 } from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
6
import { IStakingUSDS } from "../../interfaces/IStakingUSDS.sol";
7
import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
8
import { HyperdriveBase } from "../../internal/HyperdriveBase.sol";
9
import { StakingUSDSConversions } from "./StakingUSDSConversions.sol";
10

11
/// @author DELV
12
/// @title StakingUSDSBase
13
/// @notice The base contract for the StakingUSDS Hyperdrive implementation.
14
/// @dev This Hyperdrive implementation is designed to work with standard
15
///      StakingUSDS vaults. Non-standard implementations may not work correctly
16
///      and should be carefully checked.
17
/// @custom:disclaimer The language used in this code is for coding convenience
18
///                    only, and is not intended to, and does not, have any
19
///                    particular legal or regulatory significance.
20
abstract contract StakingUSDSBase is HyperdriveBase {
21
    using SafeERC20 for ERC20;
22

23
    /// @dev The staking rewards contract for USDS. This is where the USDS will
24
    ///      be deposited.
25
    IStakingUSDS internal immutable _stakingUSDS;
26

27
    /// @notice Instantiates the StakingUSDSHyperdrive base contract.
28
    /// @param __stakingUSDS The staking USDS contract that pays out rewards.
29
    constructor(IStakingUSDS __stakingUSDS) {
30
        // Set the staking USDS contract and set an initial approval to ensure
31
        // that the approval storage slot is dirty.
32
        _stakingUSDS = __stakingUSDS;
396✔
33
        ERC20(address(_baseToken)).forceApprove(address(__stakingUSDS), 1);
396✔
34
    }
35

36
    /// Yield Source ///
37

38
    /// @dev Accepts a deposit from the user in base.
39
    /// @param _baseAmount The base amount to deposit.
40
    /// @return The shares that were minted in the deposit.
41
    /// @return The amount of ETH to refund. Since this yield source isn't
42
    ///         payable, this is always zero.
43
    function _depositWithBase(
44
        uint256 _baseAmount,
45
        bytes calldata // unused
46
    ) internal override returns (uint256, uint256) {
47
        // Take custody of the deposit in base.
48
        ERC20(address(_baseToken)).safeTransferFrom(
2,466✔
49
            msg.sender,
50
            address(this),
51
            _baseAmount
52
        );
53

54
        // Deposit the base into the yield source.
55
        //
56
        // NOTE: We increase the required approval amount by 1 wei so that
57
        // staking USDS ends with an approval of 1 wei. This makes future
58
        // approvals cheaper by keeping the storage slot warm.
59
        ERC20(address(_baseToken)).forceApprove(
2,466✔
60
            address(_stakingUSDS),
61
            _baseAmount + 1
62
        );
63
        _stakingUSDS.stake(
2,466✔
64
            _baseAmount,
65
            // FIXME: Get a referral ID.
66
            uint16(0)
67
        );
68

69
        return (_baseAmount, 0);
2,466✔
70
    }
71

72
    /// @dev Deposits with shares are not supported for this integration.
73
    function _depositWithShares(
74
        uint256, // unused _shareAmount
75
        bytes calldata // unused _extraData
76
    ) internal pure override {
NEW
77
        revert IHyperdrive.UnsupportedToken();
×
78
    }
79

80
    /// @dev Process a withdrawal in base and send the proceeds to the
81
    ///      destination.
82
    /// @param _shareAmount The amount of vault shares to withdraw.
83
    /// @param _destination The destination of the withdrawal.
84
    /// @return amountWithdrawn The amount of base withdrawn.
85
    function _withdrawWithBase(
86
        uint256 _shareAmount,
87
        address _destination,
88
        bytes calldata // unused
89
    ) internal override returns (uint256 amountWithdrawn) {
90
        // Withdraw from the staking USDS vault.
91
        _stakingUSDS.withdraw(_shareAmount);
1,290✔
92

93
        // Transfer the shares to the destination.
94
        amountWithdrawn = _convertToBase(_shareAmount);
1,290✔
95
        ERC20(address(_baseToken)).safeTransfer(_destination, amountWithdrawn);
1,290✔
96

NEW
97
        return amountWithdrawn;
×
98
    }
99

100
    /// @dev Withdrawals with shares are not supported for this integration.
101
    function _withdrawWithShares(
102
        uint256, // unused _shareAmount
103
        address, // unused _destination
104
        bytes calldata // unused
105
    ) internal pure override {
NEW
106
        revert IHyperdrive.UnsupportedToken();
×
107
    }
108

109
    /// @dev Convert an amount of vault shares to an amount of base.
110
    /// @param _shareAmount The vault shares amount.
111
    /// @return The base amount.
112
    function _convertToBase(
113
        uint256 _shareAmount
114
    ) internal pure override returns (uint256) {
115
        return StakingUSDSConversions.convertToBase(_shareAmount);
9,562✔
116
    }
117

118
    /// @dev Convert an amount of base to an amount of vault shares.
119
    /// @param _baseAmount The base amount.
120
    /// @return The vault shares amount.
121
    function _convertToShares(
122
        uint256 _baseAmount
123
    ) internal pure override returns (uint256) {
124
        return StakingUSDSConversions.convertToShares(_baseAmount);
2,500✔
125
    }
126

127
    /// @dev Gets the total amount of shares held by the pool in the yield
128
    ///      source.
129
    /// @return shareAmount The total amount of shares.
130
    function _totalShares()
131
        internal
132
        view
133
        override
134
        returns (uint256 shareAmount)
135
    {
136
        return _convertToShares(_stakingUSDS.balanceOf(address(this)));
8✔
137
    }
138

139
    /// @dev We override the message value check since this integration is
140
    ///      not payable.
141
    function _checkMessageValue() internal view override {
142
        if (msg.value != 0) {
2,474✔
143
            revert IHyperdrive.NotPayable();
8✔
144
        }
145
    }
146
}
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