Skip to content

Commit

Permalink
feat: Open source platform
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Jun 10, 2024
1 parent 4daec3b commit 018550c
Show file tree
Hide file tree
Showing 34 changed files with 216 additions and 2,014 deletions.
7 changes: 7 additions & 0 deletions .changeset/good-rats-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sphinx-labs/contracts': minor
'@sphinx-labs/plugins': minor
'@sphinx-labs/core': minor
---

Opensource Platform

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions packages/contracts/contracts/core/PermissionlessRelay.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;

import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";

/**
* @title PermissionlessRelay
* @notice A contract used for the `executor` field in the Sphinx Merkle tree which allows permissionless
* execution of signed bundles by any address. This allows the Sphinx backend to work with any relayer account.
*/
contract PermissionlessRelay is ReentrancyGuard {
/**
* @notice Emitted when a call is made.
*
* @param relayer The address of the account that made the call.
* @param to The address of the remote contract.
* @param value The value transferred from the caller to the destination address.
* @param dataHash A keccak256 hash of the input data.
*/
event Called(
address indexed relayer,
address payable indexed to,
uint256 value,
bytes32 indexed dataHash
);

/**
* @notice Allows for the relayers to make arbitrary calls using this contract. We forward
* the return value of the underlying function call to allow maximum flexibility in future
* uses of this contract.
*
* @notice If `_to` is an EOA then this function will still call it and return successfully.
*
* @param _to The target address.
* @param _data The data that will be sent.
*
* @return bytes The return value of the underlying call.
*/
function exec(
address payable _to,
bytes calldata _data
) public payable nonReentrant returns (bytes memory) {
require(_to != address(0), "PermissionlessRelay: target is address(0)");

emit Called(msg.sender, _to, msg.value, keccak256(_data));

// slither-disable-next-line arbitrary-send-eth
(bool success, bytes memory res) = _to.call{ value: msg.value }(_data);

if (!success) {
// If the call failed, then decode and forward the revert reason
if (res.length == 0) revert("PermissionlessRelay: Transaction reverted silently");
assembly {
revert(add(32, res), mload(res))
}
} else {
return res;
}
}
}
4 changes: 2 additions & 2 deletions packages/contracts/contracts/foundry/Sphinx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ abstract contract Sphinx {

FoundryDeploymentInfo memory deploymentInfo = sphinxCollect(
ExecutionMode.Platform,
constants.managedServiceAddress(),
constants.permissionlessRelayAddress(),
_scriptFunctionCalldata,
_callDepth
);
Expand All @@ -163,7 +163,7 @@ abstract contract Sphinx {
// Set the `ManagedService` contract as the deployer. Although this isn't strictly
// necessary, it allows us to reuse the DevOps Platform logic for local network
// broadcasts.
deployer = constants.managedServiceAddress();
deployer = constants.permissionlessRelayAddress();
} else {
revert("Incorrect execution type.");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/foundry/SphinxConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract SphinxConstants {
address public constant multiSendAddress = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
address public constant createCallAddress = 0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4;
address public constant sphinxModuleProxyFactoryAddress = 0x8f3301c9Eada5642B5bB12FD047D3EBb2932E619;
address public constant managedServiceAddress = 0xB5E96127D417b1B3ef8438496a38A143167209c7;
address public constant permissionlessRelayAddress = 0xA2eA7657440875bF916CBFC0cfA88F13e38aD463;
address public constant safeFactoryAddress = 0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2;
address public constant safeSingletonAddress = 0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552;
address public constant sphinxModuleImplAddress = 0x8f4E4d51B8050B0ff713eff1F88f3dD8b5e8a530;
Expand Down
5 changes: 0 additions & 5 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
"files": [
"dist/*",
"contracts/*",
"out/build-info/*.json",
"out/ManagedService.sol/*.json",
"out/SphinxModule.sol/*.json",
"out/SphinxModuleProxyFactory.sol/*.json",
"out/SphinxModuleProxyFactory.sol/*.json",
"contract-artifacts/**/*.json"
],
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/scripts/write-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { ethers } from 'ethers'

import { remove0x } from '../src/utils'
import {
getManagedServiceAddress,
getSphinxModuleProxyFactoryAddress,
getGnosisSafeProxyFactoryAddress,
getGnosisSafeSingletonAddress,
getCreateCallAddress,
getCompatibilityFallbackHandlerAddress,
getMultiSendAddress,
getSphinxModuleImplAddress,
getPermissionlessRelayAddress,
} from '../src/addresses'
import {
SPHINX_NETWORKS,
Expand Down Expand Up @@ -45,9 +45,9 @@ const writeConstants = async () => {
type: 'address',
value: getSphinxModuleProxyFactoryAddress(),
},
managedServiceAddress: {
permissionlessRelayAddress: {
type: 'address',
value: getManagedServiceAddress(),
value: getPermissionlessRelayAddress(),
},
safeFactoryAddress: {
type: 'address',
Expand Down
32 changes: 3 additions & 29 deletions packages/contracts/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import {
ZeroHash,
getCreate2Address,
solidityPackedKeccak256,
AbiCoder,
ethers,
} from 'ethers'

import {
ManagedServiceArtifact,
SphinxModuleProxyFactoryArtifact,
SimulateTxAccessorArtifact,
GnosisSafeProxyFactoryArtifact,
Expand All @@ -20,10 +18,10 @@ import {
GnosisSafeArtifact,
SphinxModuleArtifact,
SignMessageLibArtifact,
DrippieArtifact,
CheckBalanceLowArtifact,
SphinxModuleProxyFactoryABI,
GnosisSafeProxyArtifact,
PermissionlessRelayArtifact,
} from './ifaces'
import {
getOwnerAddress,
Expand All @@ -35,20 +33,11 @@ export const getManagedServiceConstructorArgs = () => {
return [getOwnerAddress()]
}

export const getManagedServiceAddress = () => {
export const getPermissionlessRelayAddress = () => {
return getCreate2Address(
DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS,
ZeroHash,
solidityPackedKeccak256(
['bytes', 'bytes'],
[
ManagedServiceArtifact.bytecode,
AbiCoder.defaultAbiCoder().encode(
['address'],
getManagedServiceConstructorArgs()
),
]
)
solidityPackedKeccak256(['bytes'], [PermissionlessRelayArtifact.bytecode])
)
}

Expand Down Expand Up @@ -169,21 +158,6 @@ export const getGnosisSafeSingletonAddress = () => {
)
}

// Drippie
export const getDrippieAddress = () => {
return getCreate2Address(
DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS,
ZeroHash,
solidityPackedKeccak256(
['bytes', 'bytes'],
[
DrippieArtifact.bytecode,
AbiCoder.defaultAbiCoder().encode(['address'], [getOwnerAddress()]),
]
)
)
}

export const getCheckBalanceLowAddress = () => {
return getCreate2Address(
DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS,
Expand Down
19 changes: 5 additions & 14 deletions packages/contracts/src/contract-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import {
CompatibilityFallbackHandlerArtifact,
CreateCallArtifact,
DefaultCallbackHandlerArtifact,
DrippieArtifact,
GnosisSafeArtifact,
GnosisSafeL2Artifact,
GnosisSafeProxyFactoryArtifact,
ManagedServiceArtifact,
MultiSendArtifact,
MultiSendCallOnlyArtifact,
SimulateTxAccessorArtifact,
SphinxModuleProxyFactoryArtifact,
SignMessageLibArtifact,
SphinxModuleArtifact,
PermissionlessRelayArtifact,
} from './ifaces'
import {
ContractArtifact,
Expand All @@ -27,19 +26,17 @@ import {
getCompatibilityFallbackHandlerAddress,
getCreateCallAddress,
getDefaultCallbackHandlerAddress,
getDrippieAddress,
getGnosisSafeSingletonAddress,
getGnosisSafeL2Address,
getGnosisSafeProxyFactoryAddress,
getManagedServiceAddress,
getMultiSendAddress,
getMultiSendCallOnlyAddress,
getSignMessageLibAddress,
getSimulateTxAccessorAddress,
getSphinxModuleImplAddress,
getSphinxModuleProxyFactoryAddress,
getPermissionlessRelayAddress,
} from './addresses'
import { getOwnerAddress } from './constants'
import { remove0x } from './utils'

export enum SystemContractType {
Expand Down Expand Up @@ -71,9 +68,9 @@ export const additionalSystemContractsToVerify: Array<SphinxSystemContract> = [
export const getSphinxConstants = (): Array<SphinxSystemContract> => {
const contractInfo = [
{
artifact: ManagedServiceArtifact,
expectedAddress: getManagedServiceAddress(),
constructorArgs: [getOwnerAddress()],
artifact: PermissionlessRelayArtifact,
expectedAddress: getPermissionlessRelayAddress(),
constructorArgs: [],
type: SystemContractType.SPHINX,
},
{
Expand Down Expand Up @@ -142,12 +139,6 @@ export const getSphinxConstants = (): Array<SphinxSystemContract> => {
constructorArgs: [],
type: SystemContractType.GNOSIS_SAFE,
},
{
artifact: DrippieArtifact,
expectedAddress: getDrippieAddress(),
constructorArgs: [getOwnerAddress()],
type: SystemContractType.OPTIMISM,
},
{
artifact: CheckBalanceLowArtifact,
expectedAddress: getCheckBalanceLowAddress(),
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/src/ifaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { GnosisSafeContractArtifact } from './types'
import { parseFoundryContractArtifact } from './utils'

/* eslint-disable @typescript-eslint/no-var-requires */
export const ManagedServiceArtifact = parseFoundryContractArtifact(
require('../contract-artifacts/sphinx/ManagedService.sol/ManagedService.json')
export const PermissionlessRelayArtifact = parseFoundryContractArtifact(
require('../contract-artifacts/sphinx/PermissionlessRelay.sol/PermissionlessRelay.json')
)
export const SphinxModuleArtifact = parseFoundryContractArtifact(
require('../contract-artifacts/sphinx/SphinxModule.sol/SphinxModule.json')
Expand All @@ -12,7 +12,7 @@ export const SphinxModuleProxyFactoryArtifact = parseFoundryContractArtifact(
require('../contract-artifacts/sphinx/SphinxModuleProxyFactory.sol/SphinxModuleProxyFactory.json')
)

export const ManagedServiceABI = ManagedServiceArtifact.abi
export const ManagedServiceABI = PermissionlessRelayArtifact.abi
export const SphinxModuleABI = SphinxModuleArtifact.abi
export const SphinxModuleProxyFactoryABI = SphinxModuleProxyFactoryArtifact.abi

Expand Down
Loading

0 comments on commit 018550c

Please sign in to comment.