Skip to content

Commit

Permalink
feat: reintegrate mads precompile wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Jan 11, 2025
1 parent 7c5154a commit 0fdaadd
Show file tree
Hide file tree
Showing 7 changed files with 1,023 additions and 183 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ docs/

# Soldeer
/dependencies
byzantine-*
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@openzeppelin-contracts-5.2.0/=dependencies/@openzeppelin-contracts-5.2.0/
forge-std-1.9.5/=dependencies/forge-std-1.9.5/
solmate-6.8.0/=dependencies/solmate-6.8.0/
469 changes: 346 additions & 123 deletions src/TangleLiquidRestakingVault.sol

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions src/TangleMultiAssetDelegationWrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

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

/// @title TangleMultiAssetDelegationWrapper
/// @notice Base contract for interacting with Tangle's MultiAssetDelegation system
/// @dev Provides delegation lifecycle management for a specific ERC20 token
abstract contract TangleMultiAssetDelegationWrapper {
/* ============ Events ============ */

/// @notice Emitted when delegation occurs
event Delegated(bytes32 indexed operator, uint256 amount, uint64[] blueprintSelection);

/// @notice Emitted when unstake is scheduled
event UnstakeScheduled(bytes32 indexed operator, uint256 amount);

/// @notice Emitted when unstake is cancelled
event UnstakeCancelled(bytes32 indexed operator, uint256 amount);

/// @notice Emitted when withdrawal is scheduled
event WithdrawalScheduled(uint256 amount);

/// @notice Emitted when withdrawal is cancelled
event WithdrawalCancelled(uint256 amount);

/// @notice Emitted when assets are deposited
event Deposited(uint256 amount);

/* ============ State Variables ============ */

/// @notice The ERC20 token being delegated
ERC20 public immutable token;

/// @notice The MultiAssetDelegation implementation
MultiAssetDelegation public immutable mads;

/* ============ Constructor ============ */

constructor(address _token, address _mads) {
token = ERC20(_token);
mads = MultiAssetDelegation(_mads);
}

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

/// @notice Deposit assets into the delegation system
/// @param amount Amount of assets to deposit
function _deposit(uint256 amount) internal {
mads.deposit(
0,
address(token),
amount,
0 // Lock multiplier
);

emit Deposited(amount);
}

/// @notice Delegate assets to an operator
/// @param operator The operator to delegate to
/// @param amount Amount of assets to delegate
/// @param blueprintSelection Blueprint selection for delegation
function _delegate(
bytes32 operator,
uint256 amount,
uint64[] memory blueprintSelection
) internal {
mads.delegate(
operator,
0,
address(token),
amount,
blueprintSelection
);

emit Delegated(operator, amount, blueprintSelection);
}

/// @notice Schedule unstaking of assets
/// @param operator The operator to unstake from
/// @param amount Amount of assets to unstake
function _scheduleUnstake(bytes32 operator, uint256 amount) internal {
mads.scheduleDelegatorUnstake(
operator,
0,
address(token),
amount
);

emit UnstakeScheduled(operator, amount);
}

/// @notice Cancel a scheduled unstake
/// @param operator The operator to cancel unstake from
/// @param amount Amount of assets to cancel unstaking
function _cancelUnstake(bytes32 operator, uint256 amount) internal {
mads.cancelDelegatorUnstake(
operator,
0,
address(token),
amount
);

emit UnstakeCancelled(operator, amount);
}

/// @notice Execute pending unstake
function _executeUnstake() internal {
mads.executeDelegatorUnstake();
}

/// @notice Schedule withdrawal of assets
/// @param amount Amount of assets to withdraw
function _scheduleWithdraw(uint256 amount) internal {
mads.scheduleWithdraw(
0,
address(token),
amount
);

emit WithdrawalScheduled(amount);
}

/// @notice Cancel a scheduled withdrawal
/// @param amount Amount of assets to cancel withdrawal
function _cancelWithdraw(uint256 amount) internal {
mads.cancelWithdraw(
0,
address(token),
amount
);

emit WithdrawalCancelled(amount);
}

/// @notice Execute pending withdrawal
function _executeWithdraw() internal {
mads.executeWithdraw();
}
}
Loading

0 comments on commit 0fdaadd

Please sign in to comment.