Added HOP connector: polygon

This commit is contained in:
pradyuman-verma 2022-04-04 00:18:53 +05:30
parent 91e0ba0031
commit 243326c7b2
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
4 changed files with 253 additions and 0 deletions

View File

@ -0,0 +1,30 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract Events {
event LogSendToL1(
address token,
uint256 chainId,
address recipient,
uint256 amount,
uint256 bonderFee,
uint256 amountOutMin,
uint256 deadline,
uint256 destinationAmountOutMin,
uint256 destinationDeadline,
uint256 getId
);
event LogSendToL2(
address token,
uint256 chainId,
address recipient,
uint256 amount,
uint256 bonderFee,
uint256 amountOutMin,
uint256 deadline,
uint256 destinationAmountOutMin,
uint256 destinationDeadline,
uint256 getId
);
}

View File

@ -0,0 +1,63 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import { TokenInterface } from "../../common/interfaces.sol";
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import "./interface.sol";
contract Helpers is DSMath, Basic {
function _swapAndSend(
address token,
uint256 chainId,
address recipient,
uint256 amount,
uint256 bonderFee,
uint256 amountOutMin,
uint256 deadline,
uint256 destinationAmountOutMin,
uint256 destinationDeadline
) internal {
IHopRouter router = _getRouter(token);
TokenInterface tokenContract = TokenInterface(token);
approve(tokenContract, address(router), amount);
router.swapAndSend(
chainId,
recipient,
amount,
bonderFee,
amountOutMin,
deadline,
destinationAmountOutMin,
destinationDeadline
);
}
function _getRouter(address token_)
internal
pure
returns (IHopRouter router)
{
if (token_ == 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174)
//USDC l2AmmWrapper
router = IHopRouter(0x76b22b8C1079A44F1211D867D68b1eda76a635A7);
else if (token_ == 0xc2132D05D31c914a87C6611C10748AEb04B58e8F)
//USDT l2AmmWrapper
router = IHopRouter(0x8741Ba6225A6BF91f9D73531A98A89807857a2B3);
else if (token_ == 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270)
//WMATIC l2AmmWrapper
router = IHopRouter(0x884d1Aa15F9957E1aEAA86a82a72e49Bc2bfCbe3);
else if (token_ == 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063)
//DAI l2AmmWrapper
router = IHopRouter(0x28529fec439cfF6d7D1D5917e956dEE62Cd3BE5c);
else if (token_ == 0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619)
//WETH l2AmmWrapper
router = IHopRouter(0xc315239cFb05F1E130E7E28E603CEa4C014c57f0);
else if (token_ == 0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6)
//WBTC l2AmmWrapper
router = IHopRouter(0xCd1d7AEfA8055e020db0d0e98bbF3FeD1A16aad6);
else revert("Invalid token migration");
}
}

View File

@ -0,0 +1,17 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import { TokenInterface } from "../../common/interfaces.sol";
interface IHopRouter {
function swapAndSend(
uint256 chainId,
address recipient,
uint256 amount,
uint256 bonderFee,
uint256 amountOutMin,
uint256 deadline,
uint256 destinationAmountOutMin,
uint256 destinationDeadline
) external;
}

View File

@ -0,0 +1,143 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title Hop.
* @dev Cross chain Bridge.
*/
import { TokenInterface, MemoryInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import "./interface.sol";
import "./helpers.sol";
import "./events.sol";
abstract contract Resolver is Helpers {
function sendToL1(
address token,
uint256 chainId,
address recipientOnL1,
uint256 amount,
uint256 bonderFee,
uint256 amountOutMin,
uint256 deadline,
uint256 destinationAmountOutMin,
uint256 destinationDeadline,
uint256 getId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(getId, amount);
bool isMatic = token == maticAddr;
address _token = isMatic ? wmaticAddr : token;
TokenInterface tokenContract = TokenInterface(_token);
if (isMatic) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
convertMaticToWmatic(isMatic, tokenContract, _amt);
} else {
_amt = _amt == uint256(-1)
? tokenContract.balanceOf(address(this))
: _amt;
}
require(
destinationAmountOutMin == 0,
"destinationAmountOutMin != 0, sending to L1"
);
require(
destinationDeadline == 0,
"destinationDeadline != 0, sending to L1"
);
_swapAndSend(
_token,
chainId,
recipientOnL1,
_amt,
bonderFee,
amountOutMin,
deadline,
destinationAmountOutMin,
destinationDeadline
);
_eventName = "LogSendToL1(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
_token,
chainId,
recipientOnL1,
_amt,
bonderFee,
amountOutMin,
deadline,
destinationAmountOutMin,
destinationDeadline,
getId
);
}
function sendToL2(
address token,
uint256 chainId,
address recipientOnL2,
uint256 amount,
uint256 bonderFee,
uint256 amountOutMin,
uint256 deadline,
uint256 destinationAmountOutMin,
uint256 destinationDeadline,
uint256 getId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(getId, amount);
bool isMatic = token == maticAddr;
address _token = isMatic ? wmaticAddr : token;
TokenInterface tokenContract = TokenInterface(_token);
if (isMatic) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
convertMaticToWmatic(isMatic, tokenContract, _amt);
} else {
_amt = _amt == uint256(-1)
? tokenContract.balanceOf(address(this))
: _amt;
}
_swapAndSend(
_token,
chainId,
recipientOnL2,
_amt,
bonderFee,
amountOutMin,
deadline,
destinationAmountOutMin,
destinationDeadline
);
_eventName = "LogSendToL2(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
_token,
chainId,
recipientOnL2,
_amt,
bonderFee,
amountOutMin,
deadline,
destinationAmountOutMin,
destinationDeadline,
getId
);
}
}