Skip to content

Commit

Permalink
Feature/pro 284 integration of cbridge (#78)
Browse files Browse the repository at this point in the history
* Structure setup

Set up of contract and testing file and folder structure

* cBridge smart contract and testing

- Updated hardhat version to latest and added support for issue with EIP when testing.
- Added hardhat-tracer plugin for extra visibility of events and transactions and EVM opcodes.
- Added mainnet forking to hardhat.config to reduce testing deployments.
- Added logic for cBridge integration in smart contract.
- Added new test util for checking emitted event information.
- Added new test util for checking last emitted event in a multicall function.
- Tested smart contract.
- Slither check performed.

* Amended test suite to integrate diamond functionality

- Integrated Diamond Proxy functionality into CBridgeFacet test suite.
- Added in checks to ensure some contract functions can only be called by Diamond Proxy owner.
- Created deployment script.
- Removed 0.8.13 compiler version from hardhat.config as no longer used.
- Turned off forking for deployment testing.
- HH Addr: 0xD9a9Ee6B79fBa90dA738735C85bdAf43ae1E2B60

* Updated cBridgeFacet

- Removed chainId from the contract and replaced with block.chainid and removed contract variable.
- Amended test suite to reflect the changes.

* Edited deployment script and tested CREATE2 deployment

- Edited deployment script to reflect removal of chain id.
- Tested deterministic deployment on Goerli, OptimismKovan & ArbitrumTest (0x3054F79f18AecC4aAe249fd9C8ca23D93d635504)

* Fixed linting issue

- Removed chainId variable from deployment script.

* Smart contract and test suite changes

- Added storage struct into smart contract.
- Added namespace storage pointer.
- Updated cBridge address updating function name to be more specific.
- Updated test suite to reflect smart contract changes.

* Replaced OpenZeppelin contracts

- Removed imports from OpenZeppelin
- Manually added contracts that were removed

* Reinstated IERC20 OpenZeppelin import

- Reinstated IERC20 OpenZeppelin import

* Updated CBridgeFacet to include slippage

- Added default slippage into facet
- Added functionality to update slippage tolerance
- Changed function and event names to relate more bridge type
- Added SafeERC20 functionality for standard approvals and transfers
- Removed need for LibAsset helper functions
- Updated test suite to reflect changes and confirm all still passing
- Added custom CBridge errors

* Added further tests and amended deployment script to match contract changes

- Added more revert requirements in cbBridgeTokens and added to test suite
- Changed deployment script to match new initialise fn name
- Added tests for cbWithdraw fn

* Modified ReentrancyGuard contract and moved

- Changed the contract name to DiamondReentrancyGuard.sol
- Moved the contract into common/helpers and updated the path in the facet
- Amended the NAMESPACE constant to something that better reflects the code

* Updated typings - issue with pulling through Stargate typings

* Fix for unneeded typings

- Running 'npx hardhat coverage' seemed to remove unwanted typings

* Update 204_deploy_cbridge_facet.ts

- Changed tags on deployment script in line with new diamond deployments.

* Removed receive fn from facet contract

* Update StargateFacet.sol

- Removed receive() from StargateFacet

* Removal of withdraw from CBridge and Stargate facets

- Removed withdraw fn from CBridge and Stargate facets
- Updated test suite to remove testing for withdraw fn

* Fix merge conflicts

* Update hardhat.config.ts

- Added new compiler version to hardhat.config to fix issue with @connext imported contracts

* Update package-lock.json

- Rerun of npm to install latest packages for connext libs

* Updated connext lib

* Removed 0.8.15 compiler version

* Re-added 0.8.15 compiler version

Co-authored-by: Luke Wickens <[email protected]>
  • Loading branch information
cryptonoyaiba and Luke Wickens authored Aug 23, 2022
1 parent 00ddc1e commit 823af44
Show file tree
Hide file tree
Showing 136 changed files with 171,880 additions and 40,869 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ node_modules
.test*
coverage
coverage.json
deployments

This comment has been minimized.

Copy link
@ch4r10t33r

ch4r10t33r Sep 14, 2022

Member

This is incorrect. Shouldn't be added to .gitignore


# hardhat
.hardhat
337 changes: 337 additions & 0 deletions artifacts/CBridgeFacet.json

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions artifacts/ICBridge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "ICBridge",
"sourceName": "src/bridges/interfaces/ICBridge.sol",
"abi": [
{
"inputs": [
{
"internalType": "bytes",
"name": "_relayRequest",
"type": "bytes"
},
{
"internalType": "bytes[]",
"name": "_sigs",
"type": "bytes[]"
},
{
"internalType": "address[]",
"name": "_signers",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "_powers",
"type": "uint256[]"
}
],
"name": "relay",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_receiver",
"type": "address"
},
{
"internalType": "address",
"name": "_token",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "_dstChinId",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "_nonce",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "_maxSlippage",
"type": "uint32"
}
],
"name": "send",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_receiver",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "_dstChinId",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "_nonce",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "_maxSlippage",
"type": "uint32"
}
],
"name": "sendNative",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}
76 changes: 76 additions & 0 deletions config/cBridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
interface cBridgeConfig {
[key: string]: {
cBridge: string;
chainId: number;
};
}
//0x552008c0f6870c2f77e5cc1d2eb9bdff03e30ea0
const config: cBridgeConfig = {
// leave cBridgeConfig as '' if you want to deploy a router with deployments
hardhat: {
cBridge: "0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820",
chainId: 1,
},
xdai: {
cBridge: "0x3795C36e7D12A8c252A20C5a7B455f7c57b60283",
chainId: 100,
},
mainnet: {
cBridge: "0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820",
chainId: 1,
},
optimism: {
cBridge: "0x9D39Fc627A6d9d9F8C831c16995b209548cc3401",
chainId: 10,
},
bsc: {
cBridge: "0xdd90E5E87A2081Dcf0391920868eBc2FFB81a1aF",
chainId: 56,
},
polygon: {
cBridge: "0x88DCDC47D2f83a99CF0000FDF667A468bB958a78",
chainId: 137,
},
fantom: {
cBridge: "0x374B8a9f3eC5eB2D97ECA84Ea27aCa45aa1C57EF",
chainId: 250,
},
moonbeam: {
cBridge: "0x841ce48F9446C8E281D3F1444cB859b4A6D0738C",
chainId: 1284,
},
boba: {
cBridge: "0x841ce48F9446C8E281D3F1444cB859b4A6D0738C",
chainId: 288,
},
arbitrum: {
cBridge: "0x1619DE6B6B20eD217a58d00f37B9d47C7663feca",
chainId: 42161,
},
avax: {
cBridge: "0xef3c714c9425a8F3697A9C969Dc1af30ba82e5d4",
chainId: 43114,
},
moon_river: {
cBridge: "0x841ce48F9446C8E281D3F1444cB859b4A6D0738C",
chainId: 1285,
},
celo: {
cBridge: "0xBB7684Cc5408F4DD0921E5c2Cadd547b8f1AD573",
chainId: 42220,
},
goerli: {
cBridge: "0xd9145CCE52D386f254917e481eB44e9943F39138",
chainId: 5,
},
optimismKovan: {
cBridge: "0x6D5862a18C6a169D44d02a8B726a02A5B707B484",
chainId: 69,
},
arbitrumTest: {
cBridge: "0x8314Af54080dF4d05768c5D3f097f59f170d9564",
chainId: 421611,
},
};

