mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
added hop mainnet
This commit is contained in:
parent
533fee6eba
commit
ca34079520
14
contracts/mainnet/connectors/hop/events.sol
Normal file
14
contracts/mainnet/connectors/hop/events.sol
Normal file
|
@ -0,0 +1,14 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogBridge(
|
||||
address token,
|
||||
uint256 chainId,
|
||||
address recipient,
|
||||
uint256 amount,
|
||||
uint256 amountOutMin,
|
||||
uint256 deadline,
|
||||
uint256 getId
|
||||
);
|
||||
}
|
69
contracts/mainnet/connectors/hop/helpers.sol
Normal file
69
contracts/mainnet/connectors/hop/helpers.sol
Normal file
|
@ -0,0 +1,69 @@
|
|||
//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 {
|
||||
/**
|
||||
* @param token The address of token to be bridged.(For USDC: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
|
||||
* @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).
|
||||
* @param amountOutMin minimum amount of token out for swap
|
||||
* @param deadline The deadline for the transaction (Recommended - Date.now() + 604800 (1 week))
|
||||
*/
|
||||
struct BridgeParams {
|
||||
address token;
|
||||
uint256 chainId;
|
||||
address recipient;
|
||||
uint256 amount;
|
||||
uint256 amountOutMin;
|
||||
uint256 deadline;
|
||||
}
|
||||
|
||||
function _sendToL2(BridgeParams memory params) internal {
|
||||
IHopRouter router = _getRouter(params.token);
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(params.token);
|
||||
approve(tokenContract, address(router), params.amount);
|
||||
|
||||
router.sendToL2(
|
||||
params.chainId,
|
||||
params.recipient,
|
||||
params.amount,
|
||||
params.amountOutMin,
|
||||
params.deadline,
|
||||
address(0), // relayer address
|
||||
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");
|
||||
}
|
||||
}
|
16
contracts/mainnet/connectors/hop/interface.sol
Normal file
16
contracts/mainnet/connectors/hop/interface.sol
Normal file
|
@ -0,0 +1,16 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
||||
interface IHopRouter {
|
||||
function sendToL2(
|
||||
uint256 chainId,
|
||||
address recipient,
|
||||
uint256 amount,
|
||||
uint256 amountOutMin,
|
||||
uint256 deadline,
|
||||
address relayer,
|
||||
uint256 relayerFee
|
||||
) external;
|
||||
}
|
63
contracts/mainnet/connectors/hop/main.sol
Normal file
63
contracts/mainnet/connectors/hop/main.sol
Normal file
|
@ -0,0 +1,63 @@
|
|||
//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 {
|
||||
/**
|
||||
* @dev Bridge Token.
|
||||
* @notice Bridge Token on HOP.
|
||||
* @param params BridgeParams struct for bridging
|
||||
* @param getId ID to retrieve amount from last spell.
|
||||
*/
|
||||
function bridge(BridgeParams memory params, uint256 getId)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
params.amount = getUint(getId, params.amount);
|
||||
|
||||
bool isEth = params.token == ethAddr;
|
||||
params.token = params.token == ethAddr ? wethAddr : params.token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(params.token);
|
||||
|
||||
if (isEth) {
|
||||
params.amount = params.amount == uint256(-1)
|
||||
? address(this).balance
|
||||
: params.amount;
|
||||
convertEthToWeth(isEth, tokenContract, params.amount);
|
||||
} else {
|
||||
params.amount = params.amount == uint256(-1)
|
||||
? tokenContract.balanceOf(address(this))
|
||||
: params.amount;
|
||||
}
|
||||
|
||||
_sendToL2(params);
|
||||
|
||||
_eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
params.token,
|
||||
params.chainId,
|
||||
params.recipient,
|
||||
params.amount,
|
||||
params.amountOutMin,
|
||||
params.deadline,
|
||||
getId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2Hop is Resolver {
|
||||
string public constant name = "Hop-v1.0";
|
||||
}
|
Loading…
Reference in New Issue
Block a user