Skip to content

Commit

Permalink
feat: Redstone deployment (#570)
Browse files Browse the repository at this point in the history
This commit adds the deployment details for Redstone. Some notes:
- A comment recently added to the MulticallHandler contract had to be
  backed out because it affects the resulting bytecode and subsequently
  the deployed address.
- The current version of the SpokePoolVerifier is not audited. Both
  the current and previous versions have been deployed, but the previous
  version is used, such that its deployment addresses matches all other
  currently-used SpokePoolVerifier addresses.
  • Loading branch information
pxrl authored Aug 1, 2024
1 parent 01728d3 commit 50b6b56
Show file tree
Hide file tree
Showing 24 changed files with 4,447 additions and 8 deletions.
44 changes: 44 additions & 0 deletions contracts/Redstone_SpokePool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol";

import "./Ovm_SpokePool.sol";
import "./external/interfaces/CCTPInterfaces.sol";

/**
* @notice Redstone Spoke pool.
* @custom:security-contact [email protected]
*/
contract Redstone_SpokePool is Ovm_SpokePool {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
address _wrappedNativeTokenAddress,
uint32 _depositQuoteTimeBuffer,
uint32 _fillDeadlineBuffer,
IERC20 _l2Usdc,
ITokenMessenger _cctpTokenMessenger
)
Ovm_SpokePool(
_wrappedNativeTokenAddress,
_depositQuoteTimeBuffer,
_fillDeadlineBuffer,
_l2Usdc,
_cctpTokenMessenger
)
{} // solhint-disable-line no-empty-blocks

/**
* @notice Construct the OVM Redstone SpokePool.
* @param _initialDepositId Starting deposit ID. Set to 0 unless this is a re-deployment in order to mitigate
* relay hash collisions.
* @param _crossDomainAdmin Cross domain admin to set. Can be changed by admin.
* @param _hubPool Hub pool address to set. Can be changed by admin.
*/
function initialize(
uint32 _initialDepositId,
address _crossDomainAdmin,
address _hubPool
) public initializer {
__OvmSpokePool_init(_initialDepositId, _crossDomainAdmin, _hubPool, Lib_PredeployAddresses.OVM_ETH);
}
}
100 changes: 100 additions & 0 deletions contracts/chain-adapters/Redstone_Adapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "./interfaces/AdapterInterface.sol";
import "../external/interfaces/WETH9Interface.sol";

// @dev Use local modified CrossDomainEnabled contract instead of one exported by eth-optimism because we need
// this contract's state variables to be `immutable` because of the delegateCall call.
import "./CrossDomainEnabled.sol";
import "@eth-optimism/contracts/L1/messaging/IL1StandardBridge.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../libraries/CircleCCTPAdapter.sol";
import "../external/interfaces/CCTPInterfaces.sol";

/**
* @notice Contract containing logic to send messages from L1 to Redstone. This is a clone of the Base/Mode adapter
* @dev Public functions calling external contracts do not guard against reentrancy because they are expected to be
* called via delegatecall, which will execute this contract's logic within the context of the originating contract.
* For example, the HubPool will delegatecall these functions, therefore its only necessary that the HubPool's methods
* that call this contract's logic guard against reentrancy.
* @custom:security-contact [email protected]
*/

