Skip to content

Commit

Permalink
inline UUPSProxy with fixed license
Browse files Browse the repository at this point in the history
  • Loading branch information
d10r committed Jan 23, 2024
1 parent e95ea6b commit df7bfb2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/PureSuperToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma solidity 0.8.19;
// This abstract contract provides storage padding for the proxy
import { CustomSuperTokenBase } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/CustomSuperTokenBase.sol";
// Implementation of UUPSProxy (see https://eips.ethereum.org/EIPS/eip-1822)
import { UUPSProxy } from "@superfluid-finance/ethereum-contracts/contracts/upgradability/UUPSProxy.sol";
import { UUPSProxy } from "./base/UUPSProxy.sol";
// Superfluid framework interfaces we need
import { ISuperToken, ISuperTokenFactory, IERC20 } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";

Expand Down
48 changes: 48 additions & 0 deletions contracts/base/UUPSProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.0;

import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol";

/// @title UUPS Proxy implementation contract
/// @author jtriley.eth
/// @notice Stores the logic contract's address at the _IMPLEMENTATION_SLOT
/// @dev `initializeProxy(address)` is called by the Super Token Factory
/// The call to the factory should be in the same transaction to avoid being
/// front run
contract UUPSProxy is Proxy {
/// @notice Thrown when the logic contract address is zero
error ZeroAddress();

/// @notice Thrown when the logic contract has been set
error Initialized();

/// @notice Precomputed from the following for gas savings
/// bytes32(uint256(keccak256("eip1967.proxy.implementation") - 1));
bytes32 internal constant _IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/// @notice Stores the logic contract address only once.
/// @dev Called by the SuperTokenFactory contract on upgrade
/// @param initialAddress logic contract address
function initializeProxy(address initialAddress) external {
if (initialAddress == address(0)) revert ZeroAddress();
if (_implementation() != address(0)) revert Initialized();
assembly {
sstore(_IMPLEMENTATION_SLOT, initialAddress)
}
}

/// @notice Reads logic contract from precomputed slot
/// @return impl Logic contract address
function _implementation()
internal
view
virtual
override
returns (address impl)
{
assembly {
impl := sload(_IMPLEMENTATION_SLOT)
}
}
}

0 comments on commit df7bfb2

Please sign in to comment.