Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-cameras-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts-periphery': minor
---

Releases the first version of the contracts-periphery package
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
- node_modules
- packages/common-ts/node_modules
- packages/contracts/node_modules
- packages/contracts-periphery/node_modules
- packages/core-utils/node_modules
- packages/data-transport-layer/node_modules
- packages/fault-detector/node_modules
Expand Down Expand Up @@ -141,6 +142,24 @@ jobs:
command: yarn test:coverage
working_directory: packages/contracts

contracts-periphery-tests:
docker:
- image: ethereumoptimism/js-builder:latest
resource_class: xlarge
steps:
- restore_cache:
keys:
- v2-cache-yarn-build-{{ .Revision }}
- checkout
- run:
name: Lint
command: yarn lint:check
working_directory: packages/contracts-periphery
- run:
name: Test
command: yarn test:coverage
working_directory: packages/contracts-periphery

dtl-tests:
docker:
- image: ethereumoptimism/js-builder:latest
Expand Down Expand Up @@ -178,6 +197,10 @@ jobs:
name: Check contracts
command: npx depcheck
working_directory: packages/contracts
- run:
name: Check contracts-periphery
command: npx depcheck
working_directory: packages/contracts-periphery
- run:
name: Check core-utils
command: npx depcheck
Expand Down Expand Up @@ -489,6 +512,9 @@ workflows:
- contracts-tests:
requires:
- yarn-monorepo
- contracts-periphery-tests:
requires:
- yarn-monorepo
- js-lint-test:
name: dtl-tests
package_name: data-transport-layer
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- 'ops/**/*'
- 'packages/batch-submitter/**/*'
- 'packages/contracts/**/*'
- 'packages/contracts-periphery/**/*'
- 'packages/data-transport-layer/**/*'
- 'packages/message-relayer/**/*'
- 'packages/fault-detector/**/*'
Expand All @@ -25,6 +26,9 @@ M-batch-submitter:
M-contracts:
- any: ['packages/contracts/**/*']

M-contracts-periphery:
- any: ['packages/contracts-periphery/**/*']

M-core-utils:
- any: ['packages/core-utils/**/*']

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ packages/contracts/coverage*
packages/contracts/@ens*
packages/contracts/@openzeppelin*
packages/contracts/hardhat*
packages/contracts-periphery/coverage*
packages/contracts-periphery/@openzeppelin*
packages/contracts-periphery/hardhat*

packages/data-transport-layer/db

Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{"directory": "packages/core-utils", "changeProcessCWD": true },
{"directory": "packages/common-ts", "changeProcessCWD": true },
{"directory": "packages/contracts", "changeProcessCWD": true },
{"directory": "packages/contracts-periphery", "changeProcessCWD": true },
{"directory": "packages/data-transport-layer", "changeProcessCWD": true },
{"directory": "packages/batch-submitter", "changeProcessCWD": true },
{"directory": "packages/message-relayer", "changeProcessCWD": true },
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ root
├── <a href="./packages">packages</a>
│ ├── <a href="./packages/common-ts">common-ts</a>: Common tools for building apps in TypeScript
│ ├── <a href="./packages/contracts">contracts</a>: L1 and L2 smart contracts for Optimism
│ ├── <a href="./packages/contracts-periphery">contracts-periphery</a>: Peripheral contracts for Optimism
│ ├── <a href="./packages/core-utils">core-utils</a>: Low-level utilities that make building Optimism easier
│ ├── <a href="./packages/data-transport-layer">data-transport-layer</a>: Service for indexing Optimism-related L1 data
│ ├── <a href="./packages/fault-detector">fault-detector</a>:
Expand Down
1 change: 1 addition & 0 deletions ops/docker/Dockerfile.packages
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COPY packages/sdk/package.json ./packages/sdk/package.json
COPY packages/core-utils/package.json ./packages/core-utils/package.json
COPY packages/common-ts/package.json ./packages/common-ts/package.json
COPY packages/contracts/package.json ./packages/contracts/package.json
COPY packages/contracts-periphery/package.json ./packages/contracts-periphery/package.json
COPY packages/data-transport-layer/package.json ./packages/data-transport-layer/package.json
COPY packages/message-relayer/package.json ./packages/message-relayer/package.json
COPY packages/fault-detector/package.json ./packages/fault-detector/package.json
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts-periphery/.depcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ignores: [
"@openzeppelin/contracts",
"@rari-capital/solmate",
"@types/node",
"hardhat-deploy",
"ts-node",
"typescript",
"prettier-plugin-solidity",
"solhint-plugin-prettier",
]
5 changes: 5 additions & 0 deletions packages/contracts-periphery/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Etherscan API key for Ethereum and Ethereum testnets
ETHERSCAN_API_KEY=

