6

aave-protocol/Proxy.sol at e8d020e9752fbd4807a3b55f9cf98a88dcfb674d · aave/aave-...

 2 years ago
source link: https://github.com/aave/aave-protocol/blob/e8d020e9752fbd4807a3b55f9cf98a88dcfb674d/contracts/libraries/openzeppelin-upgradeability/Proxy.sol
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
aave-protocol/Proxy.sol at e8d020e9752fbd4807a3b55f9cf98a88dcfb674d · aave/aave-protocol · GitHub

71 lines (63 sloc) 2.23 KB

pragma solidity ^0.5.0;

/** * @title Proxy * @dev Implements delegation of calls to other contracts, with proper * forwarding of return values and bubbling of failures. * It defines a fallback function that delegates all calls to the address * returned by the abstract _implementation() internal function. */ contract Proxy { /** * @dev Fallback function. * Implemented entirely in `_fallback`. */ function() external payable { _fallback(); }

/** * @return The Address of the implementation. */ function _implementation() internal view returns (address);

/** * @dev Delegates execution to an implementation contract. * This is a low level function that doesn't return to its internal call site. * It will return to the external caller whatever the implementation returns. * @param implementation Address to delegate. */ function _delegate(address implementation) internal { //solium-disable-next-line 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 Function that is run as the first thing in the fallback function. * Can be redefined in derived contracts to add functionality. * Redefinitions must call super._willFallback(). */ function _willFallback() internal {}

/** * @dev fallback implementation. * Extracted to enable manual triggering. */ function _fallback() internal { _willFallback(); _delegate(_implementation()); } }


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK