Skip to content
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

chore: update MADs precompile contract #3

Merged
merged 2 commits into from
Jan 20, 2025
Merged
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
36 changes: 35 additions & 1 deletion src/MultiAssetDelegation.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.20;
pragma solidity >=0.8.3;

/// @dev The MultiAssetDelegation contract's address.
address constant MULTI_ASSET_DELEGATION = 0x0000000000000000000000000000000000000822;
Expand All @@ -14,57 +14,71 @@ MultiAssetDelegation constant MULTI_ASSET_DELEGATION_CONTRACT = MultiAssetDelega
interface MultiAssetDelegation {
/// @dev Join as an operator with a bond amount.
/// @param bondAmount The amount to bond as an operator.
/// @custom:selector de883d74
function joinOperators(uint256 bondAmount) external;

/// @dev Schedule to leave as an operator.
/// @custom:selector ce3edd76
function scheduleLeaveOperators() external;

/// @dev Cancel the scheduled leave as an operator.
/// @custom:selector 9b1300c1
function cancelLeaveOperators() external;

/// @dev Execute the leave as an operator.
/// @custom:selector 0de1fc17
function executeLeaveOperators() external;

/// @dev Bond more as an operator.
/// @param additionalBond The additional amount to bond.
/// @custom:selector eede281b
function operatorBondMore(uint256 additionalBond) external;

/// @dev Schedule to unstake as an operator.
/// @param unstakeAmount The amount to unstake.
/// @custom:selector 44aff252
function scheduleOperatorUnstake(uint256 unstakeAmount) external;

/// @dev Execute the unstake as an operator.
/// @custom:selector b0dfce06
function executeOperatorUnstake() external;

/// @dev Cancel the scheduled unstake as an operator.
/// @custom:selector ac359f2b
function cancelOperatorUnstake() external;

/// @dev Go offline as an operator.
/// @custom:selector a6485ccd
function goOffline() external;

/// @dev Go online as an operator.
/// @custom:selector 6e5b676b
function goOnline() external;

/// @dev Deposit an amount of an asset.
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @param amount The amount to deposit.
/// @param lockMultiplier The lock multiplier.
/// @custom:selector b3c11395
function deposit(uint256 assetId, address tokenAddress, uint256 amount, uint8 lockMultiplier) external;

/// @dev Schedule a withdrawal of an amount of an asset.
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @param amount The amount to withdraw.
/// @custom:selector a125b146
function scheduleWithdraw(uint256 assetId, address tokenAddress, uint256 amount) external;

/// @dev Execute the scheduled withdrawal.
/// @custom:selector f8fd9795
function executeWithdraw() external;

/// @dev Cancel the scheduled withdrawal.
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @param amount The amount to cancel withdrawal.
/// @custom:selector 098d2a20
function cancelWithdraw(uint256 assetId, address tokenAddress, uint256 amount) external;

/// @dev Delegate an amount of an asset to an operator.
Expand All @@ -73,6 +87,7 @@ interface MultiAssetDelegation {
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @param amount The amount to delegate.
/// @param blueprintSelection The blueprint selection.
/// @custom:selector a12de0ba
function delegate(
bytes32 operator,
uint256 assetId,
Expand All @@ -86,16 +101,35 @@ interface MultiAssetDelegation {
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @param amount The amount to unstake.
/// @custom:selector 5bea61c6
function scheduleDelegatorUnstake(bytes32 operator, uint256 assetId, address tokenAddress, uint256 amount)
external;

/// @dev Execute the scheduled unstake as a delegator.
/// @custom:selector 007910d0
function executeDelegatorUnstake() external;

/// @dev Cancel the scheduled unstake as a delegator.
/// @param operator The address of the operator.
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @param amount The amount to cancel unstake.
/// @custom:selector 504aff13
function cancelDelegatorUnstake(bytes32 operator, uint256 assetId, address tokenAddress, uint256 amount) external;

/// @dev Get the total balance of the delegator (including the delegated balance).
/// @param who The address of the account.
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @return The total balance of the delegator.
/// @custom:selector 467f4cb9
function balanceOf(address who, uint256 assetId, address tokenAddress) external view returns (uint256);

/// @dev Get the delegated balance of the delegator.
/// @param who The address of the delegator.
/// @param assetId The ID of the asset (0 for ERC20).
/// @param tokenAddress The address of the ERC20 token (if assetId is 0).
/// @return The delegated balance of the delegator.
/// @custom:selector aabd20df
function delegatedBalanceOf(address who, uint256 assetId, address tokenAddress) external view returns (uint256);
}
2 changes: 1 addition & 1 deletion src/TangleLiquidRestakingVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ contract TangleLiquidRestakingVault is ERC4626, Owned, TangleMultiAssetDelegatio
/// @dev Returns total base assets, excluding reward tokens
/// @return Total value in terms of asset tokens
function totalAssets() public view override returns (uint256) {
return asset.balanceOf(address(this));
return _balanceOf(address(this));
}

/// @notice Get reward data for a token
Expand Down
7 changes: 7 additions & 0 deletions src/TangleMultiAssetDelegationWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ abstract contract TangleMultiAssetDelegationWrapper {

/* ============ Internal Functions ============ */

/// @notice Get the current balance of the delegator
/// @param delegator The delegator to get the balance for
/// @return The balance of the delegator
function _balanceOf(address delegator) internal view returns (uint256) {
return mads.balanceOf(delegator, 0, address(token));
}

/// @notice Deposit assets into the delegation system
/// @param amount Amount of assets to deposit
function _deposit(uint256 amount) internal {
Expand Down
2 changes: 1 addition & 1 deletion test/TangleLiquidRestakingVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract TangleLiquidRestakingVaultTest is Test {
baseToken = new MockERC20("Base Token", "BASE", 18);
rewardToken1 = new MockERC20("Reward Token 1", "RWD1", 18);
rewardToken2 = new MockERC20("Reward Token 2", "RWD2", 18);
mockMADS = new MockMultiAssetDelegation();
mockMADS = new MockMultiAssetDelegation(baseToken);
blueprintSelection = new uint64[](1);
blueprintSelection[0] = 1;

Expand Down
16 changes: 15 additions & 1 deletion test/mock/MockMultiAssetDelegation.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ERC20} from "dependencies/solmate-6.8.0/src/tokens/ERC20.sol";
import {MultiAssetDelegation} from "../../src/MultiAssetDelegation.sol";

contract MockMultiAssetDelegation is MultiAssetDelegation {
Expand All @@ -18,6 +19,12 @@ contract MockMultiAssetDelegation is MultiAssetDelegation {
mapping(address => ScheduleState) public scheduledWithdraws;
mapping(address => uint256) public delegatedAmounts;

ERC20 public immutable token;

constructor(ERC20 _token) {
token = _token;
}

// Events
event Delegated(
address indexed token, address indexed user, uint256 amount, bytes32 operator, uint64[] blueprintSelection
Expand Down Expand Up @@ -56,7 +63,6 @@ contract MockMultiAssetDelegation is MultiAssetDelegation {

// Deposit function - just track delegated amount
function deposit(uint256, address, uint256 amount, uint8) external {
delegatedAmounts[msg.sender] += amount;
emit Delegated(address(0), msg.sender, amount, bytes32(0), new uint64[](0));
}

Expand Down Expand Up @@ -154,4 +160,12 @@ contract MockMultiAssetDelegation is MultiAssetDelegation {
ScheduleState storage state = scheduledWithdraws[tokenAddress];
return (state.amount, state.timestamp);
}

function balanceOf(address who, uint256, address) external view returns (uint256) {
return token.balanceOf(who);
}

function delegatedBalanceOf(address who, uint256, address) external view returns (uint256) {
return delegatedAmounts[who];
}
}
Loading