dsa-connectors/contracts/optimism/connectors/connext/main.sol

67 lines
1.7 KiB
Solidity
Raw Normal View History

2023-03-13 09:01:00 +00:00
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title Connext.
* @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 ConnextResolver is Helpers {
/**
* @dev Call xcall on Connext.
* @notice Call xcall on Connext.
* @param params XCallParams struct.
* @param getId ID to retrieve amount from last spell.
2023-03-22 01:55:54 +00:00
* @param setId ID stores the amount of tokens deposited.
2023-03-13 09:01:00 +00:00
*/
2023-03-22 01:55:54 +00:00
function xcall(XCallParams memory params, uint256 getId, uint256 setId)
2023-03-13 09:01:00 +00:00
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2023-03-22 01:55:54 +00:00
uint256 _amount = getUint(getId, params.amount);
2023-03-13 09:01:00 +00:00
TokenInterface tokenContract = TokenInterface(params.asset);
bool isNative = params.asset == ethAddr;
2023-03-22 01:55:54 +00:00
if (isNative) {
_amount = _amount == uint256(-1) ? sub(address(this).balance, params.relayerFee) : _amount;
// xcall does not take native asset, must wrap
convertEthToWeth(true, tokenContract, _amount);
} else {
_amount = _amount == uint256(-1) ? tokenContract.balanceOf(address(this)) : _amount;
}
params.amount = _amount;
approve(tokenContract, connextAddr, _amount);
2023-03-13 09:01:00 +00:00
_xcall(params);
2023-03-22 01:55:54 +00:00
setUint(setId, _amount);
_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)";
2023-03-13 09:01:00 +00:00
_eventParam = abi.encode(
params.destination,
params.to,
2023-03-13 09:02:29 +00:00
params.asset,
2023-03-13 09:01:00 +00:00
params.delegate,
params.amount,
params.slippage,
2023-03-22 01:55:54 +00:00
getId,
setId
2023-03-13 09:01:00 +00:00
);
}
}
contract ConnectV2ConnextOptimism is ConnextResolver {
string public constant name = "Connext-v1.0";
2023-03-13 09:02:29 +00:00
}