export default config;
46 changes: 46 additions & 0 deletions deploy/204_deploy_cbridge_facet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { utils } from "ethers";
import { network } from "hardhat";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { addOrReplaceFacets } from "../utils/diamond";
import config from "../config/cBridge";

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

let bridgeAddr = "0xc578cbaf5a411dfa9f0d227f97dadaa4074ad062";

await deploy("CBridgeFacet", {
from,
log: true,
deterministicDeployment: true,
});

const cBridgeFacet = await ethers.getContract("CBridgeFacet");
const diamond = await ethers.getContract("Diamond");

const ABI = ["function cbInitialize(address)"];
const iface = new utils.Interface(ABI);

if (config[network.name].cBridge != "") {
bridgeAddr = config[network.name].cBridge;
}

const initData = iface.encodeFunctionData("cbInitialize", [bridgeAddr]);

await addOrReplaceFacets(
[cBridgeFacet],
diamond.address,
cBridgeFacet.address,
initData,
);
};
export default func;
func.id = "cbridge_facet_deploy";
func.tags = ["bridges", "cbridge"];
func.dependencies = ["init-facets"];
8 changes: 8 additions & 0 deletions dist/config/cBridge.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface cBridgeConfig {
[key: string]: {
cBridge: string;
chainId: number;
};
}
declare const config: cBridgeConfig;
export default config;
69 changes: 69 additions & 0 deletions dist/config/cBridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config = {
hardhat: {
cBridge: "0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820",
chainId: 1,
},
xdai: {
cBridge: "0x3795C36e7D12A8c252A20C5a7B455f7c57b60283",
chainId: 100,
},
mainnet: {
cBridge: "0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820",
chainId: 1,
},
optimism: {
cBridge: "0x9D39Fc627A6d9d9F8C831c16995b209548cc3401",
chainId: 10,
},
bsc: {
cBridge: "0xdd90E5E87A2081Dcf0391920868eBc2FFB81a1aF",
chainId: 56,
},
polygon: {
cBridge: "0x88DCDC47D2f83a99CF0000FDF667A468bB958a78",
chainId: 137,
},
fantom: {
cBridge: "0x374B8a9f3eC5eB2D97ECA84Ea27aCa45aa1C57EF",
chainId: 250,
},
moonbeam: {
cBridge: "0x841ce48F9446C8E281D3F1444cB859b4A6D0738C",
chainId: 1284,
},
boba: {
cBridge: "0x841ce48F9446C8E281D3F1444cB859b4A6D0738C",
chainId: 288,
},
arbitrum: {
cBridge: "0x1619DE6B6B20eD217a58d00f37B9d47C7663feca",
chainId: 42161,
},
avax: {
cBridge: "0xef3c714c9425a8F3697A9C969Dc1af30ba82e5d4",
chainId: 43114,
},
moon_river: {
cBridge: "0x841ce48F9446C8E281D3F1444cB859b4A6D0738C",
chainId: 1285,
},
celo: {
cBridge: "0xBB7684Cc5408F4DD0921E5c2Cadd547b8f1AD573",
chainId: 42220,
},
goerli: {
cBridge: "0xd9145CCE52D386f254917e481eB44e9943F39138",
chainId: 5,
},
optimismKovan: {
cBridge: "0x6D5862a18C6a169D44d02a8B726a02A5B707B484",
chainId: 69,
},
arbitrumTest: {
cBridge: "0x8314Af54080dF4d05768c5D3f097f59f170d9564",
chainId: 421611,
},
};
exports.default = config;
2 changes: 2 additions & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export declare enum ContractNames {
AmplificationUtils = 'AmplificationUtils',
BalancesHelper = 'BalancesHelper',
BalancesHelperV2 = 'BalancesHelperV2',
CBridgeFacet = 'CBridgeFacet',
ConnextFacet = 'ConnextFacet',
ConnextMessage = 'ConnextMessage',
Context = 'Context',
Expand Down Expand Up @@ -36,6 +37,7 @@ export declare enum ContractNames {
Guarded = 'Guarded',
Home = 'Home',
IBridgeToken = 'IBridgeToken',
ICBridge = 'ICBridge',
ICallback = 'ICallback',
IConnextHandler = 'IConnextHandler',
IDiamondCut = 'IDiamondCut',
Expand Down
2 changes: 2 additions & 0 deletions dist/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
AmplificationUtils: 'AmplificationUtils',
BalancesHelper: 'BalancesHelper',
BalancesHelperV2: 'BalancesHelperV2',
CBridgeFacet: 'CBridgeFacet',
ConnextFacet: 'ConnextFacet',
ConnextMessage: 'ConnextMessage',
Context: 'Context',
Expand Down Expand Up @@ -39,6 +40,7 @@ module.exports = {
Guarded: 'Guarded',
Home: 'Home',
IBridgeToken: 'IBridgeToken',
ICBridge: 'ICBridge',
ICallback: 'ICallback',
IConnextHandler: 'IConnextHandler',
IDiamondCut: 'IDiamondCut',
Expand Down
Loading

0 comments on commit 823af44

Please sign in to comment.