Skip to content

Commit

Permalink
fix: small adjustments to crosschain contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
evandrosaturnino committed Feb 23, 2025
1 parent c15b644 commit e06fe3a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 95 deletions.
3 changes: 1 addition & 2 deletions solidity/contracts/cross-chain/L1BitcoinDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract contract L1BitcoinDepositor is
Reimbursable
{
using SafeERC20Upgradeable for IERC20Upgradeable;

/// @notice Reflects the deposit state:
/// - Unknown deposit has not been initialized yet.
/// - Initialized deposit has been initialized with a call to
Expand Down Expand Up @@ -157,7 +157,6 @@ abstract contract L1BitcoinDepositor is
__AbstractTBTCDepositor_initialize(_tbtcBridge, _tbtcVault);

tbtcToken = IERC20Upgradeable(ITBTCVault(_tbtcVault).tbtcToken());
// slither-disable-next-line missing-zero-check

initializeDepositGasOffset = 60_000;
finalizeDepositGasOffset = 20_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";

import "./LayerZero.sol";
import "../L1BitcoinDepositor.sol";

Expand All @@ -23,27 +26,8 @@ import "../L1BitcoinDepositor.sol";
/// users to obtain ERC20 TBTC on supported L2 chains, without the need
/// to interact with the L1 tBTC ledger chain where minting occurs.
contract L1BitcoinDepositorLayerZero is L1BitcoinDepositor {
/**
* @dev Struct representing token parameters for the OFT send() operation.
*/
struct SendParam {
uint32 dstEid; // Destination endpoint ID.
bytes32 to; // Recipient address.
uint256 amountLD; // Amount to send in local decimals.
uint256 minAmountLD; // Minimum amount to send in local decimals.
bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
bytes composeMsg; // The composed message for the send() operation.
bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations.
}

/**
* @dev Struct representing message fee for the OFT send() operation.
*/
struct MessagingFee {
uint nativeFee; // gas amount in native gas token
uint lzTokenFee; // gas amount in ZRO token
}

using SafeERC20Upgradeable for IERC20Upgradeable;

/// @notice tBTC `l1OFTAdapter` contract.
IOFT public l1OFTAdapter;
/// @notice LayerZero Destination Endpoint Id.
Expand Down Expand Up @@ -93,16 +77,18 @@ contract L1BitcoinDepositorLayerZero is L1BitcoinDepositor {
require(minimumAmount > 0, "minimumAmount too low to bridge");
require(amount > 0, "Amount too low to bridge");

MessagingFee msgFee = l1OFTAdapter.quoteSend(
{
LayerZeroTypes.SendParam memory sendParam = LayerZeroTypes.SendParam({
dstEid: destinationEndpointId,
to: l2Receiver,
amountLD: amount,
minAmountLD: minimumAmount,
extraOptions: bytes(""),
composeMsg: bytes(""),
oftCmd: bytes("")
},
});

LayerZeroTypes.MessagingFee memory msgFee = l1OFTAdapter.quoteSend(
sendParam,
false
);

Expand All @@ -115,19 +101,7 @@ contract L1BitcoinDepositorLayerZero is L1BitcoinDepositor {
// Initiate a LayerZero token transfer that will mint L2 TBTC and
// send it to the user.
// slither-disable-next-line arbitrary-send-eth
l1OFTAdapter.send{
value: msgFee.nativeFee
}(
{
dstEid: destinationEndpointId,
to: l2Receiver,
amountLD: amount,
minAmountLD: minimumAmount,
extraOptions: bytes(""),
composeMsg: bytes(""),
oftCmd: bytes("")
}
);
l1OFTAdapter.send{ value: msgFee.nativeFee }(sendParam);
}

/**
Expand Down
116 changes: 60 additions & 56 deletions solidity/contracts/cross-chain/layerzero/LayerZero.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,65 @@

pragma solidity ^0.8.17;

/**
* @dev Struct representing the LayerZero messaging receipt.
*/
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
/// @title LayerZeroTypes
/// @notice Namespace which groups all types relevant to LayerZero interfaces.
library LayerZeroTypes {
/**
* @dev Struct representing the LayerZero messaging receipt.
*/
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}

/**
* @dev Struct representing the LayerZero messaging fee.
*/
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
/**
* @dev Struct representing the LayerZero messaging fee.
*/
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}

/**
* @dev Struct representing token parameters for the OFT send() operation.
*/
struct SendParam {
uint32 dstEid; // Destination endpoint ID.
bytes32 to; // Recipient address.
uint256 amountLD; // Amount to send in local decimals.
uint256 minAmountLD; // Minimum amount to send in local decimals.
bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
bytes composeMsg; // The composed message for the send() operation.
bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations.
}
/**
* @dev Struct representing token parameters for the OFT send() operation.
*/
struct SendParam {
uint32 dstEid; // Destination endpoint ID.
bytes32 to; // Recipient address.
uint256 amountLD; // Amount to send in local decimals.
uint256 minAmountLD; // Minimum amount to send in local decimals.
bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
bytes composeMsg; // The composed message for the send() operation.
bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations.
}

/**
* @dev Struct representing OFT limit information.
* @dev These amounts can change dynamically and are up the the specific oft implementation.
*/
struct OFTLimit {
uint256 minAmountLD; // Minimum amount in local decimals that can be sent to the recipient.
uint256 maxAmountLD; // Maximum amount in local decimals that can be sent to the recipient.
}
/**
* @dev Struct representing OFT limit information.
* @dev These amounts can change dynamically and are up the the specific oft implementation.
*/
struct OFTLimit {
uint256 minAmountLD; // Minimum amount in local decimals that can be sent to the recipient.
uint256 maxAmountLD; // Maximum amount in local decimals that can be sent to the recipient.
}

/**
* @dev Struct representing OFT receipt information.
*/
struct OFTReceipt {
uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals.
// @dev In non-default implementations, the amountReceivedLD COULD differ from this value.
uint256 amountReceivedLD; // Amount of tokens to be received on the remote side.
}
/**
* @dev Struct representing OFT receipt information.
*/
struct OFTReceipt {
uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals.
// @dev In non-default implementations, the amountReceivedLD COULD differ from this value.
uint256 amountReceivedLD; // Amount of tokens to be received on the remote side.
}

/**
* @dev Struct representing OFT fee details.
* @dev Future proof mechanism to provide a standardized way to communicate fees to things like a UI.
*/
struct OFTFeeDetail {
int256 feeAmountLD; // Amount of the fee in local decimals.
string description; // Description of the fee.
/**
* @dev Struct representing OFT fee details.
* @dev Future proof mechanism to provide a standardized way to communicate fees to things like a UI.
*/
struct OFTFeeDetail {
int256 feeAmountLD; // Amount of the fee in local decimals.
string description; // Description of the fee.
}
}

/**
Expand Down Expand Up @@ -139,8 +143,8 @@ interface IOFT {
* @return receipt The OFT receipt information.
*/
function quoteOFT(
SendParam calldata _sendParam
) external view returns (OFTLimit memory, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory);
LayerZeroTypes.SendParam calldata _sendParam
) external view returns (LayerZeroTypes.OFTLimit memory, LayerZeroTypes.OFTFeeDetail[] memory oftFeeDetails, LayerZeroTypes.OFTReceipt memory);

/**
* @notice Provides a quote for the send() operation.
Expand All @@ -152,7 +156,7 @@ interface IOFT {
* - nativeFee: The native fee.
* - lzTokenFee: The lzToken fee.
*/
function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory);
function quoteSend(LayerZeroTypes.SendParam calldata _sendParam, bool _payInLzToken) external view returns (LayerZeroTypes.MessagingFee memory);

/**
* @notice Executes the send() operation.
Expand All @@ -170,8 +174,8 @@ interface IOFT {
* - fee: The LayerZero fee incurred for the message.
*/
function send(
SendParam calldata _sendParam,
MessagingFee calldata _fee,
LayerZeroTypes.SendParam calldata _sendParam,
LayerZeroTypes.MessagingFee calldata _fee,
address _refundAddress
) external payable returns (MessagingReceipt memory, OFTReceipt memory);
) external payable returns (LayerZeroTypes.MessagingReceipt memory, LayerZeroTypes.OFTReceipt memory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";

import "./Wormhole.sol";
import "../L1BitcoinDepositor.sol";

Expand All @@ -23,6 +26,7 @@ import "../L1BitcoinDepositor.sol";
/// users to obtain ERC20 TBTC on supported L2 chains, without the need
/// to interact with the L1 tBTC ledger chain where minting occurs.
contract L1BitcoinDepositorWormhole is L1BitcoinDepositor {
using SafeERC20Upgradeable for IERC20Upgradeable;

/// @notice `Wormhole` core contract on L1.
IWormhole public wormhole;
Expand Down

0 comments on commit e06fe3a

Please sign in to comment.