Merge pull request #286 from connext/connext-connectors

Connext connectors
This commit is contained in:
Shriya Tyagi 2023-04-24 18:17:57 +04:00 committed by GitHub
commit a3ae6fcbe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1161 additions and 0 deletions

View 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
);
}

View 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
);
}
}

View 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);
}

View 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 ConnectV2ConnextArbitrum is ConnextResolver {
string public constant name = "Connext-v1.0";
}

View 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
);
}

View 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
);
}
}

View 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);
}

View 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 ConnectV2Connext is ConnextResolver {
string public constant name = "Connext-v1.0";
}

View 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
);
}

View 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 =
0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA;
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
);
}
}

View 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);
}

View 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";
}

View 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
);
}

View 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
);
}
}

View 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);
}

View 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 == maticAddr;
if (isNative) {
_amount = _amount == uint256(-1) ? address(this).balance : _amount;
params.asset = wmaticAddr;
tokenContract = TokenInterface(params.asset);
// xcall does not take native asset, must wrap
convertMaticToWmatic(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 ConnectV2ConnextPolygon is ConnextResolver {
string public constant name = "Connext-v1.0";
}

View File

@ -0,0 +1,154 @@
import { expect } from "chai";
import hre from "hardhat";
const { ethers, waffle } = hre;
const { provider } = waffle;
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/tests/arbitrum/addresses";
import { abis } from "../../../scripts/constant/abis";
import { ConnectV2ConnextArbitrum__factory } from "../../../typechain";
import { Signer, Contract } from "ethers";
describe("Connext Connector [Arbitrum]", () => {
const connectorName = "CONNEXT-TEST-A";
let dsaWallet0: Contract;
let masterSigner: Signer;
let instaConnectorsV2: Contract;
let connector: Contract;
let usdcContract: Contract;
let signer: any;
const usdcAddr = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8";
const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const account = "0x62383739d68dd0f844103db8dfb05a7eded5bbe6";
const wallets = provider.getWallets();
const [wallet0, wallet1] = wallets;
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 82686991
}
}
]
});
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2ConnextArbitrum__factory,
signer: masterSigner,
connectors: instaConnectorsV2
});
usdcContract = await ethers.getContractAt(abis.basic.erc20, usdcAddr);
signer = await ethers.getSigner(account);
await hre.network.provider.send("hardhat_setBalance", [account, ethers.utils.parseEther("10").toHexString()]);
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [account]
});
await usdcContract.connect(signer).transfer(wallet0.address, ethers.utils.parseUnits("10000", 6));
console.log("deployed connector: ", connector.address);
});
it("Should have contracts deployed.", async () => {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!(await masterSigner.getAddress())).to.be.true;
});
describe("DSA wallet setup", () => {
it("Should build DSA v2", async () => {
dsaWallet0 = await buildDSAv2(wallet0.getAddress());
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH & USDC into DSA wallet", async () => {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
await usdcContract.connect(wallet0).transfer(dsaWallet0.address, ethers.utils.parseUnits("10", 6));
expect(await usdcContract.balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("10", 6));
});
});
describe("Main", () => {
it("should xcall with eth", async () => {
const amount = ethers.utils.parseEther("5");
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
ethAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
it("should xcall with usdc", async () => {
const amount = ethers.utils.parseUnits("5", 6);
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
usdcAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
});
});

View File

@ -0,0 +1,154 @@
import { expect } from "chai";
import hre from "hardhat";
const { ethers, waffle } = hre;
const { provider } = waffle;
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/tests/mainnet/addresses";
import { abis } from "../../../scripts/constant/abis";
import { ConnectV2ConnextMainnet__factory } from "../../../typechain";
import { Signer, Contract } from "ethers";
describe("Connext Connector [Mainnet]", () => {
const connectorName = "CONNEXT-TEST-A";
let dsaWallet0: Contract;
let masterSigner: Signer;
let instaConnectorsV2: Contract;
let connector: Contract;
let usdcContract: Contract;
let signer: any;
const usdcAddr = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const account = "0x756D64Dc5eDb56740fC617628dC832DDBCfd373c";
const wallets = provider.getWallets();
const [wallet0, wallet1] = wallets;
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 82686991
}
}
]
});
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2ConnextMainnet__factory,
signer: masterSigner,
connectors: instaConnectorsV2
});
usdcContract = await ethers.getContractAt(abis.basic.erc20, usdcAddr);
signer = await ethers.getSigner(account);
await hre.network.provider.send("hardhat_setBalance", [account, ethers.utils.parseEther("10").toHexString()]);
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [account]
});
await usdcContract.connect(signer).transfer(wallet0.address, ethers.utils.parseUnits("10000", 6));
console.log("deployed connector: ", connector.address);
});
it("Should have contracts deployed.", async () => {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!(await masterSigner.getAddress())).to.be.true;
});
describe("DSA wallet setup", () => {
it("Should build DSA v2", async () => {
dsaWallet0 = await buildDSAv2(wallet0.getAddress());
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH & USDC into DSA wallet", async () => {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
await usdcContract.connect(wallet0).transfer(dsaWallet0.address, ethers.utils.parseUnits("10", 6));
expect(await usdcContract.balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("10", 6));
});
});
describe("Main", () => {
it("should xcall with eth", async () => {
const amount = ethers.utils.parseEther("5");
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
ethAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
it("should xcall with usdc", async () => {
const amount = ethers.utils.parseUnits("5", 6);
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
usdcAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
});
});

View File

@ -0,0 +1,154 @@
import { expect } from "chai";
import hre from "hardhat";
const { ethers, waffle } = hre;
const { provider } = waffle;
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/tests/optimism/addresses";
import { abis } from "../../../scripts/constant/abis";
import { ConnectV2ConnextOptimism__factory } from "../../../typechain";
import { Signer, Contract } from "ethers";
describe("Connext Connector [Optimism]", () => {
const connectorName = "CONNEXT-TEST-A";
let dsaWallet0: Contract;
let masterSigner: Signer;
let instaConnectorsV2: Contract;
let connector: Contract;
let usdcContract: Contract;
let signer: any;
const usdcAddr = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const account = "0xebe80f029b1c02862b9e8a70a7e5317c06f62cae";
const wallets = provider.getWallets();
const [wallet0, wallet1] = wallets;
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 82686991
}
}
]
});
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2ConnextOptimism__factory,
signer: masterSigner,
connectors: instaConnectorsV2
});
usdcContract = await ethers.getContractAt(abis.basic.erc20, usdcAddr);
signer = await ethers.getSigner(account);
await hre.network.provider.send("hardhat_setBalance", [account, ethers.utils.parseEther("10").toHexString()]);
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [account]
});
await usdcContract.connect(signer).transfer(wallet0.address, ethers.utils.parseUnits("10000", 6));
console.log("deployed connector: ", connector.address);
});
it("Should have contracts deployed.", async () => {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!(await masterSigner.getAddress())).to.be.true;
});
describe("DSA wallet setup", () => {
it("Should build DSA v2", async () => {
dsaWallet0 = await buildDSAv2(wallet0.getAddress());
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH & USDC into DSA wallet", async () => {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
await usdcContract.connect(wallet0).transfer(dsaWallet0.address, ethers.utils.parseUnits("10", 6));
expect(await usdcContract.balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("10", 6));
});
});
describe("Main", () => {
it("should xcall with eth", async () => {
const amount = ethers.utils.parseEther("5");
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
ethAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
it("should xcall with usdc", async () => {
const amount = ethers.utils.parseUnits("5", 6);
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
usdcAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
});
});

View File

@ -0,0 +1,123 @@
import { expect } from "chai";
import hre from "hardhat";
const { ethers, waffle } = hre;
const { provider } = waffle;
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/tests/polygon/addresses";
import { abis } from "../../../scripts/constant/abis";
import { ConnectV2ConnextPolygon__factory } from "../../../typechain";
import { Signer, Contract } from "ethers";
describe("Connext Connector [Polygon]", () => {
const connectorName = "CONNEXT-TEST-A";
let dsaWallet0: Contract;
let masterSigner: Signer;
let instaConnectorsV2: Contract;
let connector: Contract;
let usdcContract: Contract;
let signer: any;
const usdcAddr = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
const account = "0xfa0b641678f5115ad8a8de5752016bd1359681b9";
const wallets = provider.getWallets();
const [wallet0, wallet1] = wallets;
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 82686991
}
}
]
});
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2ConnextPolygon__factory,
signer: masterSigner,
connectors: instaConnectorsV2
});
usdcContract = await ethers.getContractAt(abis.basic.erc20, usdcAddr);
signer = await ethers.getSigner(account);
await hre.network.provider.send("hardhat_setBalance", [account, ethers.utils.parseEther("10").toHexString()]);
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [account]
});
await usdcContract.connect(signer).transfer(wallet0.address, ethers.utils.parseUnits("10000", 6));
console.log("deployed connector: ", connector.address);
});
it("Should have contracts deployed.", async () => {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!(await masterSigner.getAddress())).to.be.true;
});
describe("DSA wallet setup", () => {
it("Should build DSA v2", async () => {
dsaWallet0 = await buildDSAv2(wallet0.getAddress());
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH & USDC into DSA wallet", async () => {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
await usdcContract.connect(wallet0).transfer(dsaWallet0.address, ethers.utils.parseUnits("10", 6));
expect(await usdcContract.balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("10", 6));
});
});
describe("Main", () => {
it("should xcall with usdc", async () => {
const amount = ethers.utils.parseUnits("5", 6);
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const xcallParams: any = [
domainId,
wallet1.address,
usdcAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
});
});