Skip to content

Commit

Permalink
feat: Zora deployments (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl authored Aug 6, 2024
1 parent d721cce commit 502fdc4
Show file tree
Hide file tree
Showing 17 changed files with 3,438 additions and 7 deletions.
44 changes: 44 additions & 0 deletions contracts/Zora_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 Zora Spoke pool.
* @custom:security-contact bugs@across.to
*/
contract Zora_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 Zora 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/Zora_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 Zora. 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 bugs@across.to
*/

// solhint-disable-next-line contract-name-camelcase
contract Zora_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 Zora 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 Zora.
* @param target Contract on Zora 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 Zora.
* @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);
}
}
28 changes: 28 additions & 0 deletions deploy/048_deploy_zora_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("Zora_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [
WETH[chainId],
L1_ADDRESS_MAP[chainId].zoraCrossDomainMessenger,
L1_ADDRESS_MAP[chainId].zoraStandardBridge,
ZERO_ADDRESS,
],
});
};

module.exports = func;
func.tags = ["ZoraAdapter", "mainnet"];
38 changes: 38 additions & 0 deletions deploy/049_deploy_zora_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 { ZORA } = 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("Zora_SpokePool", constructorArgs, initArgs, spokeChainId === ZORA);
};
module.exports = func;
func.tags = ["spokepool", "zora"];
2 changes: 2 additions & 0 deletions deploy/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const L1_ADDRESS_MAP: { [key: number]: { [contractName: string]: string }
blastDaiRetriever: "0x98Dd57048d7d5337e92D9102743528ea4Fea64aB",
redstoneCrossDomainMessenger: "0x592C1299e0F8331D81A28C0FC7352Da24eDB444a",
redstoneStandardBridge: "0xc473ca7E02af24c129c2eEf51F2aDf0411c1Df69",
zoraCrossDomainMessenger: "0x363B4B1ADa52E50353f746999bd9E94395190d2C",
zoraStandardBridge: "0xbF6acaF315477b15D638bf4d91eA48FA79b58335",
},
4: {
weth: "0xc778417E063141139Fce010982780140Aa0cD5Ab",
Expand Down
8 changes: 7 additions & 1 deletion deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"Scroll_Adapter": { "address": "0xb6129Ab69aEA75e6884c2D6ecf25293C343C519F", "blockNumber": 20318360 },
"Blast_DaiRetriever": { "address": "0x98Dd57048d7d5337e92D9102743528ea4Fea64aB", "blockNumber": 20378862 },
"Blast_RescueAdapter": { "address": "0xE5Dea263511F5caC27b15cBd58Ff103F4Ce90957", "blockNumber": 20378872 },
"Redstone_Adapter": { "address": "0x188F8C95B7cfB7993B53a4F643efa687916f73fA", "blockNumber": 20432774 }
"Redstone_Adapter": { "address": "0x188F8C95B7cfB7993B53a4F643efa687916f73fA", "blockNumber": 20432774 },
"Zora_Adapter": { "address": "0xa27fb9f2A22F8dA4cBF155e9795A43488004AAc3", "blockNumber": 20468487 }
},
"4": {
"Arbitrum_Adapter": { "address": "0x18F4D98C7CeA6Ab934F2976c2a98009A529d8F49", "blockNumber": 10367195 },
Expand Down Expand Up @@ -173,6 +174,11 @@
"SpokePoolVerifier": { "address": "0xB4A8d45647445EA9FC3E1058096142390683dBC2", "blockNumber": 7490003 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 7489978 }
},
"7777777": {
"SpokePool": { "address": "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64", "blockNumber": 18119425 },
"SpokePoolVerifier": { "address": "0xB4A8d45647445EA9FC3E1058096142390683dBC2", "blockNumber": 18120222 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 18119854 }
},
"11155111": {
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 6284508 },
"AcrossConfigStore": { "address": "0xB3De1e212B49e68f4a68b5993f31f63946FCA2a6", "blockNumber": 4968255 },
Expand Down
1 change: 1 addition & 0 deletions deployments/zora/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7777777
Loading

0 comments on commit 502fdc4

Please sign in to comment.