Skip to content

Commit

Permalink
fix(ct): remove dependency on @eth-optimism/contracts-bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Oct 28, 2023
1 parent 9b4c956 commit f2c5d28
Show file tree
Hide file tree
Showing 17 changed files with 508 additions and 382 deletions.
8 changes: 8 additions & 0 deletions .changeset/hot-maps-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@sphinx-labs/contracts': patch
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
'@sphinx-labs/demo': patch
---

Remove @eth-optimism/contracts-bedrock dependency due to a breaking change in a minor version update in their package
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@sphinx-labs/{contracts,plugins,executor,demo}/ds-test",
"@sphinx-labs/{contracts,plugins}/@openzeppelin/contracts",
"@sphinx-labs/{contracts,plugins}/@openzeppelin/contracts-upgradeable",
"@sphinx-labs/{contracts,plugins}/@eth-optimism/contracts-bedrock",
"@sphinx-labs/{contracts,plugins}/@eth-optimism/contracts",
"@sphinx-labs/{plugins,demo,executor}/@sphinx-labs/contracts",
"@sphinx-labs/plugins/sphinx-forge-std",
Expand Down
214 changes: 214 additions & 0 deletions packages/contracts/contracts/Proxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

/**
* @title Proxy
* @notice Proxy is a transparent proxy that passes through the call if the caller is the owner or
* if the caller is address(0), meaning that the call originated from an off-chain
* simulation.
*/
contract Proxy {
/**
* @notice The storage slot that holds the address of the implementation.
* bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
*/
bytes32 internal constant IMPLEMENTATION_KEY =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/**
* @notice The storage slot that holds the address of the owner.
* bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
*/
bytes32 internal constant OWNER_KEY =
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

/**
* @notice An event that is emitted each time the implementation is changed. This event is part
* of the EIP-1967 specification.
*
* @param implementation The address of the implementation contract
*/
event Upgraded(address indexed implementation);

/**
* @notice An event that is emitted each time the owner is upgraded. This event is part of the
* EIP-1967 specification.
*
* @param previousAdmin The previous owner of the contract
* @param newAdmin The new owner of the contract
*/
event AdminChanged(address previousAdmin, address newAdmin);

/**
* @notice A modifier that reverts if not called by the owner or by address(0) to allow
* eth_call to interact with this proxy without needing to use low-level storage
* inspection. We assume that nobody is able to trigger calls from address(0) during
* normal EVM execution.
*/
modifier proxyCallIfNotAdmin() {
if (msg.sender == _getAdmin() || msg.sender == address(0)) {
_;
} else {
// This WILL halt the call frame on completion.
_doProxyCall();
}
}

/**
* @notice Sets the initial admin during contract deployment. Admin address is stored at the
* EIP-1967 admin storage slot so that accidental storage collision with the
* implementation is not possible.
*
* @param _admin Address of the initial contract admin. Admin as the ability to access the
* transparent proxy interface.
*/
constructor(address _admin) {
_changeAdmin(_admin);
}

// slither-disable-next-line locked-ether
receive() external payable {
// Proxy call by default.
_doProxyCall();
}

// slither-disable-next-line locked-ether
fallback() external payable {
// Proxy call by default.
_doProxyCall();
}

/**
* @notice Set the implementation contract address. The code at the given address will execute
* when this contract is called.
*
* @param _implementation Address of the implementation contract.
*/
function upgradeTo(address _implementation) public virtual proxyCallIfNotAdmin {
_setImplementation(_implementation);
}

/**
* @notice Set the implementation and call a function in a single transaction. Useful to ensure
* atomic execution of initialization-based upgrades.
*
* @param _implementation Address of the implementation contract.
* @param _data Calldata to delegatecall the new implementation with.
*/
function upgradeToAndCall(
address _implementation,
bytes calldata _data
) public payable virtual proxyCallIfNotAdmin returns (bytes memory) {
_setImplementation(_implementation);
(bool success, bytes memory returndata) = _implementation.delegatecall(_data);
require(success, "Proxy: delegatecall to new implementation contract failed");
return returndata;
}

/**
* @notice Changes the owner of the proxy contract. Only callable by the owner.
*
* @param _admin New owner of the proxy contract.
*/
function changeAdmin(address _admin) public virtual proxyCallIfNotAdmin {
_changeAdmin(_admin);
}

/**
* @notice Gets the owner of the proxy contract.
*
* @return Owner address.
*/
function admin() public virtual proxyCallIfNotAdmin returns (address) {
return _getAdmin();
}

/**
* @notice Queries the implementation address.
*
* @return Implementation address.
*/
function implementation() public virtual proxyCallIfNotAdmin returns (address) {
return _getImplementation();
}

/**
* @notice Sets the implementation address.
*
* @param _implementation New implementation address.
*/
function _setImplementation(address _implementation) internal {
assembly {
sstore(IMPLEMENTATION_KEY, _implementation)
}
emit Upgraded(_implementation);
}

/**
* @notice Changes the owner of the proxy contract.
*
* @param _admin New owner of the proxy contract.
*/
function _changeAdmin(address _admin) internal {
address previous = _getAdmin();
assembly {
sstore(OWNER_KEY, _admin)
}
emit AdminChanged(previous, _admin);
}

/**
* @notice Performs the proxy call via a delegatecall.
*/
function _doProxyCall() internal {
address impl = _getImplementation();
require(impl != address(0), "Proxy: implementation not initialized");

assembly {
// Copy calldata into memory at 0x0....calldatasize.
calldatacopy(0x0, 0x0, calldatasize())

// Perform the delegatecall, make sure to pass all available gas.
let success := delegatecall(gas(), impl, 0x0, calldatasize(), 0x0, 0x0)

// Copy returndata into memory at 0x0....returndatasize. Note that this *will*
// overwrite the calldata that we just copied into memory but that doesn't really
// matter because we'll be returning in a second anyway.
returndatacopy(0x0, 0x0, returndatasize())

// Success == 0 means a revert. We'll revert too and pass the data up.
if iszero(success) {
revert(0x0, returndatasize())
}

// Otherwise we'll just return and pass the data up.
return(0x0, returndatasize())
}
}

/**
* @notice Queries the implementation address.
*
* @return Implementation address.
*/
function _getImplementation() internal view returns (address) {
address impl;
assembly {
impl := sload(IMPLEMENTATION_KEY)
}
return impl;
}

/**
* @notice Queries the owner of the proxy contract.
*
* @return Owner address.
*/
function _getAdmin() internal view returns (address) {
address owner;
assembly {
owner := sload(OWNER_KEY)
}
return owner;
}
}
2 changes: 1 addition & 1 deletion packages/contracts/contracts/SphinxAuthProxy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import { Proxy } from "@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol";
import { Proxy } from "./Proxy.sol";
import { SphinxAuthFactory } from "./SphinxAuthFactory.sol";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/SphinxManagerProxy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import { Proxy } from "@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol";
import { Proxy } from "./Proxy.sol";
import { SphinxRegistry } from "./SphinxRegistry.sol";
import { ISphinxManager } from "./interfaces/ISphinxManager.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/adapters/DefaultAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.15;

