mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add mainnet, arbitrum, polygon connectors
This commit is contained in:
parent
9cd3cec75c
commit
ff174f4040
15
contracts/arbitrum/connectors/connext/events.sol
Normal file
15
contracts/arbitrum/connectors/connext/events.sol
Normal file
|
@ -0,0 +1,15 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogXCall(
|
||||
uint32 destination,
|
||||
address to,
|
||||
address asset,
|
||||
address delegate,
|
||||
uint256 amount,
|
||||
uint256 slippage,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
48
contracts/arbitrum/connectors/connext/helpers.sol
Normal file
48
contracts/arbitrum/connectors/connext/helpers.sol
Normal file
|
@ -0,0 +1,48 @@
|
|||
//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 { IConnext } from "./interface.sol";
|
||||
|
||||
contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
* @dev Connext Diamond Address
|
||||
*/
|
||||
address internal constant connextAddr =
|
||||
0xEE9deC2712cCE65174B561151701Bf54b99C24C8;
|
||||
IConnext internal constant connext = IConnext(connextAddr);
|
||||
|
||||
/**
|
||||
* @param destination The destination domain ID.
|
||||
* @param asset The address of token to be bridged.
|
||||
* @param delegate Address that can revert or forceLocal on destination.
|
||||
* @param amount The amount to transfer.
|
||||
* @param slippage Maximum amount of slippage the user will accept in BPS.
|
||||
* @param relayerFee Relayer fee paid in origin native asset.
|
||||
* @param callData Encoded calldata to send.
|
||||
*/
|
||||
struct XCallParams {
|
||||
uint32 destination;
|
||||
address to;
|
||||
address asset;
|
||||
address delegate;
|
||||
uint256 amount;
|
||||
uint256 slippage;
|
||||
uint256 relayerFee;
|
||||
bytes callData;
|
||||
}
|
||||
|
||||
function _xcall(XCallParams memory params) internal {
|
||||
connext.xcall{ value: params.relayerFee }(
|
||||
params.destination,
|
||||
params.to,
|
||||
params.asset,
|
||||
params.delegate,
|
||||
params.amount,
|
||||
params.slippage,
|
||||
params.callData
|
||||
);
|
||||
}
|
||||
}
|
14
contracts/arbitrum/connectors/connext/interface.sol
Normal file
14
contracts/arbitrum/connectors/connext/interface.sol
Normal file
|
@ -0,0 +1,14 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IConnext {
|
||||
function xcall(
|
||||
uint32 _destination,
|
||||
address _to,
|
||||
address _asset,
|
||||
address _delegate,
|
||||
uint256 _amount,
|
||||
uint256 _slippage,
|
||||
bytes calldata _callData
|
||||
) external payable returns (bytes32);
|
||||
}
|
67
contracts/arbitrum/connectors/connext/main.sol
Normal file
67
contracts/arbitrum/connectors/connext/main.sol
Normal file
|
@ -0,0 +1,67 @@
|
|||
//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.
|
||||
* @param setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function xcall(XCallParams memory params, uint256 getId, uint256 setId)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amount = getUint(getId, params.amount);
|
||||
TokenInterface tokenContract = TokenInterface(params.asset);
|
||||
bool isNative = params.asset == ethAddr;
|
||||
|
||||
if (isNative) {
|
||||
_amount = _amount == uint256(-1) ? address(this).balance : _amount;
|
||||
params.asset = wethAddr;
|
||||
tokenContract = TokenInterface(params.asset);
|
||||
// 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);
|
||||
_xcall(params);
|
||||
|
||||
setUint(setId, _amount);
|
||||
_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
params.destination,
|
||||
params.to,
|
||||
params.asset,
|
||||
params.delegate,
|
||||
params.amount,
|
||||
params.slippage,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ConnextOptimism is ConnextResolver {
|
||||
string public constant name = "Connext-v1.0";
|
||||
}
|
15
contracts/mainnet/connectors/connext/events.sol
Normal file
15
contracts/mainnet/connectors/connext/events.sol
Normal file
|
@ -0,0 +1,15 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogXCall(
|
||||
uint32 destination,
|
||||
address to,
|
||||
address asset,
|
||||
address delegate,
|
||||
uint256 amount,
|
||||
uint256 slippage,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
48
contracts/mainnet/connectors/connext/helpers.sol
Normal file
48
contracts/mainnet/connectors/connext/helpers.sol
Normal file
|
@ -0,0 +1,48 @@
|
|||
//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 { IConnext } from "./interface.sol";
|
||||
|
||||
contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
* @dev Connext Diamond Address
|
||||
*/
|
||||
address internal constant connextAddr =
|
||||
0x8898B472C54c31894e3B9bb83cEA802a5d0e63C6;
|
||||
IConnext internal constant connext = IConnext(connextAddr);
|
||||
|
||||
/**
|
||||
* @param destination The destination domain ID.
|
||||
* @param asset The address of token to be bridged.
|
||||
* @param delegate Address that can revert or forceLocal on destination.
|
||||
* @param amount The amount to transfer.
|
||||
* @param slippage Maximum amount of slippage the user will accept in BPS.
|
||||
* @param relayerFee Relayer fee paid in origin native asset.
|
||||
* @param callData Encoded calldata to send.
|
||||
*/
|
||||
struct XCallParams {
|
||||
uint32 destination;
|
||||
address to;
|
||||
address asset;
|
||||
address delegate;
|
||||
uint256 amount;
|
||||
uint256 slippage;
|
||||
uint256 relayerFee;
|
||||
bytes callData;
|
||||
}
|
||||
|
||||
function _xcall(XCallParams memory params) internal {
|
||||
connext.xcall{ value: params.relayerFee }(
|
||||
params.destination,
|
||||
params.to,
|
||||
params.asset,
|
||||
params.delegate,
|
||||
params.amount,
|
||||
params.slippage,
|
||||
params.callData
|
||||
);
|
||||
}
|
||||
}
|
14
contracts/mainnet/connectors/connext/interface.sol
Normal file
14
contracts/mainnet/connectors/connext/interface.sol
Normal file
|
@ -0,0 +1,14 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IConnext {
|
||||
function xcall(
|
||||
uint32 _destination,
|
||||
address _to,
|
||||
address _asset,
|
||||
address _delegate,
|
||||
uint256 _amount,
|
||||
uint256 _slippage,
|
||||
bytes calldata _callData
|
||||
) external payable returns (bytes32);
|
||||
}
|
67
contracts/mainnet/connectors/connext/main.sol
Normal file
67
contracts/mainnet/connectors/connext/main.sol
Normal file
|
@ -0,0 +1,67 @@
|
|||
//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.
|
||||
* @param setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function xcall(XCallParams memory params, uint256 getId, uint256 setId)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amount = getUint(getId, params.amount);
|
||||
TokenInterface tokenContract = TokenInterface(params.asset);
|
||||
bool isNative = params.asset == ethAddr;
|
||||
|
||||
if (isNative) {
|
||||
_amount = _amount == uint256(-1) ? address(this).balance : _amount;
|
||||
params.asset = wethAddr;
|
||||
tokenContract = TokenInterface(params.asset);
|
||||
// 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);
|
||||
_xcall(params);
|
||||
|
||||
setUint(setId, _amount);
|
||||
_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
params.destination,
|
||||
params.to,
|
||||
params.asset,
|
||||
params.delegate,
|
||||
params.amount,
|
||||
params.slippage,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ConnextOptimism is ConnextResolver {
|
||||
string public constant name = "Connext-v1.0";
|
||||
}
|
15
contracts/polygon/connectors/connext/events.sol
Normal file
15
contracts/polygon/connectors/connext/events.sol
Normal file
|
@ -0,0 +1,15 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogXCall(
|
||||
uint32 destination,
|
||||
address to,
|
||||
address asset,
|
||||
address delegate,
|
||||
uint256 amount,
|
||||
uint256 slippage,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
48
contracts/polygon/connectors/connext/helpers.sol
Normal file
48
contracts/polygon/connectors/connext/helpers.sol
Normal file
|
@ -0,0 +1,48 @@
|
|||
//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 { IConnext } from "./interface.sol";
|
||||
|
||||
contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
* @dev Connext Diamond Address
|
||||
*/
|
||||
address internal constant connextAddr =
|
||||
0x11984dc4465481512eb5b777E44061C158CF2259;
|
||||
IConnext internal constant connext = IConnext(connextAddr);
|
||||
|
||||
/**
|
||||
* @param destination The destination domain ID.
|
||||
* @param asset The address of token to be bridged.
|
||||
* @param delegate Address that can revert or forceLocal on destination.
|
||||
* @param amount The amount to transfer.
|
||||
* @param slippage Maximum amount of slippage the user will accept in BPS.
|
||||
* @param relayerFee Relayer fee paid in origin native asset.
|
||||
* @param callData Encoded calldata to send.
|
||||
*/
|
||||
struct XCallParams {
|
||||
uint32 destination;
|
||||
address to;
|
||||
address asset;
|
||||
address delegate;
|
||||
uint256 amount;
|
||||
uint256 slippage;
|
||||
uint256 relayerFee;
|
||||
bytes callData;
|
||||
}
|
||||
|
||||
function _xcall(XCallParams memory params) internal {
|
||||
connext.xcall{ value: params.relayerFee }(
|
||||
params.destination,
|
||||
params.to,
|
||||
params.asset,
|
||||
params.delegate,
|
||||
params.amount,
|
||||
params.slippage,
|
||||
params.callData
|
||||
);
|
||||
}
|
||||
}
|
14
contracts/polygon/connectors/connext/interface.sol
Normal file
14
contracts/polygon/connectors/connext/interface.sol
Normal file
|
@ -0,0 +1,14 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IConnext {
|
||||
function xcall(
|
||||
uint32 _destination,
|
||||
address _to,
|
||||
address _asset,
|
||||
address _delegate,
|
||||
uint256 _amount,
|
||||
uint256 _slippage,
|
||||
bytes calldata _callData
|
||||
) external payable returns (bytes32);
|
||||
}
|
67
contracts/polygon/connectors/connext/main.sol
Normal file
67
contracts/polygon/connectors/connext/main.sol
Normal file
|
@ -0,0 +1,67 @@
|
|||
//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.
|
||||
* @param setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function xcall(XCallParams memory params, uint256 getId, uint256 setId)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amount = getUint(getId, params.amount);
|
||||
TokenInterface tokenContract = TokenInterface(params.asset);
|
||||
bool isNative = params.asset == ethAddr;
|
||||
|
||||
if (isNative) {
|
||||
_amount = _amount == uint256(-1) ? address(this).balance : _amount;
|
||||
params.asset = wethAddr;
|
||||
tokenContract = TokenInterface(params.asset);
|
||||
// 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);
|
||||
_xcall(params);
|
||||
|
||||
setUint(setId, _amount);
|
||||
_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
params.destination,
|
||||
params.to,
|
||||
params.asset,
|
||||
params.delegate,
|
||||
params.amount,
|
||||
params.slippage,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ConnextOptimism is ConnextResolver {
|
||||
string public constant name = "Connext-v1.0";
|
||||
}
|
Loading…
Reference in New Issue
Block a user