// solhint-disable-next-line contract-name-camelcase
contract Redstone_Adapter is CrossDomainEnabled, AdapterInterface, CircleCCTPAdapter {
using SafeERC20 for IERC20;
uint32 public constant L2_GAS_LIMIT = 200_000;

WETH9Interface public immutable L1_WETH;

IL1StandardBridge public immutable L1_STANDARD_BRIDGE;

/**
* @notice Constructs new Adapter.
* @param _l1Weth WETH address on L1.
* @param _crossDomainMessenger XDomainMessenger Redstone system contract.
* @param _l1StandardBridge Standard bridge contract.
* @param _l1Usdc USDC address on L1.
*/
constructor(
WETH9Interface _l1Weth,
address _crossDomainMessenger,
IL1StandardBridge _l1StandardBridge,
IERC20 _l1Usdc
)
CrossDomainEnabled(_crossDomainMessenger)
CircleCCTPAdapter(
_l1Usdc,
// Hardcode cctp messenger to 0x0 to disable CCTP bridging.
ITokenMessenger(address(0)),
CircleDomainIds.UNINTIALIZED
)
{
L1_WETH = _l1Weth;
L1_STANDARD_BRIDGE = _l1StandardBridge;
}

/**
* @notice Send cross-chain message to target on Redstone.
* @param target Contract on Redstone that will receive message.
* @param message Data to send to target.
*/
function relayMessage(address target, bytes calldata message) external payable override {
sendCrossDomainMessage(target, L2_GAS_LIMIT, message);
emit MessageRelayed(target, message);
}

/**
* @notice Bridge tokens to Redstone.
* @param l1Token L1 token to deposit.
* @param l2Token L2 token to receive.
* @param amount Amount of L1 tokens to deposit and L2 tokens to receive.
* @param to Bridge recipient.
*/
function relayTokens(
address l1Token,
address l2Token,
uint256 amount,
address to
) external payable override {
// If the l1Token is weth then unwrap it to ETH then send the ETH to the standard bridge.
if (l1Token == address(L1_WETH)) {
L1_WETH.withdraw(amount);
L1_STANDARD_BRIDGE.depositETHTo{ value: amount }(to, L2_GAS_LIMIT, "");
}
// Check if this token is USDC, which requires a custom bridge via CCTP.
else if (_isCCTPEnabled() && l1Token == address(usdcToken)) {
_transferUsdc(to, amount);
} else {
IL1StandardBridge _l1StandardBridge = L1_STANDARD_BRIDGE;

IERC20(l1Token).safeIncreaseAllowance(address(_l1StandardBridge), amount);
_l1StandardBridge.depositERC20To(l1Token, l2Token, to, amount, L2_GAS_LIMIT, "");
}
emit TokensRelayed(l1Token, l2Token, amount, to);
}
}
1 change: 0 additions & 1 deletion contracts/handlers/MulticallHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
* @title Across Multicall contract that allows a user to specify a series of calls that should be made by the handler
* via the message field in the deposit.
* @dev This contract makes the calls blindly. The contract will send any remaining tokens The caller should ensure that the tokens recieved by the handler are completely consumed.
* @custom:security-contact [email protected]
*/
contract MulticallHandler is AcrossMessageHandler, ReentrancyGuard {
using SafeERC20 for IERC20;
Expand Down
28 changes: 28 additions & 0 deletions deploy/046_deploy_redstone_adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ZERO_ADDRESS } from "@uma/common";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { L1_ADDRESS_MAP, WETH } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId, network } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

const chainId = parseInt(await getChainId());

await deploy("Redstone_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [
WETH[chainId],
L1_ADDRESS_MAP[chainId].redstoneCrossDomainMessenger,
L1_ADDRESS_MAP[chainId].redstoneStandardBridge,
ZERO_ADDRESS,
],
});
};

module.exports = func;
func.tags = ["RedstoneAdapter", "mainnet"];
38 changes: 38 additions & 0 deletions deploy/047_deploy_redstone_spokepool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ZERO_ADDRESS } from "@uma/common";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { CHAIN_IDs } from "../utils";
import { WETH } from "./consts";

const { REDSTONE } = CHAIN_IDs;

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);

const initArgs = [
1,
// Set hub pool as cross domain admin since it delegatecalls the Adapter logic.
hubPool.address,
hubPool.address,
];
// Construct this spokepool with a:
// * A WETH address of the WETH address
// * A depositQuoteTimeBuffer of 1 hour
// * A fillDeadlineBuffer of 6 hours
// * Native USDC address on L2
// * CCTP token messenger address on L2
const constructorArgs = [
WETH[spokeChainId],
3600,
21600,
ZERO_ADDRESS,
// L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
// For now, we are not using the CCTP bridge and can disable by setting
// the cctpTokenMessenger to the zero address.
ZERO_ADDRESS,
];
await deployNewProxy("Redstone_SpokePool", constructorArgs, initArgs, spokeChainId === REDSTONE);
};
module.exports = func;
func.tags = ["spokepool", "redstone"];
6 changes: 6 additions & 0 deletions deploy/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils";

