Skip to content

Commit

Permalink
Merge pull request #10 from mirooon/test7
Browse files Browse the repository at this point in the history
new
  • Loading branch information
mirooon authored Feb 18, 2025
2 parents d9ffa55 + 1817bc9 commit 3cecdf4
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/securityAlertsReview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ name: Security Alerts Review
# - helps maintain a transparent and collaborative security review process by generating a pr comment summarizing the status of all security alerts.

on:
push:
paths:
- 'src/**.sol'
pull_request:
types:
- synchronize
- reopened
- ready_for_review
paths:
- 'src/**.sol'
pull_request_review:
types:
- submitted
Expand Down
104 changes: 104 additions & 0 deletions src/Facets/OmniBridgeFacetNewNewNewNew.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import { ILiFi } from "../Interfaces/ILiFi.sol";
import { IOmniBridge } from "../Interfaces/IOmniBridge.sol";
import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol";
import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol";
import { SwapperV2, LibSwap } from "../Helpers/SwapperV2.sol";
import { Validatable } from "../Helpers/Validatable.sol";

/// @title OmniBridge Facet
/// @author LI.FI (https://li.fi)
/// @notice Provides functionality for bridging through OmniBridge
/// @custom:version 1.0.0
contract OmniBridgeFacetNew is ILiFi, ReentrancyGuard, SwapperV2, Validatable {
/// Storage ///

/// @notice The contract address of the foreign omni bridge on the source chain.
IOmniBridge private immutable foreignOmniBridge;

/// @notice The contract address of the weth omni bridge on the source chain.
IOmniBridge private immutable wethOmniBridge;

/// Constructor ///

/// @notice Initialize the contract.
/// @param _foreignOmniBridge The contract address of the foreign omni bridge on the source chain.
/// @param _wethOmniBridge The contract address of the weth omni bridge on the source chain.
constructor(IOmniBridge _foreignOmniBridge, IOmniBridge _wethOmniBridge) {
foreignOmniBridge = _foreignOmniBridge;
wethOmniBridge = _wethOmniBridge;
}

/// External Methods ///

/// @notice Bridges tokens via OmniBridge
/// @param _bridgeData Data contaning core information for bridging
function startBridgeTokensViaOmniBridge(
ILiFi.BridgeData memory _bridgeData
)
external
payable
nonReentrant
refundExcessNative(payable(msg.sender))
doesNotContainSourceSwaps(_bridgeData)
doesNotContainDestinationCalls(_bridgeData)
validateBridgeData(_bridgeData)
{
LibAsset.depositAsset(
_bridgeData.sendingAssetId,
_bridgeData.minAmount
);
_startBridge(_bridgeData);
}

/// @notice Performs a swap before bridging via OmniBridge
/// @param _bridgeData Data contaning core information for bridging
/// @param _swapData An array of swap related data for performing swaps before bridging
function swapAndStartBridgeTokensViaOmniBridge(
ILiFi.BridgeData memory _bridgeData,
LibSwap.SwapData[] calldata _swapData
)
external
payable
nonReentrant
refundExcessNative(payable(msg.sender))
containsSourceSwaps(_bridgeData)
doesNotContainDestinationCalls(_bridgeData)
validateBridgeData(_bridgeData)
{
_bridgeData.minAmount = _depositAndSwap(
_bridgeData.transactionId,
_bridgeData.minAmount,
_swapData,
payable(msg.sender)
);
_startBridge(_bridgeData);
}

/// Private Methods ///

/// @dev Contains the business logic for the bridge via OmniBridge
/// @param _bridgeData Data contaning core information for bridging
function _startBridge(ILiFi.BridgeData memory _bridgeData) private {
if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) {
wethOmniBridge.wrapAndRelayTokens{ value: _bridgeData.minAmount }(
_bridgeData.receiver
);
} else {
LibAsset.maxApproveERC20(
IERC20(_bridgeData.sendingAssetId),
address(foreignOmniBridge),
_bridgeData.minAmount
);
foreignOmniBridge.relayTokens(
_bridgeData.sendingAssetId,
_bridgeData.receiver,
_bridgeData.minAmount
);
}

emit LiFiTransferStarted(_bridgeData);
}
}

0 comments on commit 3cecdf4

Please sign in to comment.