forked from LayerZero-Labs/mainnet-testnet-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0xIryna
committed
Dec 15, 2022
1 parent
11be35d
commit 5d11c0f
Showing
26 changed files
with
487 additions
and
966 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"goerli": "0xeBBEa1682C59D9cfBd0142783B47AA934cB3137d", | ||
"bsc-testnet": "0xd336c031701debb988f9780c7b5c606b9348504d" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"goerli": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", | ||
"bsc-testnet": "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "@layerzerolabs/solidity-examples/contracts/token/oft/IOFTCore.sol"; | ||
|
||
interface INativeOFT is IOFTCore { | ||
function deposit() external payable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.10; | ||
pragma solidity ^0.8.0; | ||
|
||
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; | ||
import "@layerzerolabs/solidity-examples/contracts/token/oft/v2/ICommonOFT.sol"; | ||
import "@layerzerolabs/solidity-examples/contracts/token/oft/v2/IOFTV2.sol"; | ||
import "@layerzerolabs/solidity-examples/contracts/token/oft/IOFTCore.sol"; | ||
import "./INativeOFT.sol"; | ||
|
||
contract SwappableBridge { | ||
IOFTV2 public oft; | ||
IOFTCore public oft; | ||
INativeOFT public nativeOft; | ||
IUniswapV2Router02 public uniswapRouter; | ||
|
||
constructor(address _oft, address _uniswapRouter) { | ||
constructor(address _oft, address _nativeOft, address _uniswapRouter) { | ||
require(_oft != address(0), "SwappableBridge: invalid OFT address"); | ||
require(_nativeOft != address(0), "SwappableBridge: invalid Native OFT address"); | ||
require(_uniswapRouter != address(0), "SwappableBridge: invalid Uniswap Router address"); | ||
|
||
oft = IOFTV2(_oft); | ||
oft = IOFTCore(_oft); | ||
nativeOft = INativeOFT(_nativeOft); | ||
uniswapRouter = IUniswapV2Router02(_uniswapRouter); | ||
} | ||
|
||
function swapAndBridge(uint amountIn, uint amountOutMin, uint16 dstChainId, ICommonOFT.LzCallParams calldata callParams) external payable { | ||
function swapAndBridge(uint amountIn, uint amountOutMin, uint16 dstChainId, address payable refundAddress, address zroPaymentAddress, bytes calldata adapterParams) external payable { | ||
require(msg.value > amountIn, "SwappableBridge: not enough value sent"); | ||
|
||
address[] memory path = new address[](2); | ||
path[0] = uniswapRouter.WETH(); | ||
path[1] = address(oft); | ||
|
||
uint[] memory amounts = uniswapRouter.swapExactETHForTokens{value: amountIn}(amountOutMin, path, address(this), block.timestamp); | ||
bytes32 bytes32Address = bytes32(uint(uint160(msg.sender))); | ||
oft.sendFrom{value: msg.value - amountIn}(address(this), dstChainId, bytes32Address, amounts[1], callParams); | ||
oft.sendFrom{value: msg.value - amountIn}(address(this), dstChainId, abi.encodePacked(msg.sender), amounts[1], refundAddress, zroPaymentAddress, adapterParams); | ||
} | ||
|
||
function bridge(uint amountIn, uint16 dstChainId, address payable refundAddress, address zroPaymentAddress, bytes calldata adapterParams) external payable { | ||
require(msg.value > amountIn, "SwappableBridge: not enough value sent"); | ||
|
||
nativeOft.deposit{value: amountIn}(); | ||
nativeOft.sendFrom{value: msg.value - amountIn}(address(this), dstChainId, abi.encodePacked(msg.sender), amountIn, refundAddress, zroPaymentAddress, adapterParams); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.