import { IProxyAdapter } from "../interfaces/IProxyAdapter.sol";
import { IProxyUpdater } from "../interfaces/IProxyUpdater.sol";
import { Proxy } from "@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol";
import { Proxy } from "../Proxy.sol";

/**
* @title DefaultAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.15;

import { IProxyAdapter } from "../interfaces/IProxyAdapter.sol";
import { IProxyUpdater } from "../interfaces/IProxyUpdater.sol";
import { Proxy } from "@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol";
import { Proxy } from "../Proxy.sol";

/**
* @title OZTransparentAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.15;

import { IProxyAdapter } from "../interfaces/IProxyAdapter.sol";
import { OZUUPSUpdater } from "../updaters/OZUUPSUpdater.sol";
import { Proxy } from "@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol";
import { Proxy } from "../Proxy.sol";

/**
* @title OZUUPSBaseAdapter
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ verbosity = 2
remappings = [
'@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/',
'@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/',
'@eth-optimism/contracts-bedrock/=node_modules/@eth-optimism/contracts-bedrock',
'@eth-optimism/contracts/=node_modules/@eth-optimism/contracts',
'@connext/interfaces=node_modules/@connext/interfaces/',
'forge-std/=node_modules/forge-std/src/',
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"dist/*",
"contracts/*",
"artifacts/contracts/**/*.json",
"artifacts/@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol/*.json",
"artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/*.json",
"artifacts/build-info/**/*.json"
],
Expand Down Expand Up @@ -50,7 +49,6 @@
},
"dependencies": {
"@eth-optimism/contracts": "^0.5.40",
"@eth-optimism/contracts-bedrock": "0.0.0-20230522161230",
"ethers": "^6.7.0"
}
}
2 changes: 1 addition & 1 deletion packages/contracts/src/ifaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const SphinxRegistryArtifact = require('../artifacts/contracts/SphinxRegi
export const SphinxManagerArtifact = require('../artifacts/contracts/SphinxManager.sol/SphinxManager.json')
export const SphinxManagerProxyArtifact = require('../artifacts/contracts/SphinxManagerProxy.sol/SphinxManagerProxy.json')
export const ManagedServiceArtifact = require('../artifacts/contracts/ManagedService.sol/ManagedService.json')
export const ProxyArtifact = require('../artifacts/@eth-optimism/contracts-bedrock/contracts/universal/Proxy.sol/Proxy.json')
export const ProxyArtifact = require('../artifacts/contracts/Proxy.sol/Proxy.json')
export const DefaultUpdaterArtifact = require('../artifacts/contracts/updaters/DefaultUpdater.sol/DefaultUpdater.json')
export const OZUUPSUpdaterArtifact = require('../artifacts/contracts/updaters/OZUUPSUpdater.sol/OZUUPSUpdater.json')
export const DefaultAdapterArtifact = require('../artifacts/contracts/adapters/DefaultAdapter.sol/DefaultAdapter.json')
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dependencies": {
"@amplitude/node": "^1.10.2",
"@eth-optimism/common-ts": "^0.7.1",
"@eth-optimism/contracts-bedrock": "0.0.0-20230522161230",
"@ethersproject/bignumber": "^5.7.0",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
Expand Down
1 change: 0 additions & 1 deletion packages/demo/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ds-test/=node_modules/ds-test/src/
@openzeppelin/contracts-upgradeable/=../../node_modules/@openzeppelin/contracts-upgradeable/
@openzeppelin/contracts/=../../node_modules/@openzeppelin/contracts/
solidity-stringutils=../../node_modules/solidity-stringutils/src/
@eth-optimism/contracts-bedrock/=../../node_modules/@eth-optimism/contracts-bedrock/
@eth-optimism/contracts/=../../node_modules/@eth-optimism/contracts/
solmate/src/=../../node_modules/solmate/src/
@layerzerolabs/solidity-examples/contracts/=../../node_modules/@layerzerolabs/solidity-examples/contracts/
165 changes: 48 additions & 117 deletions packages/plugins/contracts/foundry/SphinxConstants.sol

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
"core-js": "^3.31.1",
"dotenv": "^16.0.3",
"ethers": "^6.7.0",
"sphinx-forge-std": "https://github.com/foundry-rs/forge-std.git#v1.7.1",
"ipfs-http-client": "56.0.3",
"ipfs-only-hash": "^4.0.0",
"node-fetch": "^2.6.7",
"ora": "^5.4.1",
"semver": "^7.3.7",
"solidity-ast": "^0.4.52",
"sphinx-forge-std": "https://github.com/foundry-rs/forge-std.git#v1.7.1",
"sphinx-solmate": "npm:solmate@^6.7.0",
"stream-chain": "^2.2.5",
"stream-json": "^1.8.0",
Expand All @@ -70,8 +70,6 @@
"yesno": "^0.4.0"
},
"devDependencies": {
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"@eth-optimism/contracts-bedrock": "0.0.0-20230522161230",
"@layerzerolabs/solidity-examples": "^0.0.13",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@openzeppelin/contracts-upgradeable": "^4.8.3",
Expand All @@ -82,6 +80,7 @@
"@types/yargs": "^17.0.24",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"hardhat": "^2.17.1"
},
"peerDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ sphinx-forge-std/=node_modules/sphinx-forge-std/src/
sphinx-solmate/=node_modules/sphinx-solmate/src/
ds-test/=node_modules/ds-test/src/
solidity-stringutils=node_modules/solidity-stringutils/src/
@eth-optimism/contracts-bedrock/=node_modules/@eth-optimism/contracts-bedrock/
@eth-optimism/contracts/=node_modules/@eth-optimism/contracts/
@sphinx-labs/plugins=contracts/foundry/
@layerzerolabs/solidity-examples/contracts/=node_modules/@layerzerolabs/solidity-examples/contracts/
Loading

0 comments on commit f2c5d28

Please sign in to comment.