Contract Name:
RebalancerProxy
Contract Source Code:
<i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Proxy.sol)
pragma solidity ^0.8.20;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback
* function and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
/**
* @title IRebalancingManagerCore
* @author MetaLend
* @notice Core rebalancing manager interface to read rebalancer implementation
*/
interface IRebalancingManagerCore {
/**
* @notice Returns the address of the rebalancer implementation contract
* @dev Use this with _implementation() in the proxy contract to get the implementation address
* @return rebalancerImplementation The address of the rebalancer implementation contract
*/
function getRebalancerImplementation() external view returns (address rebalancerImplementation);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
/**
* @title RebalancerCore
* @author MetaLend
* @notice Abstract contract that provides default storage layout for proxy and implementation contract
*/
abstract contract RebalancerCore {
/// @notice Manager contract providing rebalancing functionality and access control and implementation
address internal _rebalancingManager;
/// @notice Address of the owner of this rebalancer
address internal _owner;
/**
* @notice Emitted when the rebalancer is initialized
* @param rebalancer Address of this rebalancer
* @param manager Address of the rebalancing manager
* @param owner Address of the owner of this rebalancer
*/
event RebalancerInitialized(address indexed rebalancer, address indexed manager, address indexed owner);
} <i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol";
import {IRebalancingManagerCore} from "../manager/IRebalancingManagerCore.sol";
import {RebalancerCore} from "./RebalancerCore.sol";
/**
* @title RebalancerProxy
* @author MetaLend
* @notice Proxy contract for the rebalancer
* @dev This contract is created to be used as a proxy for the rebalancer implementation managed by the rebalancing manager
*/
contract RebalancerProxy is RebalancerCore, Proxy {
/**
* @notice Constructor for the RebalancerProxy contract
* @param manager_ The address of the rebalancing manager
* @param owner_ The address of the owner of the rebalancer
*/
constructor(address manager_, address owner_) {
_rebalancingManager = manager_;
_owner = owner_;
emit RebalancerInitialized(address(this), _rebalancingManager, _owner);
}
/**
* @notice Returns the address of the implementation contract
* @dev This is used by the proxy `_fallback` function to delegate calls to the implementation contract
*/
function _implementation() internal view override returns (address implementation) {
return IRebalancingManagerCore(_rebalancingManager).getRebalancerImplementation();
}
}