Merge pull request #224 from Instadapp/hop-mainnet-updates

Hop mainnet fixes
This commit is contained in:
0xPradyuman 2022-05-28 23:40:50 +05:30 committed by GitHub
commit 0c91fc9e15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 144 additions and 12 deletions

View File

@ -26,13 +26,16 @@ contract Helpers is DSMath, Basic {
uint256 destinationDeadline;
}
function _sendToL2(BridgeParams memory params) internal {
function _sendToL2(BridgeParams memory params, bool isNative) internal {
IHopRouter router = IHopRouter(params.router);
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, params.router, params.amount);
uint256 nativeTokenAmt = isNative ? params.amount : 0;
if (!isNative) {
TokenInterface tokenContract = TokenInterface(params.token);
approve(tokenContract, params.router, params.amount);
}
router.sendToL2(
router.sendToL2{ value: nativeTokenAmt }(
params.targetChainId,
params.recipient,
params.amount,

View File

@ -12,5 +12,5 @@ interface IHopRouter {
uint256 deadline,
address relayer,
uint256 relayerFee
) external;
) external payable;
}

View File

@ -26,24 +26,26 @@ abstract contract Resolver is Helpers {
returns (string memory _eventName, bytes memory _eventParam)
{
params.amount = getUint(getId, params.amount);
bool isEth = params.token == ethAddr;
params.token = params.token == ethAddr ? wethAddr : params.token;
TokenInterface tokenContract = TokenInterface(params.token);
if (isEth) {
if (params.token == wethAddr) {
convertWethToEth(true, tokenContract, params.amount);
params.token = ethAddr;
}
bool isNative = params.token == ethAddr;
if (isNative) {
params.amount = params.amount == uint256(-1)
? address(this).balance
: params.amount;
convertEthToWeth(isEth, tokenContract, params.amount);
} else {
params.amount = params.amount == uint256(-1)
? tokenContract.balanceOf(address(this))
: params.amount;
}
_sendToL2(params);
_sendToL2(params, isNative);
_eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(

View File

@ -0,0 +1,127 @@
import { expect } from "chai";
import hre from "hardhat";
const { waffle, ethers } = 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 { addLiquidity } from "../../../scripts/tests/addLiquidity";
import { addresses } from "../../../scripts/tests/mainnet/addresses";
import { abis } from "../../../scripts/constant/abis";
import { ConnectV2Hop__factory } from "../../../typechain";
import { Signer, Contract } from "ethers";
describe("Hop Connector", function () {
const connectorName = "HOP-MAINNET-X";
let dsaWallet0: Contract;
let masterSigner: Signer;
let instaConnectorsV2: Contract;
let connector: Contract;
const wallets = provider.getWallets();
const [wallet0, wallet1, wallet2, wallet3] = wallets;
const DAI_ADDR = "0x6B175474E89094C44Da98b954EedeAC495271d0F";
const l2AmmWrapper = "0x3d4Cc8A61c7528Fd86C55cfe061a78dCBA48EDd1";
const token = new ethers.Contract(DAI_ADDR, 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: 14854895
}
}
]
});
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2Hop__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.address);
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH & DAI 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("dai", dsaWallet0.address, ethers.utils.parseEther("10000"));
});
});
describe("Main", function () {
it("should migrate DAI from L1 to L2", async function () {
const amount = ethers.utils.parseEther("10");
const deadline = Date.now() + 604800;
const getId = "0";
const params: any = [DAI_ADDR, wallet0.address, l2AmmWrapper, 137, amount.toString(), "0", deadline];
const spells = [
{
connector: connectorName,
method: "bridge",
args: [params, getId]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
let receipt = await tx.wait();
});
it("should migrate ETH from L1 to L2", async function () {
const amount = ethers.utils.parseEther("10");
const deadline = Date.now() + 604800;
const getId = "0";
const params: any = [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
wallet0.address,
"0xb8901acB165ed027E32754E0FFe830802919727f",
137,
amount.toString(),
"0",
deadline
];
const spells = [
{
connector: connectorName,
method: "bridge",
args: [params, getId]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
let receipt = await tx.wait();
});
});
});