added hop arbitrum

This commit is contained in:
pradyuman-verma 2022-04-11 17:40:07 +05:30
parent 227004ab79
commit 5952962977
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
4 changed files with 168 additions and 0 deletions

View File

@ -0,0 +1,17 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract Events {
event LogBridge(
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,52 @@
//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: 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8)
* @param hopRouter The address of hop l2AmmWrapper.
* @param chainId The Id of the destination chain.(For MAINNET : 1)
* @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.
* @param amountOutMin minimum amount of token out for swap
* @param deadline The deadline for the transaction (Recommended - Date.now() + 604800 (1 week))
* @param destinationAmountOutMin minimum amount of token out for bridge, zero for L1 bridging
* @param destinationDeadline The deadline for the transaction (Recommended - Date.now() + 604800 (1 week)), zero for L1 bridging
*/
struct BridgeParams {
address token;
address recipient;
address hopRouter;
uint256 chainId;
uint256 amount;
uint256 bonderFee;
uint256 amountOutMin;
uint256 deadline;
uint256 destinationAmountOutMin;
uint256 destinationDeadline;
}
function _swapAndSend(BridgeParams memory params) internal {
IHopRouter router = IHopRouter(params.hopRouter);
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, params.hopRouter, params.amount);
router.swapAndSend(
params.chainId,
params.recipient,
params.amount,
params.bonderFee,
params.amountOutMin,
params.deadline,
params.destinationAmountOutMin,
params.destinationDeadline
);
}
}

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,82 @@
//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 bridgeToL1 bool to check which layer to migrate to
* @param getId ID to retrieve amount from last spell.
*/
function bridge(
BridgeParams memory params,
bool bridgeToL1,
uint256 getId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
if (bridgeToL1) {
require(
params.destinationAmountOutMin == 0,
"destinationAmountOutMin != 0, sending to L1"
);
require(
params.destinationDeadline == 0,
"destinationDeadline != 0, sending to L1"
);
}
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;
}
_swapAndSend(params);
_eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
params.token,
params.chainId,
params.recipient,
params.amount,
params.bonderFee,
params.amountOutMin,
params.deadline,
params.destinationAmountOutMin,
params.destinationDeadline,
getId
);
}
}
contract ConnectV2HopArbitrum is Resolver {
string public constant name = "Hop-v1.0";
}