Skip to content

Commit

Permalink
Merge pull request #13 from mirooon/test10
Browse files Browse the repository at this point in the history
d
  • Loading branch information
mirooon authored Feb 18, 2025
2 parents ce43998 + 09c43dd commit d785231
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 53 deletions.
53 changes: 0 additions & 53 deletions .github/workflows/forge.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .github/workflows/securityAlertsReview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ github.head_ref }}
run: |
# Fallback in case BRANCH_NAME is empty.
if [ -z "$BRANCH_NAME" ]; then
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF##*/}}"
echo "BRANCH_NAME was empty, falling back to: $BRANCH_NAME"
fi
echo "Checking latest Olympix Static Analysis run for branch: $BRANCH_NAME"
# Fetch the latest completed runs of the Olympix Static Analysis workflow
Expand Down
104 changes: 104 additions & 0 deletions src/Facets/OmniBridgeFacet4.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 OmniBridgeFacet4 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 d785231

Please sign in to comment.