-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from asymmetryfinance/sfrx-eth-adapt
Redeploy + Update readme
- Loading branch information
Showing
12 changed files
with
185 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
/// @author philogy <https://github.com/philogy> | ||
interface IProxySource { | ||
function implementation() external view returns (address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol"; | ||
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; | ||
import {IProxySource} from "../interfaces/IProxySource.sol"; | ||
|
||
/// @author philogy <https://github.com/philogy> | ||
/// @dev ERC1967 Proxy that has no initcall or implementation factor in its deploy bytecode. | ||
contract SimpleProxy is Proxy { | ||
constructor() { | ||
address implementation = IProxySource(msg.sender).implementation(); | ||
ERC1967Utils.upgradeToAndCall(implementation, new bytes(0)); | ||
} | ||
|
||
function _implementation() internal view override returns (address) { | ||
return ERC1967Utils.getImplementation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
import {IProxySource} from "../interfaces/IProxySource.sol"; | ||
import {SimpleProxy} from "./SimpleProxy.sol"; | ||
|
||
/// @author philogy <https://github.com/philogy> | ||
contract SimpleProxyFactory is IProxySource { | ||
address internal constant NO_IMPLEMENTATION = address(1); | ||
|
||
bytes32 public immutable PROXY_INIT_HASH = keccak256(type(SimpleProxy).creationCode); | ||
|
||
address public implementation = NO_IMPLEMENTATION; | ||
|
||
error NotSaltOwner(); | ||
error InitCallFailed(); | ||
|
||
function deployDeterministic(bytes32 salt, address initialImplementation, bytes memory initCall) | ||
external | ||
payable | ||
returns (address proxy) | ||
{ | ||
address saltOwner = address(bytes20(salt)); | ||
if (saltOwner != address(0) && saltOwner != msg.sender) revert NotSaltOwner(); | ||
implementation = initialImplementation; | ||
proxy = address(new SimpleProxy{salt: salt}()); | ||
implementation = NO_IMPLEMENTATION; | ||
|
||
if (msg.value > 0 || initCall.length > 0) { | ||
(bool success,) = proxy.call{value: msg.value}(initCall); | ||
if (!success) revert InitCallFailed(); | ||
} | ||
} | ||
|
||
function predictDeterministicAddress(bytes32 salt) external view returns (address addr) { | ||
return | ||
address(uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, PROXY_INIT_HASH))))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#define constant SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc | ||
|
||
#define function proxiableUUID() view returns (bytes32) | ||
|
||
|
||
#define macro _MAIN(z0) = takes(0) returns(0) { | ||
[SLOT] <z0> mstore | ||
|
||
msize <z0> | ||
|
||
<z0> calldataload 0xe0 shr | ||
__FUNC_SIG(proxiableUUID) sub error jumpi | ||
return | ||
error: | ||
revert | ||
} | ||
|
||
#define macro MAIN() = takes(0) returns(0) { | ||
_MAIN(returndatasize) | ||
} |
Oops, something went wrong.