export const WETH = TOKEN_SYMBOLS_MAP.WETH.addresses;

export const L1_ADDRESS_MAP: { [key: number]: { [contractName: string]: string } } = {
1: {
optimismCrossDomainMessenger: "0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1", // Source: https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts/deployments
Expand Down Expand Up @@ -37,6 +41,8 @@ export const L1_ADDRESS_MAP: { [key: number]: { [contractName: string]: string }
liskStandardBridge: "0x2658723Bf70c7667De6B25F99fcce13A16D25d08",
blastYieldManager: "0xa230285d5683C74935aD14c446e137c8c8828438",
blastDaiRetriever: "0x98Dd57048d7d5337e92D9102743528ea4Fea64aB",
redstoneCrossDomainMessenger: "0x592C1299e0F8331D81A28C0FC7352Da24eDB444a",
redstoneStandardBridge: "0xc473ca7E02af24c129c2eEf51F2aDf0411c1Df69",
},
4: {
weth: "0xc778417E063141139Fce010982780140Aa0cD5Ab",
Expand Down
7 changes: 7 additions & 0 deletions deployments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@
| Blast_SpokePool | [0x2D509190Ed0172ba588407D4c2df918F955Cc6E1](https://blastscan.io/address/0x2D509190Ed0172ba588407D4c2df918F955Cc6E1) |
| MulticallHandler | [0x924a9f036260DdD5808007E1AA95f08eD08aA569](https://blastscan.io/address/0x924a9f036260DdD5808007E1AA95f08eD08aA569) |

## Redstone mainnet (690)

| Contract Name | Address |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| Redstone_SpokePool | [0x28077B47Cd03326De7838926A63699849DD4fa87](https://explorer.redstone.xyz/address/0x28077B47Cd03326De7838926A63699849DD4fa87) |
| MulticallHandler | [0x924a9f036260DdD5808007E1AA95f08eD08aA569](https://explorer.redstone.xyz/address/0x924a9f036260DdD5808007E1AA95f08eD08aA569) |

## Scroll mainnet (534352)

| Contract Name | Address |
Expand Down
8 changes: 7 additions & 1 deletion deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"Blast_Adapter": { "address": "0xF2bEf5E905AAE0295003ab14872F811E914EdD81", "blockNumber": 20221494 },
"Scroll_Adapter": { "address": "0xb6129Ab69aEA75e6884c2D6ecf25293C343C519F", "blockNumber": 20318360 },
"Blast_DaiRetriever": { "address": "0x98Dd57048d7d5337e92D9102743528ea4Fea64aB", "blockNumber": 20378862 },
"Blast_RescueAdapter": { "address": "0xE5Dea263511F5caC27b15cBd58Ff103F4Ce90957", "blockNumber": 20378872 }
"Blast_RescueAdapter": { "address": "0xE5Dea263511F5caC27b15cBd58Ff103F4Ce90957", "blockNumber": 20378872 },
"Redstone_Adapter": { "address": "0x188F8C95B7cfB7993B53a4F643efa687916f73fA", "blockNumber": 20432774 }
},
"4": {
"Arbitrum_Adapter": { "address": "0x18F4D98C7CeA6Ab934F2976c2a98009A529d8F49", "blockNumber": 10367195 },
Expand Down Expand Up @@ -95,6 +96,11 @@
"MulticallHandler": { "address": "0x863859ef502F0Ee9676626ED5B418037252eFeb2", "blockNumber": 36906393 }
},
"420": { "SpokePool": { "address": "0xeF684C38F94F48775959ECf2012D7E864ffb9dd4", "blockNumber": 17025501 } },
"690": {
"SpokePool": { "address": "0x28077B47Cd03326De7838926A63699849DD4fa87", "blockNumber": 5158526 },
"SpokePoolVerifier": { "address": "0xB4A8d45647445EA9FC3E1058096142390683dBC2", "blockNumber": 5161326 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 5159031 }
},
"919": {
"SpokePool": { "address": "0xbd886FC0725Cc459b55BbFEb3E4278610331f83b", "blockNumber": 13999465 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 15826581 }
Expand Down
Loading

0 comments on commit 50b6b56

Please sign in to comment.