Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions contracts/EverlongStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ contract EverlongStrategy is BaseStrategy {

/// @notice Whether to use Hyperdrive's base token to purchase bonds.
/// If false, use the Hyperdrive's `vaultSharesToken`.
/// @dev When `isWrapped=true`, `asBase` must be set to false.
bool public immutable asBase;

/// @notice Whether the strategy asset is a wrapped version of hyperdrive's
Expand Down Expand Up @@ -172,23 +173,28 @@ contract EverlongStrategy is BaseStrategy {
bool _asBase,
bool _isWrapped
) BaseStrategy(_asset, __name) {
// When the asset is wrapped, `_asBase` must be false.
if (_isWrapped && _asBase) {
revert IEverlongStrategy.WrappedBaseMismatch();
}

// Store the hyperdrive instance's address.
hyperdrive = _hyperdrive;

// Store whether to interact with hyperdrive using its base token.
asBase = _asBase;

// Store whether `asset` should be treated as a wrapped hyperdrive
// token.
isWrapped = _isWrapped;

// Store the hyperdrive's PoolConfig since it's static.
_poolConfig = IHyperdrive(_hyperdrive).getPoolConfig();

// Store the execution token to use when opening/closing longs.
executionToken = address(
_asBase ? _poolConfig.baseToken : _poolConfig.vaultSharesToken
);

// Store whether `asset` should be treated as a wrapped hyperdrive
// token.
isWrapped = _isWrapped;
}

// ╭───────────────────────────────────────────────────────────────────────╮
Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/IEverlongStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ interface IEverlongStrategy is IPermissionedStrategy, IEverlongEvents {
/// a non-wrapped asset.
error AssetNotWrapped();

/// @notice Thrown when creating a strategy with both `isWrapped == true`
/// and `isBase == true`.
error WrappedBaseMismatch();

// ╭───────────────────────────────────────────────────────────────────────╮
// │ SETTERS │
// ╰───────────────────────────────────────────────────────────────────────╯
Expand Down
16 changes: 16 additions & 0 deletions test/everlong/units/Everlong.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import { console2 as console } from "forge-std/console2.sol";
import { IEverlongStrategy } from "../../../contracts/interfaces/IEverlongStrategy.sol";
import { EverlongStrategy } from "../../../contracts/EverlongStrategy.sol";
import { EVERLONG_STRATEGY_KIND, EVERLONG_VERSION } from "../../../contracts/libraries/Constants.sol";
import { EverlongTest } from "../EverlongTest.sol";

Expand Down Expand Up @@ -33,4 +35,18 @@ contract TestEverlong is EverlongTest {
"version does not match"
);
}

/// @dev Tests that the error `IEverlongStrategy.WrappedBaseMismatch()` is
/// thrown when creating a strategy with `isWrapped=true` and
/// `asBase=true`.
function test_wrapped_isbase_true_failure() external {
vm.expectRevert();
new EverlongStrategy(
address(address(asset)),
"EverlongTest",
address(hyperdrive),
true,
true
);
}
}
Loading