Skip to content

Commit

Permalink
Deployment adjustments
Browse files Browse the repository at this point in the history
Here we adjust the new contracts for deployment:
- We are introducing the `attach*BitcoinDepositor` functions to solve
  the chicken & egg problem that occurs upon deployment
- We are adjusting gas limits for Wormhole to real-world values
- We are getting rid of cross-chain Wormhole refunds that don't work
  for small amounts
  • Loading branch information
lukasz-zimnoch committed Mar 1, 2024
1 parent 5a179fd commit 7f81fbe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
27 changes: 19 additions & 8 deletions solidity/contracts/l2/L1BitcoinDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ contract L1BitcoinDepositor is
address _wormholeRelayer,
address _wormholeTokenBridge,
address _l2WormholeGateway,
uint16 _l2ChainId,
address _l2BitcoinDepositor
uint16 _l2ChainId
) external initializer {
__AbstractTBTCDepositor_initialize(_tbtcBridge, _tbtcVault);
__Ownable_init();
Expand All @@ -100,8 +99,23 @@ contract L1BitcoinDepositor is
wormholeTokenBridge = IWormholeTokenBridge(_wormholeTokenBridge);
l2WormholeGateway = _l2WormholeGateway;
l2ChainId = _l2ChainId;
l2FinalizeDepositGasLimit = 500_000;
}

// TODO: Document this function.
function attachL2BitcoinDepositor(address _l2BitcoinDepositor)
external
onlyOwner
{
require(
l2BitcoinDepositor == address(0),
"L2 Bitcoin Depositor already set"
);
require(
_l2BitcoinDepositor != address(0),
"L2 Bitcoin Depositor must not be 0x0"
);
l2BitcoinDepositor = _l2BitcoinDepositor;
l2FinalizeDepositGasLimit = 200_000;
}

// TODO: Document this function.
Expand Down Expand Up @@ -269,14 +283,11 @@ contract L1BitcoinDepositor is
abi.encode(l2Receiver) // Set the L2 receiver address as the transfer payload.
);

// Get Wormhole chain ID for this L1 chain.
uint16 l1ChainId = wormhole.chainId();

// Construct VAA representing the above Wormhole token transfer.
WormholeTypes.VaaKey[]
memory additionalVaas = new WormholeTypes.VaaKey[](1);
additionalVaas[0] = WormholeTypes.VaaKey({
chainId: l1ChainId,
chainId: wormhole.chainId(),
emitterAddress: WormholeUtils.toWormholeAddress(
address(wormholeTokenBridge)
),
Expand All @@ -296,7 +307,7 @@ contract L1BitcoinDepositor is
0, // No receiver value needed.
l2FinalizeDepositGasLimit,
additionalVaas,
l1ChainId, // Set this L1 chain as the refund chain.
l2ChainId, // Set the L2 chain as the refund chain to avoid cross-chain refunds.
msg.sender // Set the caller as the refund receiver.
);
}
Expand Down
25 changes: 18 additions & 7 deletions solidity/contracts/l2/L2BitcoinDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ contract L2BitcoinDepositor is IWormholeReceiver, OwnableUpgradeable {
// TODO: Document state variables.
IWormholeRelayer public wormholeRelayer;
IL2WormholeGateway public l2WormholeGateway;
uint16 public l2ChainId;
uint16 public l1ChainId;
address public l1BitcoinDepositor;
uint256 public l1InitializeDepositGasLimit;
Expand All @@ -58,20 +57,32 @@ contract L2BitcoinDepositor is IWormholeReceiver, OwnableUpgradeable {
function initialize(
address _wormholeRelayer,
address _l2WormholeGateway,
uint16 _l2ChainId,
uint16 _l1ChainId,
address _l1BitcoinDepositor
uint16 _l1ChainId
) external initializer {
__Ownable_init();

wormholeRelayer = IWormholeRelayer(_wormholeRelayer);
l2WormholeGateway = IL2WormholeGateway(_l2WormholeGateway);
l2ChainId = _l2ChainId;
l1ChainId = _l1ChainId;
l1BitcoinDepositor = _l1BitcoinDepositor;
l1InitializeDepositGasLimit = 200_000;
}

// TODO: Document this function.
function attachL1BitcoinDepositor(address _l1BitcoinDepositor)
external
onlyOwner
{
require(
l1BitcoinDepositor == address(0),
"L1 Bitcoin Depositor already set"
);
require(
_l1BitcoinDepositor != address(0),
"L1 Bitcoin Depositor must not be 0x0"
);
l1BitcoinDepositor = _l1BitcoinDepositor;
}

// TODO: Document this function.
function updateL1InitializeDepositGasLimit(
uint256 _l1InitializeDepositGasLimit
Expand Down Expand Up @@ -105,7 +116,7 @@ contract L2BitcoinDepositor is IWormholeReceiver, OwnableUpgradeable {
abi.encode(fundingTx, reveal, l2DepositOwner), // Message payload.
0, // No receiver value needed.
l1InitializeDepositGasLimit,
l2ChainId, // Set this L2 chain as the refund chain.
l1ChainId, // Set the L1 chain as the refund chain to avoid cross-chain refunds.
msg.sender // Set the caller as the refund receiver.
);

Expand Down

0 comments on commit 7f81fbe

Please sign in to comment.