# Etherscan API key for Optimism and Optimism testnets
OPTIMISTIC_ETHERSCAN_API_KEY=
3 changes: 3 additions & 0 deletions packages/contracts-periphery/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '../../.eslintrc.js',
}
1 change: 1 addition & 0 deletions packages/contracts-periphery/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sol linguist-language=Solidity
Empty file.
4 changes: 4 additions & 0 deletions packages/contracts-periphery/.lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"*.{ts,js}":
- eslint
"*.sol":
- yarn solhint -f table
1 change: 1 addition & 0 deletions packages/contracts-periphery/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
3 changes: 3 additions & 0 deletions packages/contracts-periphery/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../.prettierrc.js'),
}
9 changes: 9 additions & 0 deletions packages/contracts-periphery/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
skipFiles: [
'./test-libraries',
],
mocha: {
grep: "@skip-on-coverage",
invert: true
}
};
18 changes: 18 additions & 0 deletions packages/contracts-periphery/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"compiler-version": "off",
"code-complexity": ["warn", 5],
"max-line-length": ["error", 100],
"func-param-name-mixedcase": "error",
"modifier-name-mixedcase": "error",
"ordering": "warn",
"not-rely-on-time": "off",
"no-complex-fallback": "off",
"not-rely-on-block-hash": "off",
"reentrancy": "off",
"contract-name-camelcase": "off"
}
}
1 change: 1 addition & 0 deletions packages/contracts-periphery/.solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 22 additions & 0 deletions packages/contracts-periphery/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright 2020-2021 Optimism

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions packages/contracts-periphery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Optimism Peripheral Smart Contracts
7 changes: 7 additions & 0 deletions packages/contracts-periphery/codechecks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
checks:
- name: eth-gas-reporter/codechecks
settings:
speculativeBranchSelection: false
branches:
- develop
- master
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestERC20 is ERC20 {
constructor() ERC20("TEST", "TST") {}

function mint(address to, uint256 value) public {
_mint(to, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract TestERC721 is ERC721 {
constructor() ERC721("TEST", "TST") {}

function mint(address to, uint256 tokenId) public {
_mint(to, tokenId);
}
}
117 changes: 117 additions & 0 deletions packages/contracts-periphery/contracts/universal/RetroReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import { Owned } from "@rari-capital/solmate/src/auth/Owned.sol";
import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol";
import { ERC721 } from "@rari-capital/solmate/src/tokens/ERC721.sol";

/**
* @title RetroReceiver
* @notice RetroReceiver is a minimal contract for receiving funds, meant to be deployed at the
* same address on every chain that supports EIP-2470.
*/
contract RetroReceiver is Owned {
/**
* Emitted when ETH is received by this address.
*/
event ReceivedETH(address indexed from, uint256 amount);

/**
* Emitted when ETH is withdrawn from this address.
*/
event WithdrewETH(address indexed withdrawer, address indexed recipient, uint256 amount);

/**
* Emitted when ERC20 tokens are withdrawn from this address.
*/
event WithdrewERC20(
address indexed withdrawer,
address indexed recipient,
address indexed asset,
uint256 amount
);

/**
* Emitted when ERC721 tokens are withdrawn from this address.
*/
event WithdrewERC721(
address indexed withdrawer,
address indexed recipient,
address indexed asset,
uint256 id
);

/**
* @param _owner Address to initially own the contract.
*/
constructor(address _owner) Owned(_owner) {}

/**
* Make sure we can receive ETH.
*/
receive() external payable {
emit ReceivedETH(msg.sender, msg.value);
}

/**
* Withdraws full ETH balance to the recipient.
*
* @param _to Address to receive the ETH balance.
*/
function withdrawETH(address payable _to) public onlyOwner {
withdrawETH(_to, address(this).balance);
}

/**
* Withdraws partial ETH balance to the recipient.
*
* @param _to Address to receive the ETH balance.
* @param _amount Amount of ETH to withdraw.
*/
function withdrawETH(address payable _to, uint256 _amount) public onlyOwner {
_to.transfer(_amount);
emit WithdrewETH(msg.sender, _to, _amount);
}

/**
* Withdraws full ERC20 balance to the recipient.
*
* @param _asset ERC20 token to withdraw.
* @param _to Address to receive the ERC20 balance.
*/
function withdrawERC20(ERC20 _asset, address _to) public onlyOwner {
withdrawERC20(_asset, _to, _asset.balanceOf(address(this)));
}

/**
* Withdraws partial ERC20 balance to the recipient.
*
* @param _asset ERC20 token to withdraw.
* @param _to Address to receive the ERC20 balance.
* @param _amount Amount of ERC20 to withdraw.
*/
function withdrawERC20(
ERC20 _asset,
address _to,
uint256 _amount
) public onlyOwner {
_asset.transfer(_to, _amount);
emit WithdrewERC20(msg.sender, _to, address(_asset), _amount);
}

/**
* Withdraws ERC721 token to the recipient.
*
* @param _asset ERC721 token to withdraw.
* @param _to Address to receive the ERC721 token.
* @param _id Token ID of the ERC721 token to withdraw.
*/
function withdrawERC721(
ERC721 _asset,
address _to,
uint256 _id
) public onlyOwner {
_asset.transferFrom(address(this), _to, _id);
emit WithdrewERC721(msg.sender, _to, address(_asset), _id);
}
}
Loading