Verified contractExactMIT
RebalanceMulticall
Address0x4d0ec6cf3d8b659416dc25cf817a562fec285165
- Balance
0 ETH
- Transactions
62
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,443,061
- Creation transaction
- 0x1ba863e414…22fa1722c9
src/RebalanceMulticall.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IVaultV2 {
function allocate(address adapter, bytes memory data, uint256 assets) external;
function deallocate(address adapter, bytes memory data, uint256 assets) external;
function isAllocator(address) external view returns (bool);
function isAdapter(address) external view returns (bool);
}
interface IMorphoMarketV1AdapterV2 {
function morpho() external view returns (address);
function expectedSupplyAssets(bytes32 marketId) external view returns (uint256);
}
interface IMorpho {
struct Market {
uint128 totalSupplyAssets;
uint128 totalSupplyShares;
uint128 totalBorrowAssets;
uint128 totalBorrowShares;
uint128 lastUpdate;
uint128 fee;
}
function market(bytes32 id) external view returns (Market memory);
}
contract RebalanceMulticall {
struct Action {
address vault;
address adapter;
bytes data;
uint256 assets;
bool allocate;
}
error NoActions();
error Unauthorized(address vault);
error NotAdapter();
error NotEnoughAssets();
event Rebalanced(address indexed caller, uint256 actions);
event Deallocated(
address indexed caller,
address indexed vault,
address indexed adapter,
uint256 requested,
uint256 actual
);
function rebalance(Action[] calldata actions) external {
if (actions.length == 0) revert NoActions();
emit Rebalanced(msg.sender, actions.length);
for (uint256 i = 0; i < actions.length; i++) {
Action calldata action = actions[i];
IVaultV2 vault = IVaultV2(action.vault);
authorize(vault);
if (action.allocate) {
vault.allocate(action.adapter, action.data, action.assets);
} else {
vault.deallocate(action.adapter, action.data, action.assets);
}
}
}
function deallocate(address vault, address adapter, bytes calldata data, uint256 assets, uint256 minAssets) external {
authorize(IVaultV2(vault));
if (!IVaultV2(vault).isAdapter(adapter)) revert NotAdapter();
uint256 capped = withdrawable(adapter, data, assets);
if (capped == 0 || capped < minAssets) revert NotEnoughAssets();
IVaultV2(vault).deallocate(adapter, data, capped);
emit Deallocated(msg.sender, vault, adapter, assets, capped);
}
function authorize(IVaultV2 vault) internal view {
if (!vault.isAllocator(msg.sender)) revert Unauthorized(address(vault));
}
function withdrawable(address adapter, bytes calldata data, uint256 assets) internal view returns (uint256) {
bytes32 marketId = keccak256(data);
uint256 supplied = IMorphoMarketV1AdapterV2(adapter).expectedSupplyAssets(marketId);
IMorpho.Market memory market = IMorpho(IMorphoMarketV1AdapterV2(adapter).morpho()).market(marketId);
uint256 liquidity = uint256(market.totalSupplyAssets) - uint256(market.totalBorrowAssets);
uint256 available = supplied < liquidity ? supplied : liquidity;
return assets < available ? assets : available;
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.