dsa-connectors/contracts/polygon/connectors/hop/main.sol

80 lines
1.9 KiB
Solidity
Raw Normal View History

2022-04-03 18:48:53 +00:00
//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 {
2022-04-03 18:56:27 +00:00
/**
* @dev Bridge Token.
* @notice Bridge Token on HOP.
2022-04-03 19:11:30 +00:00
* @param params BridgeParams struct for bridging
* @param getId ID to retrieve amount from last spell.
2022-04-03 18:56:27 +00:00
*/
function bridge(BridgeParams memory params, uint256 getId)
2022-04-03 18:48:53 +00:00
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2022-04-16 17:24:24 +00:00
if (params.targetChainId == 1) {
2022-04-03 19:11:30 +00:00
require(
params.destinationAmountOutMin == 0,
"destinationAmountOutMin != 0, sending to L1"
);
require(
params.destinationDeadline == 0,
"destinationDeadline != 0, sending to L1"
);
2022-04-03 18:48:53 +00:00
}
2022-04-03 19:11:30 +00:00
params.amount = getUint(getId, params.amount);
2022-05-07 15:03:57 +00:00
TokenInterface tokenContract = TokenInterface(params.token);
2022-04-03 18:48:53 +00:00
2022-05-10 12:53:57 +00:00
if (params.token == wmaticAddr) {
convertWmaticToMatic(true, tokenContract, params.amount);
2022-05-07 15:03:57 +00:00
params.token = maticAddr;
}
2022-04-03 18:48:53 +00:00
2022-05-07 15:03:57 +00:00
bool isNative = params.token == maticAddr;
2022-04-03 18:48:53 +00:00
2022-05-07 15:03:57 +00:00
if (isNative) {
2022-04-03 19:11:30 +00:00
params.amount = params.amount == uint256(-1)
? address(this).balance
: params.amount;
2022-04-03 18:48:53 +00:00
} else {
2022-04-03 19:11:30 +00:00
params.amount = params.amount == uint256(-1)
2022-04-03 18:48:53 +00:00
? tokenContract.balanceOf(address(this))
2022-04-03 19:11:30 +00:00
: params.amount;
2022-04-03 18:48:53 +00:00
}
2022-05-07 15:03:57 +00:00
_swapAndSend(params, isNative);
2022-04-03 18:48:53 +00:00
2022-05-10 12:53:57 +00:00
_eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
2022-04-03 18:48:53 +00:00
_eventParam = abi.encode(
2022-04-03 19:11:30 +00:00
params.token,
2022-04-16 17:24:24 +00:00
params.targetChainId,
2022-04-03 19:11:30 +00:00
params.recipient,
params.amount,
params.bonderFee,
2022-04-16 17:24:24 +00:00
params.sourceAmountOutMin,
params.sourceDeadline,
2022-04-03 19:11:30 +00:00
params.destinationAmountOutMin,
params.destinationDeadline,
2022-04-03 18:48:53 +00:00
getId
);
}
}
2022-04-03 18:49:45 +00:00
contract ConnectV2HopPolygon is Resolver {
string public constant name = "Hop-v1.0";
}