-
Notifications
You must be signed in to change notification settings - Fork 111
Add Credit Market AMO Strategy #2927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shahthepro
wants to merge
4
commits into
master
Choose a base branch
from
shah/credit-market-amo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
| import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
|
||
| import { MockERC4626Vault } from "./MockERC4626Vault.sol"; | ||
|
|
||
| /** | ||
| * @title Mock Morpho Vault V2 credit vault | ||
| * @notice ERC-4626 mock that decouples the reported position value (previewRedeem) from the | ||
| * liquid balance available to withdraw, so tests can model accrued-but-unrealized | ||
| * interest and OToken that has been borrowed out. | ||
| * @dev Mirrors production: maxWithdraw()/maxRedeem() return 0 (the strategy reads liquidity via | ||
| * MorphoV2VaultUtils, not these), and a liquidityAdapter() getter is exposed. The strategy | ||
| * is the sole depositor in the gated vault, so it always holds 100% of the shares and | ||
| * previewRedeem(allShares) == reported total assets. | ||
| */ | ||
| contract MockMorphoV2CreditVault is MockERC4626Vault { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| /// @notice Reported total assets, driving previewRedeem independent of the idle balance. | ||
| uint256 private _reportedTotalAssets; | ||
|
|
||
| /// @notice The Morpho V1 liquidity adapter address. | ||
| address public liquidityAdapter; | ||
|
|
||
| constructor(address _asset) MockERC4626Vault(_asset) {} | ||
|
|
||
| function setLiquidityAdapter(address _liquidityAdapter) external { | ||
| liquidityAdapter = _liquidityAdapter; | ||
| } | ||
|
|
||
| /// @dev Reported value, not the idle token balance. | ||
| function totalAssets() public view override returns (uint256) { | ||
| return _reportedTotalAssets; | ||
| } | ||
|
|
||
| function deposit(uint256 assets, address receiver) | ||
| public | ||
| override | ||
| returns (uint256 shares) | ||
| { | ||
| shares = super.deposit(assets, receiver); | ||
| _reportedTotalAssets += assets; | ||
| } | ||
|
|
||
| function withdraw( | ||
| uint256 assets, | ||
| address receiver, | ||
| address owner | ||
| ) public override returns (uint256 shares) { | ||
| shares = super.withdraw(assets, receiver, owner); | ||
| _reportedTotalAssets -= assets; | ||
| } | ||
|
|
||
| /// @notice Simulate interest accruing as a claim: lifts previewRedeem without adding liquidity. | ||
| function simulateInterest(uint256 amount) external { | ||
| _reportedTotalAssets += amount; | ||
| } | ||
|
|
||
| /// @notice Simulate OToken being borrowed/drawn: removes idle liquidity without changing value. | ||
| function simulateBorrow(uint256 amount, address to) external { | ||
| IERC20(asset).safeTransfer(to, amount); | ||
| } | ||
|
|
||
| /// @dev Morpho V2 vaults return 0 from these; liquidity is read via MorphoV2VaultUtils. | ||
| function maxWithdraw(address) public view override returns (uint256) { | ||
| return 0; | ||
| } | ||
|
|
||
| function maxRedeem(address) public view override returns (uint256) { | ||
| return 0; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
contracts/contracts/strategies/AbstractMerkleClaimStrategy.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| /** | ||
| * @title Abstract strategy with Merkl reward claiming | ||
| * @notice Adds the ability to claim rewards from the Merkl Distributor to a strategy. | ||
| * @dev Holds no storage so it is safe to insert into the inheritance chain of an | ||
| * already deployed upgradeable strategy without shifting any storage slots. | ||
| * @author Origin Protocol Inc | ||
| */ | ||
| import { InitializableAbstractStrategy } from "../utils/InitializableAbstractStrategy.sol"; | ||
| import { IDistributor } from "../interfaces/IMerkl.sol"; | ||
|
|
||
| abstract contract AbstractMerkleClaimStrategy is InitializableAbstractStrategy { | ||
| /// @notice The address of the Merkle Distributor contract. | ||
| IDistributor public constant merkleDistributor = | ||
| IDistributor(0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae); | ||
|
|
||
| event ClaimedRewards(address indexed token, uint256 amount); | ||
|
|
||
| /** | ||
| * @param _baseConfig The platform and OToken vault addresses | ||
| */ | ||
| constructor(BaseStrategyConfig memory _baseConfig) | ||
| InitializableAbstractStrategy(_baseConfig) | ||
| {} | ||
|
|
||
| /// @notice Claim tokens from the Merkle Distributor | ||
| /// @param token The address of the token to claim. | ||
| /// @param amount The amount of tokens to claim. | ||
| /// @param proof The Merkle proof to validate the claim. | ||
| function merkleClaim( | ||
| address token, | ||
| uint256 amount, | ||
| bytes32[] calldata proof | ||
| ) external { | ||
| address[] memory users = new address[](1); | ||
| users[0] = address(this); | ||
|
|
||
| address[] memory tokens = new address[](1); | ||
| tokens[0] = token; | ||
|
|
||
| uint256[] memory amounts = new uint256[](1); | ||
| amounts[0] = amount; | ||
|
|
||
| bytes32[][] memory proofs = new bytes32[][](1); | ||
| proofs[0] = proof; | ||
|
|
||
| merkleDistributor.claim(users, tokens, amounts, proofs); | ||
|
|
||
| emit ClaimedRewards(token, amount); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.