Skip to content

Commit

Permalink
feat: add hop protocol (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride authored Aug 18, 2022
1 parent 91fbd82 commit 00ddc1e
Show file tree
Hide file tree
Showing 15 changed files with 3,177 additions and 10 deletions.
221 changes: 221 additions & 0 deletions artifacts/HopFacet.json

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions artifacts/IHopBridge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "IHopBridge",
"sourceName": "src/bridges/interfaces/IHopBridge.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "chainId",
"type": "uint256"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amountOutMin",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "uint256",
"name": "relayerFee",
"type": "uint256"
}
],
"name": "sendToL2",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "chainId",
"type": "uint256"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "bonderFee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amountOutMin",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "destinationAmountOutMin",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "destinationDeadline",
"type": "uint256"
}
],
"name": "swapAndSend",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}
10 changes: 0 additions & 10 deletions artifacts/console.json

This file was deleted.

26 changes: 26 additions & 0 deletions config/hop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { NetworkNames } from "../extensions/constants";

const L1 = [
NetworkNames.Rinkeby,
NetworkNames.Goerli,
NetworkNames.Kovan,
]

const L2 = [
NetworkNames.Xdai,
NetworkNames.Optimism,
NetworkNames.Arbitrum,
NetworkNames.Matic,
NetworkNames.Mumbai,
]

export const HopConfig = Object.values(NetworkNames).reduce((obj, name) => {
if (L1.some(n => n === name)) {
obj[name] = 1;
} else if (L2.some(n => n === name)) {
obj[name] = 2;
}
return obj;
}, {});

HopConfig['hardhat'] = 1; // for testing purposes
47 changes: 47 additions & 0 deletions deploy/206_deploy_hop_facet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { addOrReplaceFacets } from '../utils/diamond';
import { HopConfig } from '../config/hop';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {
deployments: { deploy },
getNamedAccounts,
ethers,
network
} = hre;
const { from } = await getNamedAccounts();

if (!HopConfig[network.name]) {
throw new Error("No config for this network available: " + network.name);
}

await deploy('HopFacet', {
from,
log: true,
});

const diamond = await ethers.getContract('Diamond');
const hopFacet = await ethers.getContract("HopFacet");

const ABI = ['function initHop(uint256)'];
const iface = new hre.ethers.utils.Interface(ABI)

console.log('HopConfig', HopConfig[network.name]);

const initData = iface.encodeFunctionData('initHop', [
HopConfig[network.name]
]);

await addOrReplaceFacets(
[hopFacet],
diamond.address,
hopFacet.address,
initData
);
}

func.tags = ['bridges', 'hop'];
func.dependencies = ['init-facets'];

export default func;
2 changes: 2 additions & 0 deletions extensions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HardhatUserConfig } from 'hardhat/config';
import { NetworkNames, NETWORK_CONFIGS } from './constants';
import * as dotenv from 'dotenv';
dotenv.config();

export function createConfigNetwork(
networkName: NetworkNames,
Expand Down
Loading

0 comments on commit 00ddc1e

Please sign in to comment.