From 0406bcbf819c6a785c69bb6582babf69090c2402 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:00:37 +0700 Subject: [PATCH 01/17] add: events and interface --- .../optimism/connectors/connext/events.sol | 14 +++++++++ .../optimism/connectors/connext/interface.sol | 30 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 contracts/optimism/connectors/connext/events.sol create mode 100644 contracts/optimism/connectors/connext/interface.sol diff --git a/contracts/optimism/connectors/connext/events.sol b/contracts/optimism/connectors/connext/events.sol new file mode 100644 index 00000000..2a9da14b --- /dev/null +++ b/contracts/optimism/connectors/connext/events.sol @@ -0,0 +1,14 @@ +//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 + ); +} \ No newline at end of file diff --git a/contracts/optimism/connectors/connext/interface.sol b/contracts/optimism/connectors/connext/interface.sol new file mode 100644 index 00000000..4c8886bd --- /dev/null +++ b/contracts/optimism/connectors/connext/interface.sol @@ -0,0 +1,30 @@ +//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); +} + +interface IInstaReceiver { + function withdraw( + address _asset, + uint256 _amount + ) external returns (bytes memory); + + function xReceive( + bytes32 _transferId, + uint256 _amount, + address _asset, + address _originSender, + uint32 _origin, + bytes memory _callData + ) external returns (bytes memory); +} \ No newline at end of file From a53b4196021ae93cb5922492b7004e2fe9b1800f Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:00:54 +0700 Subject: [PATCH 02/17] add: helper --- .../optimism/connectors/connext/helpers.sol | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 contracts/optimism/connectors/connext/helpers.sol diff --git a/contracts/optimism/connectors/connext/helpers.sol b/contracts/optimism/connectors/connext/helpers.sol new file mode 100644 index 00000000..bc91cc21 --- /dev/null +++ b/contracts/optimism/connectors/connext/helpers.sol @@ -0,0 +1,80 @@ +//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"; +import { IInstaReceiver } from "./interface.sol"; + +contract Helpers is DSMath, Basic { + /** + * @dev Connext Diamond Address + */ + address internal constant connextAddr = 0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA; + IConnext internal constant connext = IConnext(connextAddr); + + /** + * @dev InstaReceiver Address + */ + address internal constant instaReceiverAddr = 0x0000000000000000000000000000000000000000; // TODO: Add InstaReceiver address + IInstaReceiver internal constant instaReceiver = IInstaReceiver(instaReceiverAddr); + + /** + * @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 { + uint256 nativeTokenAmt; + bool isNative = params.asset == ethAddr; + + if (isNative) { + params.amount = params.amount == uint256(-1) + ? address(this).balance + : params.amount; + + // xcall does not take native asset, must wrap + TokenInterface tokenContract = TokenInterface(wethAddr); + convertEthToWeth(true, tokenContract, params.amount); + + nativeTokenAmt = params.amount; + } else { + TokenInterface tokenContract = TokenInterface(params.asset); + params.amount = params.amount == uint256(-1) + ? tokenContract.balanceOf(address(this)) + : params.amount; + + if (params.amount > 0) { + tokenContract.approve(connextAddr, params.amount); + } + + nativeTokenAmt = 0; + } + + connext.xcall{ value: params.relayerFee + nativeTokenAmt }( + params.destination, + params.to, + params.asset, + params.delegate, + params.amount, + params.slippage, + params.callData + ); + } +} \ No newline at end of file From 9c56f978ef9f4e068ae9e330ba653c3306df2344 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:01:00 +0700 Subject: [PATCH 03/17] add: main --- .../optimism/connectors/connext/main.sol | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 contracts/optimism/connectors/connext/main.sol diff --git a/contracts/optimism/connectors/connext/main.sol b/contracts/optimism/connectors/connext/main.sol new file mode 100644 index 00000000..b1155002 --- /dev/null +++ b/contracts/optimism/connectors/connext/main.sol @@ -0,0 +1,101 @@ +//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. + + */ + + function xcall(XCallParams memory params, uint256 getId) + + external + + payable + + returns (string memory _eventName, bytes memory _eventParam) + + { + + params.amount = getUint(getId, params.amount); + + TokenInterface tokenContract = TokenInterface(params.asset); + + + + + _xcall(params); + + + + + _eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256)"; + + _eventParam = abi.encode( + + params.destination, + + params.to, + + params.asset, + + params.delegate, + + params.amount, + + params.slippage, + + getId + + ); + + } + +} + + + + +contract ConnectV2ConnextOptimism is ConnextResolver { + + string public constant name = "Connext-v1.0"; + +} \ No newline at end of file From 6e7477bd1b1379d66a811f9f603e5ff6c1d4e099 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:01:07 +0700 Subject: [PATCH 04/17] add: connext test --- test/optimism/connext/connext.test.ts | 127 ++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 test/optimism/connext/connext.test.ts diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts new file mode 100644 index 00000000..afd7f20b --- /dev/null +++ b/test/optimism/connext/connext.test.ts @@ -0,0 +1,127 @@ +import { expect } from "chai"; +import hre from "hardhat"; +const { ethers } = hre; + +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 { addLiquidity } from "../../../scripts/tests/addLiquidity"; +import { addresses } from "../../../scripts/tests/polygon/addresses"; +import { abis } from "../../../scripts/constant/abis"; +import { ConnectV2ConnextOptimism__factory } from "../../../typechain"; +import { Signer, Contract } from "ethers"; + +describe("Connext Connector [Optimism]", function () { + const connectorName = "CONNEXT-TEST-A"; + + let wallet0: Signer, wallet1:Signer; + let dsaWallet0: Contract; + let masterSigner: Signer; + let instaConnectorsV2: Contract; + let connector: Contract; + + const connextAddr = "0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA"; + const usdcAddr = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607"; + const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + const wethAddr = "0x4200000000000000000000000000000000000006"; + + const usdc = new ethers.Contract(usdcAddr, abis.basic.erc20); + const weth = new ethers.Contract(wethAddr, abis.basic.erc20); + + before(async () => { + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + // @ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + blockNumber: 12230000 + } + } + ] + }); + + [wallet0, wallet1] = await ethers.getSigners(); + masterSigner = await getMasterSigner(); + + instaConnectorsV2 = await ethers.getContractAt( + abis.core.connectorsV2, + addresses.core.connectorsV2 + ); + connector = await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV2ConnextOptimism__factory, + signer: masterSigner, + connectors: instaConnectorsV2 + }); + + console.log("Connector address", connector.address); + }); + + it("Should have contracts deployed.", async function () { + expect(!!instaConnectorsV2.address).to.be.true; + expect(!!connector.address).to.be.true; + expect(!!(await masterSigner.getAddress())).to.be.true; + }); + + describe("DSA wallet setup", function () { + it("Should build DSA v2", async function () { + dsaWallet0 = await buildDSAv2(wallet0.getAddress()); + expect(!!dsaWallet0.address).to.be.true; + }); + + it("Deposit ETH & USDC into DSA wallet", async function() { + 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 addLiquidity( + // "usdc", + // dsaWallet0.address, + // ethers.utils.parseEther("100000") + // ); + }); + }); + + describe("Main", function () { + + it("should xcall with eth", async function () { + const amount = ethers.utils.parseEther("10"); + const domainId = 6648936; + const slippage = 10000; + const relayerFee = ethers.utils.parseEther("1");; + const getId = 0; + const callData = "0x"; + + const wallet0Address = await wallet0.getAddress(); + + const xcallParams: any = [ + domainId, + wallet0Address, + ethAddr, + wallet0Address, + amount, + slippage, + relayerFee, + callData + ]; + + const spells = [ + { + connector: connectorName, + method: "xcall", + args: [xcallParams, getId] + } + ]; + + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0Address); + const receipt = await tx.wait(); + }); + }); +}); \ No newline at end of file From 0ee4b2af830da227c7e72350c427b80c5ab564e1 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:02:29 +0700 Subject: [PATCH 05/17] prettier --- .../optimism/connectors/connext/events.sol | 14 ++--- .../optimism/connectors/connext/helpers.sol | 43 +++++++------- .../optimism/connectors/connext/interface.sol | 43 +++++++------- .../optimism/connectors/connext/main.sol | 57 +------------------ 4 files changed, 53 insertions(+), 104 deletions(-) diff --git a/contracts/optimism/connectors/connext/events.sol b/contracts/optimism/connectors/connext/events.sol index 2a9da14b..a1d7e441 100644 --- a/contracts/optimism/connectors/connext/events.sol +++ b/contracts/optimism/connectors/connext/events.sol @@ -3,12 +3,12 @@ pragma solidity ^0.7.0; contract Events { event LogXCall( - uint32 destination, - address to, - address asset, - address delegate, - uint256 amount, - uint256 slippage, + uint32 destination, + address to, + address asset, + address delegate, + uint256 amount, + uint256 slippage, uint256 getId ); -} \ No newline at end of file +} diff --git a/contracts/optimism/connectors/connext/helpers.sol b/contracts/optimism/connectors/connext/helpers.sol index bc91cc21..5adddd7a 100644 --- a/contracts/optimism/connectors/connext/helpers.sol +++ b/contracts/optimism/connectors/connext/helpers.sol @@ -8,17 +8,20 @@ import { IConnext } from "./interface.sol"; import { IInstaReceiver } from "./interface.sol"; contract Helpers is DSMath, Basic { - /** - * @dev Connext Diamond Address - */ - address internal constant connextAddr = 0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA; + /** + * @dev Connext Diamond Address + */ + address internal constant connextAddr = + 0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA; IConnext internal constant connext = IConnext(connextAddr); - /** - * @dev InstaReceiver Address - */ - address internal constant instaReceiverAddr = 0x0000000000000000000000000000000000000000; // TODO: Add InstaReceiver address - IInstaReceiver internal constant instaReceiver = IInstaReceiver(instaReceiverAddr); + /** + * @dev InstaReceiver Address + */ + address internal constant instaReceiverAddr = + 0x0000000000000000000000000000000000000000; // TODO: Add InstaReceiver address + IInstaReceiver internal constant instaReceiver = + IInstaReceiver(instaReceiverAddr); /** * @param destination The destination domain ID. @@ -30,14 +33,14 @@ contract Helpers is DSMath, Basic { * @param callData Encoded calldata to send. */ struct XCallParams { - uint32 destination; - address to; - address asset; - address delegate; - uint256 amount; - uint256 slippage; - uint256 relayerFee; - bytes callData; + uint32 destination; + address to; + address asset; + address delegate; + uint256 amount; + uint256 slippage; + uint256 relayerFee; + bytes callData; } function _xcall(XCallParams memory params) internal { @@ -49,7 +52,7 @@ contract Helpers is DSMath, Basic { ? address(this).balance : params.amount; - // xcall does not take native asset, must wrap + // xcall does not take native asset, must wrap TokenInterface tokenContract = TokenInterface(wethAddr); convertEthToWeth(true, tokenContract, params.amount); @@ -70,11 +73,11 @@ contract Helpers is DSMath, Basic { connext.xcall{ value: params.relayerFee + nativeTokenAmt }( params.destination, params.to, - params.asset, + params.asset, params.delegate, params.amount, params.slippage, params.callData ); } -} \ No newline at end of file +} diff --git a/contracts/optimism/connectors/connext/interface.sol b/contracts/optimism/connectors/connext/interface.sol index 4c8886bd..d3597982 100644 --- a/contracts/optimism/connectors/connext/interface.sol +++ b/contracts/optimism/connectors/connext/interface.sol @@ -2,29 +2,28 @@ 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); + function xcall( + uint32 _destination, + address _to, + address _asset, + address _delegate, + uint256 _amount, + uint256 _slippage, + bytes calldata _callData + ) external payable returns (bytes32); } interface IInstaReceiver { - function withdraw( - address _asset, - uint256 _amount - ) external returns (bytes memory); + function withdraw(address _asset, uint256 _amount) + external + returns (bytes memory); - function xReceive( - bytes32 _transferId, - uint256 _amount, - address _asset, - address _originSender, - uint32 _origin, - bytes memory _callData - ) external returns (bytes memory); -} \ No newline at end of file + function xReceive( + bytes32 _transferId, + uint256 _amount, + address _asset, + address _originSender, + uint32 _origin, + bytes memory _callData + ) external returns (bytes memory); +} diff --git a/contracts/optimism/connectors/connext/main.sol b/contracts/optimism/connectors/connext/main.sol index b1155002..64b14aca 100644 --- a/contracts/optimism/connectors/connext/main.sol +++ b/contracts/optimism/connectors/connext/main.sol @@ -1,101 +1,48 @@ //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. - */ - function xcall(XCallParams memory params, uint256 getId) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - params.amount = getUint(getId, params.amount); - TokenInterface tokenContract = TokenInterface(params.asset); - - - - _xcall(params); - - - - _eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256)"; - _eventParam = abi.encode( - params.destination, - params.to, - - params.asset, - + params.asset, params.delegate, - params.amount, - params.slippage, - getId - ); - } - } - - - contract ConnectV2ConnextOptimism is ConnextResolver { - string public constant name = "Connext-v1.0"; - -} \ No newline at end of file +} From 1fc08d8ed113fdbde8b1b7b61506b340123c46c2 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:08:12 +0700 Subject: [PATCH 06/17] fix: test ps: review --- test/optimism/connext/connext.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts index afd7f20b..3e96c81d 100644 --- a/test/optimism/connext/connext.test.ts +++ b/test/optimism/connext/connext.test.ts @@ -7,7 +7,7 @@ import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; import { encodeSpells } from "../../../scripts/tests/encodeSpells"; import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { addLiquidity } from "../../../scripts/tests/addLiquidity"; -import { addresses } from "../../../scripts/tests/polygon/addresses"; +import { addresses } from "../../../scripts/tests/optimism/addresses"; import { abis } from "../../../scripts/constant/abis"; import { ConnectV2ConnextOptimism__factory } from "../../../typechain"; import { Signer, Contract } from "ethers"; From cb32c4faf32d6a79f6a75524b3372e5db3a12b15 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Mon, 13 Mar 2023 16:24:10 +0700 Subject: [PATCH 07/17] update test --- test/optimism/connext/connext.test.ts | 42 +++++++++++---------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts index 3e96c81d..5671bd93 100644 --- a/test/optimism/connext/connext.test.ts +++ b/test/optimism/connext/connext.test.ts @@ -1,12 +1,12 @@ import { expect } from "chai"; import hre from "hardhat"; -const { ethers } = hre; +const { ethers, waffle } = hre; +const { provider, deployContract } = 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 { addLiquidity } from "../../../scripts/tests/addLiquidity"; import { addresses } from "../../../scripts/tests/optimism/addresses"; import { abis } from "../../../scripts/constant/abis"; import { ConnectV2ConnextOptimism__factory } from "../../../typechain"; @@ -15,7 +15,6 @@ import { Signer, Contract } from "ethers"; describe("Connext Connector [Optimism]", function () { const connectorName = "CONNEXT-TEST-A"; - let wallet0: Signer, wallet1:Signer; let dsaWallet0: Contract; let masterSigner: Signer; let instaConnectorsV2: Contract; @@ -26,8 +25,11 @@ describe("Connext Connector [Optimism]", function () { const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; const wethAddr = "0x4200000000000000000000000000000000000006"; - const usdc = new ethers.Contract(usdcAddr, abis.basic.erc20); - const weth = new ethers.Contract(wethAddr, abis.basic.erc20); + const wallets = provider.getWallets(); + const [wallet0, wallet1] = wallets; + + // const usdc = new ethers.Contract(usdcAddr, abis.basic.erc20); + // const weth = new ethers.Contract(wethAddr, abis.basic.erc20); before(async () => { await hre.network.provider.request({ @@ -37,19 +39,14 @@ describe("Connext Connector [Optimism]", function () { forking: { // @ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 12230000 + blockNumber: 7093500 } } ] }); - [wallet0, wallet1] = await ethers.getSigners(); masterSigner = await getMasterSigner(); - - instaConnectorsV2 = await ethers.getContractAt( - abis.core.connectorsV2, - addresses.core.connectorsV2 - ); + instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); connector = await deployAndEnableConnector({ connectorName, contractArtifact: ConnectV2ConnextOptimism__factory, @@ -72,14 +69,12 @@ describe("Connext Connector [Optimism]", function () { expect(!!dsaWallet0.address).to.be.true; }); - it("Deposit ETH & USDC into DSA wallet", async function() { + it("Deposit ETH & USDC into DSA wallet", async function () { await wallet0.sendTransaction({ to: dsaWallet0.address, - value: ethers.utils.parseEther("10"), + value: ethers.utils.parseEther("10") }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( - ethers.utils.parseEther("10") - ); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); // await addLiquidity( // "usdc", @@ -90,22 +85,19 @@ describe("Connext Connector [Optimism]", function () { }); describe("Main", function () { - it("should xcall with eth", async function () { const amount = ethers.utils.parseEther("10"); const domainId = 6648936; const slippage = 10000; - const relayerFee = ethers.utils.parseEther("1");; + const relayerFee = ethers.utils.parseEther("1"); const getId = 0; const callData = "0x"; - const wallet0Address = await wallet0.getAddress(); - const xcallParams: any = [ domainId, - wallet0Address, + wallet1.address, ethAddr, - wallet0Address, + wallet1.address, amount, slippage, relayerFee, @@ -120,8 +112,8 @@ describe("Connext Connector [Optimism]", function () { } ]; - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0Address); + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); const receipt = await tx.wait(); }); }); -}); \ No newline at end of file +}); From ee4d17bb86a98cef713177884ec74e6407af9d08 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Tue, 14 Mar 2023 18:28:04 +0700 Subject: [PATCH 08/17] update: blocknumber --- test/optimism/connext/connext.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts index 5671bd93..e6fb6ed7 100644 --- a/test/optimism/connext/connext.test.ts +++ b/test/optimism/connext/connext.test.ts @@ -39,7 +39,7 @@ describe("Connext Connector [Optimism]", function () { forking: { // @ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 7093500 + blockNumber: 80768349 } } ] From 66aa290f4e55b16eac976c273dec15fcddf7123c Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Wed, 22 Mar 2023 09:55:54 +0800 Subject: [PATCH 09/17] refactor: fix incorrect comparison --- .../optimism/connectors/connext/events.sol | 3 +- .../optimism/connectors/connext/helpers.sol | 36 +------------------ .../optimism/connectors/connext/main.sol | 26 +++++++++++--- test/optimism/connext/connext.test.ts | 28 ++++++++++----- 4 files changed, 45 insertions(+), 48 deletions(-) diff --git a/contracts/optimism/connectors/connext/events.sol b/contracts/optimism/connectors/connext/events.sol index a1d7e441..63676a17 100644 --- a/contracts/optimism/connectors/connext/events.sol +++ b/contracts/optimism/connectors/connext/events.sol @@ -9,6 +9,7 @@ contract Events { address delegate, uint256 amount, uint256 slippage, - uint256 getId + uint256 getId, + uint256 setId ); } diff --git a/contracts/optimism/connectors/connext/helpers.sol b/contracts/optimism/connectors/connext/helpers.sol index 5adddd7a..ccce031b 100644 --- a/contracts/optimism/connectors/connext/helpers.sol +++ b/contracts/optimism/connectors/connext/helpers.sol @@ -15,14 +15,6 @@ contract Helpers is DSMath, Basic { 0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA; IConnext internal constant connext = IConnext(connextAddr); - /** - * @dev InstaReceiver Address - */ - address internal constant instaReceiverAddr = - 0x0000000000000000000000000000000000000000; // TODO: Add InstaReceiver address - IInstaReceiver internal constant instaReceiver = - IInstaReceiver(instaReceiverAddr); - /** * @param destination The destination domain ID. * @param asset The address of token to be bridged. @@ -44,33 +36,7 @@ contract Helpers is DSMath, Basic { } function _xcall(XCallParams memory params) internal { - uint256 nativeTokenAmt; - bool isNative = params.asset == ethAddr; - - if (isNative) { - params.amount = params.amount == uint256(-1) - ? address(this).balance - : params.amount; - - // xcall does not take native asset, must wrap - TokenInterface tokenContract = TokenInterface(wethAddr); - convertEthToWeth(true, tokenContract, params.amount); - - nativeTokenAmt = params.amount; - } else { - TokenInterface tokenContract = TokenInterface(params.asset); - params.amount = params.amount == uint256(-1) - ? tokenContract.balanceOf(address(this)) - : params.amount; - - if (params.amount > 0) { - tokenContract.approve(connextAddr, params.amount); - } - - nativeTokenAmt = 0; - } - - connext.xcall{ value: params.relayerFee + nativeTokenAmt }( + connext.xcall{ value: params.relayerFee }( params.destination, params.to, params.asset, diff --git a/contracts/optimism/connectors/connext/main.sol b/contracts/optimism/connectors/connext/main.sol index 64b14aca..d289005a 100644 --- a/contracts/optimism/connectors/connext/main.sol +++ b/contracts/optimism/connectors/connext/main.sol @@ -21,16 +21,33 @@ abstract contract ConnextResolver is Helpers { * @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) + function xcall(XCallParams memory params, uint256 getId, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) { - params.amount = getUint(getId, params.amount); + uint256 _amount = getUint(getId, params.amount); TokenInterface tokenContract = TokenInterface(params.asset); + bool isNative = params.asset == wethAddr; + + 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); _xcall(params); - _eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256)"; + + setUint(setId, _amount); + _eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode( params.destination, params.to, @@ -38,7 +55,8 @@ abstract contract ConnextResolver is Helpers { params.delegate, params.amount, params.slippage, - getId + getId, + setId ); } } diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts index e6fb6ed7..32aa281d 100644 --- a/test/optimism/connext/connext.test.ts +++ b/test/optimism/connext/connext.test.ts @@ -12,6 +12,7 @@ import { abis } from "../../../scripts/constant/abis"; import { ConnectV2ConnextOptimism__factory } from "../../../typechain"; import { Signer, Contract } from "ethers"; + describe("Connext Connector [Optimism]", function () { const connectorName = "CONNEXT-TEST-A"; @@ -19,11 +20,14 @@ describe("Connext Connector [Optimism]", function () { let masterSigner: Signer; let instaConnectorsV2: Contract; let connector: Contract; - + let usdcContract: Contract; + let signer: any; + const connextAddr = "0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA"; const usdcAddr = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607"; const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; const wethAddr = "0x4200000000000000000000000000000000000006"; + const account = "0xebe80f029b1c02862b9e8a70a7e5317c06f62cae"; const wallets = provider.getWallets(); const [wallet0, wallet1] = wallets; @@ -39,7 +43,7 @@ describe("Connext Connector [Optimism]", function () { forking: { // @ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 80768349 + blockNumber: 82686991 } } ] @@ -53,8 +57,19 @@ describe("Connext Connector [Optimism]", function () { signer: masterSigner, connectors: instaConnectorsV2 }); + usdcContract = await ethers.getContractAt(abis.basic.erc20, usdcAddr); + signer = await ethers.getSigner(account); - console.log("Connector address", connector.address); + 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 function () { @@ -76,11 +91,8 @@ describe("Connext Connector [Optimism]", function () { }); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - // await addLiquidity( - // "usdc", - // dsaWallet0.address, - // ethers.utils.parseEther("100000") - // ); + 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)); }); }); From a22f47c6ae7ebe72d0be56e76514a273e1f14135 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Wed, 22 Mar 2023 14:04:39 +0800 Subject: [PATCH 10/17] feat: remove unnecessary and add a case --- .../optimism/connectors/connext/helpers.sol | 1 - .../optimism/connectors/connext/interface.sol | 15 ----- test/optimism/connext/connext.test.ts | 59 +++++++++++++------ 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/contracts/optimism/connectors/connext/helpers.sol b/contracts/optimism/connectors/connext/helpers.sol index ccce031b..4196c05c 100644 --- a/contracts/optimism/connectors/connext/helpers.sol +++ b/contracts/optimism/connectors/connext/helpers.sol @@ -5,7 +5,6 @@ import { TokenInterface } from "../../common/interfaces.sol"; import { DSMath } from "../../common/math.sol"; import { Basic } from "../../common/basic.sol"; import { IConnext } from "./interface.sol"; -import { IInstaReceiver } from "./interface.sol"; contract Helpers is DSMath, Basic { /** diff --git a/contracts/optimism/connectors/connext/interface.sol b/contracts/optimism/connectors/connext/interface.sol index d3597982..55b4b62f 100644 --- a/contracts/optimism/connectors/connext/interface.sol +++ b/contracts/optimism/connectors/connext/interface.sol @@ -12,18 +12,3 @@ interface IConnext { bytes calldata _callData ) external payable returns (bytes32); } - -interface IInstaReceiver { - function withdraw(address _asset, uint256 _amount) - external - returns (bytes memory); - - function xReceive( - bytes32 _transferId, - uint256 _amount, - address _asset, - address _originSender, - uint32 _origin, - bytes memory _callData - ) external returns (bytes memory); -} diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts index 32aa281d..da03a900 100644 --- a/test/optimism/connext/connext.test.ts +++ b/test/optimism/connext/connext.test.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import hre from "hardhat"; const { ethers, waffle } = hre; -const { provider, deployContract } = waffle; +const { provider } = waffle; import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; @@ -13,7 +13,7 @@ import { ConnectV2ConnextOptimism__factory } from "../../../typechain"; import { Signer, Contract } from "ethers"; -describe("Connext Connector [Optimism]", function () { +describe("Connext Connector [Optimism]", () => { const connectorName = "CONNEXT-TEST-A"; let dsaWallet0: Contract; @@ -23,18 +23,13 @@ describe("Connext Connector [Optimism]", function () { let usdcContract: Contract; let signer: any; - const connextAddr = "0x8f7492DE823025b4CfaAB1D34c58963F2af5DEDA"; const usdcAddr = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607"; - const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; const wethAddr = "0x4200000000000000000000000000000000000006"; const account = "0xebe80f029b1c02862b9e8a70a7e5317c06f62cae"; const wallets = provider.getWallets(); const [wallet0, wallet1] = wallets; - // const usdc = new ethers.Contract(usdcAddr, abis.basic.erc20); - // const weth = new ethers.Contract(wethAddr, abis.basic.erc20); - before(async () => { await hre.network.provider.request({ method: "hardhat_reset", @@ -68,23 +63,22 @@ describe("Connext Connector [Optimism]", function () { }); await usdcContract.connect(signer).transfer(wallet0.address, ethers.utils.parseUnits("10000", 6)); - console.log("deployed connector: ", connector.address); }); - it("Should have contracts deployed.", async function () { + 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", function () { - it("Should build DSA v2", async function () { + 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 function () { + it("Deposit ETH & USDC into DSA wallet", async () => { await wallet0.sendTransaction({ to: dsaWallet0.address, value: ethers.utils.parseEther("10") @@ -96,19 +90,18 @@ describe("Connext Connector [Optimism]", function () { }); }); - describe("Main", function () { - it("should xcall with eth", async function () { - const amount = ethers.utils.parseEther("10"); + 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 getId = 0; const callData = "0x"; const xcallParams: any = [ domainId, wallet1.address, - ethAddr, + wethAddr, wallet1.address, amount, slippage, @@ -120,7 +113,37 @@ describe("Connext Connector [Optimism]", function () { { connector: connectorName, method: "xcall", - args: [xcallParams, getId] + 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] } ]; From 07395bf419efd656376ec23e08d5db420e79ec98 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 27 Mar 2023 16:34:37 +0800 Subject: [PATCH 11/17] Update contracts/optimism/connectors/connext/main.sol Co-authored-by: Thrilok kumar --- contracts/optimism/connectors/connext/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/optimism/connectors/connext/main.sol b/contracts/optimism/connectors/connext/main.sol index d289005a..fdf1bb97 100644 --- a/contracts/optimism/connectors/connext/main.sol +++ b/contracts/optimism/connectors/connext/main.sol @@ -30,7 +30,7 @@ abstract contract ConnextResolver is Helpers { { uint256 _amount = getUint(getId, params.amount); TokenInterface tokenContract = TokenInterface(params.asset); - bool isNative = params.asset == wethAddr; + bool isNative = params.asset == ethAddr; if (isNative) { _amount = _amount == uint256(-1) ? sub(address(this).balance, params.relayerFee) : _amount; From 91c24842d30bdeea4a86c10d79231bb050478671 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 27 Mar 2023 16:35:09 +0800 Subject: [PATCH 12/17] Update contracts/optimism/connectors/connext/main.sol Co-authored-by: Thrilok kumar --- contracts/optimism/connectors/connext/main.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/optimism/connectors/connext/main.sol b/contracts/optimism/connectors/connext/main.sol index fdf1bb97..7a9b13de 100644 --- a/contracts/optimism/connectors/connext/main.sol +++ b/contracts/optimism/connectors/connext/main.sol @@ -34,7 +34,8 @@ abstract contract ConnextResolver is Helpers { if (isNative) { _amount = _amount == uint256(-1) ? sub(address(this).balance, params.relayerFee) : _amount; - + params.asset = wethAddr; + tokenContract = TokenInterface(params.asset); // xcall does not take native asset, must wrap convertEthToWeth(true, tokenContract, _amount); From 0b757d9cd789290178eb923a08a8cdcb8b91d111 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 27 Mar 2023 16:52:08 +0800 Subject: [PATCH 13/17] fix(test): update per connector changes --- test/optimism/connext/connext.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/optimism/connext/connext.test.ts b/test/optimism/connext/connext.test.ts index da03a900..ff856943 100644 --- a/test/optimism/connext/connext.test.ts +++ b/test/optimism/connext/connext.test.ts @@ -24,7 +24,7 @@ describe("Connext Connector [Optimism]", () => { let signer: any; const usdcAddr = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607"; - const wethAddr = "0x4200000000000000000000000000000000000006"; + const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; const account = "0xebe80f029b1c02862b9e8a70a7e5317c06f62cae"; const wallets = provider.getWallets(); @@ -101,7 +101,7 @@ describe("Connext Connector [Optimism]", () => { const xcallParams: any = [ domainId, wallet1.address, - wethAddr, + ethAddr, wallet1.address, amount, slippage, From 9cd3cec75cd130b403329dacd78e6f4fe77ff622 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 3 Apr 2023 10:41:02 +0800 Subject: [PATCH 14/17] Update contracts/optimism/connectors/connext/main.sol Co-authored-by: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> --- contracts/optimism/connectors/connext/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/optimism/connectors/connext/main.sol b/contracts/optimism/connectors/connext/main.sol index 7a9b13de..0f76a7e0 100644 --- a/contracts/optimism/connectors/connext/main.sol +++ b/contracts/optimism/connectors/connext/main.sol @@ -33,7 +33,7 @@ abstract contract ConnextResolver is Helpers { bool isNative = params.asset == ethAddr; if (isNative) { - _amount = _amount == uint256(-1) ? sub(address(this).balance, params.relayerFee) : _amount; + _amount = _amount == uint256(-1) ? address(this).balance : _amount; params.asset = wethAddr; tokenContract = TokenInterface(params.asset); // xcall does not take native asset, must wrap From ff174f4040833d7e21d5d4630dd9de2a52696fff Mon Sep 17 00:00:00 2001 From: just-a-node Date: Mon, 17 Apr 2023 19:49:40 -0400 Subject: [PATCH 15/17] Add mainnet, arbitrum, polygon connectors --- .../arbitrum/connectors/connext/events.sol | 15 +++++ .../arbitrum/connectors/connext/helpers.sol | 48 +++++++++++++ .../arbitrum/connectors/connext/interface.sol | 14 ++++ .../arbitrum/connectors/connext/main.sol | 67 +++++++++++++++++++ .../mainnet/connectors/connext/events.sol | 15 +++++ .../mainnet/connectors/connext/helpers.sol | 48 +++++++++++++ .../mainnet/connectors/connext/interface.sol | 14 ++++ contracts/mainnet/connectors/connext/main.sol | 67 +++++++++++++++++++ .../polygon/connectors/connext/events.sol | 15 +++++ .../polygon/connectors/connext/helpers.sol | 48 +++++++++++++ .../polygon/connectors/connext/interface.sol | 14 ++++ contracts/polygon/connectors/connext/main.sol | 67 +++++++++++++++++++ 12 files changed, 432 insertions(+) create mode 100644 contracts/arbitrum/connectors/connext/events.sol create mode 100644 contracts/arbitrum/connectors/connext/helpers.sol create mode 100644 contracts/arbitrum/connectors/connext/interface.sol create mode 100644 contracts/arbitrum/connectors/connext/main.sol create mode 100644 contracts/mainnet/connectors/connext/events.sol create mode 100644 contracts/mainnet/connectors/connext/helpers.sol create mode 100644 contracts/mainnet/connectors/connext/interface.sol create mode 100644 contracts/mainnet/connectors/connext/main.sol create mode 100644 contracts/polygon/connectors/connext/events.sol create mode 100644 contracts/polygon/connectors/connext/helpers.sol create mode 100644 contracts/polygon/connectors/connext/interface.sol create mode 100644 contracts/polygon/connectors/connext/main.sol diff --git a/contracts/arbitrum/connectors/connext/events.sol b/contracts/arbitrum/connectors/connext/events.sol new file mode 100644 index 00000000..63676a17 --- /dev/null +++ b/contracts/arbitrum/connectors/connext/events.sol @@ -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 + ); +} diff --git a/contracts/arbitrum/connectors/connext/helpers.sol b/contracts/arbitrum/connectors/connext/helpers.sol new file mode 100644 index 00000000..5fbc2057 --- /dev/null +++ b/contracts/arbitrum/connectors/connext/helpers.sol @@ -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 + ); + } +} diff --git a/contracts/arbitrum/connectors/connext/interface.sol b/contracts/arbitrum/connectors/connext/interface.sol new file mode 100644 index 00000000..55b4b62f --- /dev/null +++ b/contracts/arbitrum/connectors/connext/interface.sol @@ -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); +} diff --git a/contracts/arbitrum/connectors/connext/main.sol b/contracts/arbitrum/connectors/connext/main.sol new file mode 100644 index 00000000..0f76a7e0 --- /dev/null +++ b/contracts/arbitrum/connectors/connext/main.sol @@ -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"; +} diff --git a/contracts/mainnet/connectors/connext/events.sol b/contracts/mainnet/connectors/connext/events.sol new file mode 100644 index 00000000..63676a17 --- /dev/null +++ b/contracts/mainnet/connectors/connext/events.sol @@ -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 + ); +} diff --git a/contracts/mainnet/connectors/connext/helpers.sol b/contracts/mainnet/connectors/connext/helpers.sol new file mode 100644 index 00000000..d7931d9a --- /dev/null +++ b/contracts/mainnet/connectors/connext/helpers.sol @@ -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 + ); + } +} diff --git a/contracts/mainnet/connectors/connext/interface.sol b/contracts/mainnet/connectors/connext/interface.sol new file mode 100644 index 00000000..55b4b62f --- /dev/null +++ b/contracts/mainnet/connectors/connext/interface.sol @@ -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); +} diff --git a/contracts/mainnet/connectors/connext/main.sol b/contracts/mainnet/connectors/connext/main.sol new file mode 100644 index 00000000..0f76a7e0 --- /dev/null +++ b/contracts/mainnet/connectors/connext/main.sol @@ -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"; +} diff --git a/contracts/polygon/connectors/connext/events.sol b/contracts/polygon/connectors/connext/events.sol new file mode 100644 index 00000000..63676a17 --- /dev/null +++ b/contracts/polygon/connectors/connext/events.sol @@ -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 + ); +} diff --git a/contracts/polygon/connectors/connext/helpers.sol b/contracts/polygon/connectors/connext/helpers.sol new file mode 100644 index 00000000..f814a89f --- /dev/null +++ b/contracts/polygon/connectors/connext/helpers.sol @@ -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 + ); + } +} diff --git a/contracts/polygon/connectors/connext/interface.sol b/contracts/polygon/connectors/connext/interface.sol new file mode 100644 index 00000000..55b4b62f --- /dev/null +++ b/contracts/polygon/connectors/connext/interface.sol @@ -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); +} diff --git a/contracts/polygon/connectors/connext/main.sol b/contracts/polygon/connectors/connext/main.sol new file mode 100644 index 00000000..0f76a7e0 --- /dev/null +++ b/contracts/polygon/connectors/connext/main.sol @@ -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"; +} From 09312ae2471eba77894a3c7462f14167ec978af3 Mon Sep 17 00:00:00 2001 From: just-a-node Date: Mon, 17 Apr 2023 19:49:55 -0400 Subject: [PATCH 16/17] Add tests for mainnet, arbitrum, polygon --- test/arbitrum/connext/connext.test.ts | 154 ++++++++++++++++++++++++++ test/mainnet/connext/connext.test.ts | 154 ++++++++++++++++++++++++++ test/polygon/connext/connext.test.ts | 123 ++++++++++++++++++++ 3 files changed, 431 insertions(+) create mode 100644 test/arbitrum/connext/connext.test.ts create mode 100644 test/mainnet/connext/connext.test.ts create mode 100644 test/polygon/connext/connext.test.ts diff --git a/test/arbitrum/connext/connext.test.ts b/test/arbitrum/connext/connext.test.ts new file mode 100644 index 00000000..74e98d63 --- /dev/null +++ b/test/arbitrum/connext/connext.test.ts @@ -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(); + }); + }); +}); diff --git a/test/mainnet/connext/connext.test.ts b/test/mainnet/connext/connext.test.ts new file mode 100644 index 00000000..7e4c0d2c --- /dev/null +++ b/test/mainnet/connext/connext.test.ts @@ -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(); + }); + }); +}); diff --git a/test/polygon/connext/connext.test.ts b/test/polygon/connext/connext.test.ts new file mode 100644 index 00000000..ce0985e8 --- /dev/null +++ b/test/polygon/connext/connext.test.ts @@ -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(); + }); + }); +}); From ab33acf097ac5c62129cb5312db8f7e451810965 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sat, 22 Apr 2023 03:09:59 +0400 Subject: [PATCH 17/17] Fix: contracts names + polygon native token --- contracts/arbitrum/connectors/connext/main.sol | 2 +- contracts/mainnet/connectors/connext/main.sol | 2 +- contracts/polygon/connectors/connext/main.sol | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/arbitrum/connectors/connext/main.sol b/contracts/arbitrum/connectors/connext/main.sol index 0f76a7e0..5438a671 100644 --- a/contracts/arbitrum/connectors/connext/main.sol +++ b/contracts/arbitrum/connectors/connext/main.sol @@ -62,6 +62,6 @@ abstract contract ConnextResolver is Helpers { } } -contract ConnectV2ConnextOptimism is ConnextResolver { +contract ConnectV2ConnextArbitrum is ConnextResolver { string public constant name = "Connext-v1.0"; } diff --git a/contracts/mainnet/connectors/connext/main.sol b/contracts/mainnet/connectors/connext/main.sol index 0f76a7e0..22c50387 100644 --- a/contracts/mainnet/connectors/connext/main.sol +++ b/contracts/mainnet/connectors/connext/main.sol @@ -62,6 +62,6 @@ abstract contract ConnextResolver is Helpers { } } -contract ConnectV2ConnextOptimism is ConnextResolver { +contract ConnectV2Connext is ConnextResolver { string public constant name = "Connext-v1.0"; } diff --git a/contracts/polygon/connectors/connext/main.sol b/contracts/polygon/connectors/connext/main.sol index 0f76a7e0..34965f1d 100644 --- a/contracts/polygon/connectors/connext/main.sol +++ b/contracts/polygon/connectors/connext/main.sol @@ -30,14 +30,14 @@ abstract contract ConnextResolver is Helpers { { uint256 _amount = getUint(getId, params.amount); TokenInterface tokenContract = TokenInterface(params.asset); - bool isNative = params.asset == ethAddr; + bool isNative = params.asset == maticAddr; if (isNative) { _amount = _amount == uint256(-1) ? address(this).balance : _amount; - params.asset = wethAddr; + params.asset = wmaticAddr; tokenContract = TokenInterface(params.asset); // xcall does not take native asset, must wrap - convertEthToWeth(true, tokenContract, _amount); + convertMaticToWmatic(true, tokenContract, _amount); } else { _amount = _amount == uint256(-1) ? tokenContract.balanceOf(address(this)) : _amount; @@ -62,6 +62,6 @@ abstract contract ConnextResolver is Helpers { } } -contract ConnectV2ConnextOptimism is ConnextResolver { +contract ConnectV2ConnextPolygon is ConnextResolver { string public constant name = "Connext-v1.0"; }