-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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,66 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@eigenlayer/contracts/interfaces/IStrategy.sol"; | ||
|
||
contract MockStrategy is IStrategy { | ||
IERC20 public override underlyingToken; | ||
uint256 public override totalShares; | ||
mapping(address => uint256) public userShares; | ||
uint256 public constant EXCHANGE_RATE = 1e18; // 1:1 exchange rate for simplicity | ||
|
||
constructor(IERC20 _underlyingToken) { | ||
underlyingToken = _underlyingToken; | ||
emit StrategyTokenSet(_underlyingToken, 18); // Assuming 18 decimals for simplicity | ||
} | ||
|
||
function deposit(IERC20 token, uint256 amount) external override returns (uint256) { | ||
require(token == underlyingToken, "Invalid token"); | ||
uint256 newShares = amount; | ||
totalShares += newShares; | ||
userShares[msg.sender] += newShares; | ||
emit ExchangeRateEmitted(EXCHANGE_RATE); | ||
return newShares; | ||
} | ||
|
||
function withdraw(address recipient, IERC20 token, uint256 amountShares) external override { | ||
require(token == underlyingToken, "Invalid token"); | ||
require(userShares[msg.sender] >= amountShares, "Insufficient shares"); | ||
userShares[msg.sender] -= amountShares; | ||
totalShares -= amountShares; | ||
underlyingToken.transfer(recipient, amountShares); | ||
} | ||
|
||
function sharesToUnderlying(uint256 amountShares) external pure override returns (uint256) { | ||
return amountShares; | ||
} | ||
|
||
function underlyingToShares(uint256 amountUnderlying) external pure override returns (uint256) { | ||
return amountUnderlying; | ||
} | ||
|
||
function userUnderlying(address user) external view override returns (uint256) { | ||
return userShares[user]; | ||
} | ||
|
||
function shares(address user) external view override returns (uint256) { | ||
return userShares[user]; | ||
} | ||
|
||
function sharesToUnderlyingView(uint256 amountShares) external pure override returns (uint256) { | ||
return amountShares; | ||
} | ||
|
||
function underlyingToSharesView(uint256 amountUnderlying) external pure override returns (uint256) { | ||
return amountUnderlying; | ||
} | ||
|
||
function userUnderlyingView(address user) external view override returns (uint256) { | ||
return userShares[user]; | ||
} | ||
|
||
function explanation() external pure override returns (string memory) { | ||
return "Mock Strategy for testing purposes"; | ||
} | ||
} |
This file contains 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,10 @@ | ||
{ | ||
"leaves": [ | ||
"0x0000000000000000000000000000000000000000000000000000000000000001", | ||
"0x0000000000000000000000000000000000000000000000000000000000000002" | ||
], | ||
"tokenLeaves": [ | ||
"0x0000000000000000000000000000000000000000000000000000000000000003", | ||
"0x0000000000000000000000000000000000000000000000000000000000000004" | ||
] | ||
} |
This file contains 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 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 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 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 @@ | ||
{"leaves":["0x1234"], "tokenLeaves":["0x5678"]} |