Skip to content

Commit

Permalink
allow custom tokens to add extra logic contract via eip-1967 storage …
Browse files Browse the repository at this point in the history
…slot
  • Loading branch information
d10r committed Oct 2, 2023
1 parent 464a25e commit 89489e4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/ethereum-contracts/contracts/superfluid/SuperToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,39 @@ contract SuperToken is
_initialize(underlyingToken, underlyingDecimals, n, s, adminOverride);
}

// solhint-disable-next-line payable-fallback
fallback() external virtual {
_fallback();
}

// Hand to extended logic contract if specified in eip-1967-adjacent storage slot
function _fallback() internal virtual {
address extraImplementation;
assembly { // solium-disable-line
// eip-1967 storage slot decremented by 1
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 2)
extraImplementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbb)
}

if (extraImplementation != address(0)) {
assembly {
// the following code is a copy (without comments) from openzeppelin Proxy
// see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.3/contracts/proxy/Proxy.sol
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), extraImplementation, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())

switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
}

function proxiableUUID() public pure virtual override returns (bytes32) {
return keccak256("org.superfluid-finance.contracts.SuperToken.implementation");
}
Expand Down

0 comments on commit 89489e4

Please sign in to comment.