Skip to content

Commit

Permalink
Replaced OFTv2 with OFTv1
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIryna committed Dec 15, 2022
1 parent 11be35d commit 5d11c0f
Show file tree
Hide file tree
Showing 26 changed files with 487 additions and 966 deletions.
4 changes: 4 additions & 0 deletions constants/pools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"goerli": "0xeBBEa1682C59D9cfBd0142783B47AA934cB3137d",
"bsc-testnet": "0xd336c031701debb988f9780c7b5c606b9348504d"
}
4 changes: 4 additions & 0 deletions constants/weths.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"goerli": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"bsc-testnet": "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"
}
9 changes: 9 additions & 0 deletions contracts/INativeOFT.sol
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;
}
27 changes: 18 additions & 9 deletions contracts/SwappableBridge.sol
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);
}
}
3 changes: 2 additions & 1 deletion contracts/mocks/LayerZeroEndpoint.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
pragma solidity ^0.8.0;

import "@layerzerolabs/solidity-examples/contracts/mocks/LZEndpointMock.sol";
import "@layerzerolabs/solidity-examples/contracts/token/oft/OFT.sol";
import "@layerzerolabs/solidity-examples/contracts/token/oft/extension/NativeOFT.sol";

contract LayerZeroEndpoint is LZEndpointMock {
constructor(uint16 _chainId) LZEndpointMock(_chainId) {}
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/WETH9.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
pragma solidity ^0.8.0;

contract WETH9 {
string public name = "Wrapped Ether";
Expand Down
43 changes: 0 additions & 43 deletions contracts/token/BaseOFTV2.sol

This file was deleted.

9 changes: 0 additions & 9 deletions contracts/token/INativeOFT.sol

This file was deleted.

109 changes: 0 additions & 109 deletions contracts/token/NativeOFTV2.sol

This file was deleted.

Loading

0 comments on commit 5d11c0f

Please sign in to comment.