added l2AmmWrapper and l1Bridge addresses as a param

This commit is contained in:
pradyuman-verma 2022-04-11 17:45:54 +05:30
parent 5952962977
commit 595e4fb620
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
3 changed files with 15 additions and 84 deletions

View File

@ -9,6 +9,7 @@ import "./interface.sol";
contract Helpers is DSMath, Basic {
/**
* @param token The address of token to be bridged.(For USDC: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
* @param hopRouter The address of hop l1Bridge.
* @param chainId The Id of the destination chain.(For POLYGON : 137)
* @param recipient The address to recieve the token on destination chain.
* @param amount The total amount sent by user (Includes bonder fee, destination chain Tx cost).
@ -17,18 +18,19 @@ contract Helpers is DSMath, Basic {
*/
struct BridgeParams {
address token;
uint256 chainId;
address recipient;
address hopRouter;
uint256 chainId;
uint256 amount;
uint256 amountOutMin;
uint256 deadline;
}
function _sendToL2(BridgeParams memory params) internal {
IHopRouter router = _getRouter(params.token);
IHopRouter router = IHopRouter(params.hopRouter);
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, address(router), params.amount);
approve(tokenContract, params.hopRouter, params.amount);
router.sendToL2(
params.chainId,
@ -40,30 +42,4 @@ contract Helpers is DSMath, Basic {
0 // relayer fee
);
}
function _getRouter(address token_)
internal
pure
returns (IHopRouter router)
{
if (token_ == 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
//USDC l1Bridge
router = IHopRouter(0x3666f603Cc164936C1b87e207F36BEBa4AC5f18a);
else if (token_ == 0xdAC17F958D2ee523a2206206994597C13D831ec7)
//USDT l1Bridge
router = IHopRouter(0x3E4a3a4796d16c0Cd582C382691998f7c06420B6);
else if (token_ == 0x7c9f4C87d911613Fe9ca58b579f737911AAD2D43)
//WMATIC l1Bridge
router = IHopRouter(0x22B1Cbb8D98a01a3B71D034BB899775A76Eb1cc2);
else if (token_ == 0x6B175474E89094C44Da98b954EedeAC495271d0F)
//DAI l1Bridge
router = IHopRouter(0x3d4Cc8A61c7528Fd86C55cfe061a78dCBA48EDd1);
else if (token_ == 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)
//WETH l1Bridge
router = IHopRouter(0xb8901acB165ed027E32754E0FFe830802919727f);
else if (token_ == 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599)
//WBTC l1Bridge
router = IHopRouter(0xb98454270065A31D71Bf635F6F7Ee6A518dFb849);
else revert("Invalid token migration");
}
}

View File

@ -10,6 +10,7 @@ contract Helpers is DSMath, Basic {
/**
* @param token The address of token to be bridged.(For USDC: 0x7f5c764cbc14f9669b88837ca1490cca17c31607)
* @param chainId The Id of the destination chain.(For MAINNET : 1)
* @param hopRouter The address of hop l2AmmWrapper.
* @param recipient The address to recieve the token on destination chain.
* @param amount The total amount sent by user (Includes bonder fee, destination chain Tx cost).
* @param bonderFee The fee to be recieved by bonder at destination chain.
@ -20,8 +21,9 @@ contract Helpers is DSMath, Basic {
*/
struct BridgeParams {
address token;
uint256 chainId;
address recipient;
address hopRouter;
uint256 chainId;
uint256 amount;
uint256 bonderFee;
uint256 amountOutMin;
@ -31,10 +33,10 @@ contract Helpers is DSMath, Basic {
}
function _swapAndSend(BridgeParams memory params) internal {
IHopRouter router = _getRouter(params.token);
IHopRouter router = IHopRouter(params.hopRouter);
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, address(router), params.amount);
approve(tokenContract, params.hopRouter, params.amount);
router.swapAndSend(
params.chainId,
@ -47,27 +49,4 @@ contract Helpers is DSMath, Basic {
params.destinationDeadline
);
}
function _getRouter(address token_)
internal
pure
returns (IHopRouter router)
{
if (token_ == 0x7F5c764cBc14f9669B88837ca1490cCa17c31607)
//USDC l2AmmWrapper
router = IHopRouter(0x2ad09850b0CA4c7c1B33f5AcD6cBAbCaB5d6e796);
else if (token_ == 0x94b008aA00579c1307B0EF2c499aD98a8ce58e58)
//USDT l2AmmWrapper
router = IHopRouter(0x7D269D3E0d61A05a0bA976b7DBF8805bF844AF3F);
else if (token_ == 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1)
//DAI l2AmmWrapper
router = IHopRouter(0xb3C68a491608952Cb1257FC9909a537a0173b63B);
else if (token_ == 0x4200000000000000000000000000000000000006)
//WETH l2AmmWrapper
router = IHopRouter(0x86cA30bEF97fB651b8d866D45503684b90cb3312);
else if (token_ == 0x68f180fcCe6836688e9084f035309E29Bf0A2095)
//WBTC l2AmmWrapper
router = IHopRouter(0x2A11a98e2fCF4674F30934B5166645fE6CA35F56);
else revert("Invalid token migration");
}
}

View File

@ -10,6 +10,7 @@ contract Helpers is DSMath, Basic {
/**
* @param token The address of token to be bridged.(For USDC: 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174)
* @param chainId The Id of the destination chain.(For MAINNET : 1)
* @param hopRouter The address of hop l2AmmWrapper.
* @param recipient The address to recieve the token on destination chain.
* @param amount The total amount sent by user (Includes bonder fee, destination chain Tx cost).
* @param bonderFee The fee to be recieved by bonder at destination chain.
@ -20,8 +21,9 @@ contract Helpers is DSMath, Basic {
*/
struct BridgeParams {
address token;
uint256 chainId;
address hopRouter;
address recipient;
uint256 chainId;
uint256 amount;
uint256 bonderFee;
uint256 amountOutMin;
@ -31,10 +33,10 @@ contract Helpers is DSMath, Basic {
}
function _swapAndSend(BridgeParams memory params) internal {
IHopRouter router = _getRouter(params.token);
IHopRouter router = IHopRouter(params.hopRouter);
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, address(router), params.amount);
approve(tokenContract, params.hopRouter, params.amount);
router.swapAndSend(
params.chainId,
@ -47,30 +49,4 @@ contract Helpers is DSMath, Basic {
params.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");
}
}