Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ Described in the corresponding [README](near/README.md)
## EthErc20Bridge scripts
Below given command will help user to deploy and interact with contracts on the network provided as arg to below command, if no arg is provided it will use default network from hardhat-config.

First set up your `.env` file in `spectere-bridge-protocol/.env`, for help `.env.example` is provided in `spectere-bridge-protocol` directory.
First set up your `.env` file in `fast-bridge-protocol/eth/.env`, for help `.env.example` is provided in `fast-bridge-protocol/eth` directory.
1. First copy content of `.env.example` file
2. Create a new file in `spectere-bridge-protocol` directory and name it `.env`
2. Create a new file in `fast-bridge-protocol/eth` directory and name it `.env`
3. Paste copied content in `.env` file
4. Fill up details as required as per used in `hardhat.config.json` file.

Then, to run below scripts go to `spectere-bridge-protocol/eth` directory, i.e. **run command `cd eth`**
Then, to run below scripts go to `fast-bridge-protocol/eth` directory, i.e. **run command `cd eth`**

example : to deploy EthErc20FastBridge on <network-name> network (network-name must be defined in hardhat-config.json's networks)
`npm run deploy:bridge -- <network-name>`

### Deployment script
Running ths script will deploy bridge proxy and store proxy and implementation address in `spectre-bridge-protocol/eth/scripts/deployment/deploymentAddresses.json`
Running this script will deploy the bridge proxy and store the proxy and implementation address in `fast-bridge-protocol/eth/scripts/deployment/deploymentAddresses.json`
To execute this script => run command `yarn run deploy:bridge -- <network-name>`
example : to deploy bridge on goerli run command `yarn run deploy:bridge -- goerli`

Expand All @@ -50,14 +50,14 @@ To execute this script => run command `yarn run deploy:verify:bridge -- <network
example : to deploy and verify bridge on goerli run command `yarn run deploy:verify:bridge -- goerli`

### Upgrade script
To upgrade bridge contract(using hardhat's upgrades plugin), use `spectre-bridge-protocol/eth/scripts/EthErc20FastBridge/upgrade_bridge.js` script.
<!-- Before upgrading, go to file `spectre-bridge-protocol/eth/scripts/EthErc20FastBridge/upgrade_bridge.js` and update current bridge proxy address at line 7. -->
To upgrade bridge contract(using hardhat's upgrades plugin), use `fast-bridge-protocol/eth/scripts/EthErc20FastBridge/upgrade_bridge.js` script.
<!-- Before upgrading, go to file `fast-bridge-protocol/eth/scripts/EthErc20FastBridge/upgrade_bridge.js` and update current bridge proxy address at line 7. -->

To execute this script => run command `yarn run upgrade:bridge -- <network-name>`
example : to upgrade on goerli run command `yarn run deploy:verify:bridge -- goerli`

### Whitelisting
To interact with EthErc20FastBridge whitelisting methods use methods defined in spectre-bridge-protocol/eth/scripts/EthErc20FastBridge/whitelistTokens.js
To interact with EthErc20FastBridge whitelisting methods use methods defined in fast-bridge-protocol/eth/scripts/EthErc20FastBridge/whitelistTokens.js

* To bulk update whitelist status of tokens import and use method `bulkWhitelistStatusUpdate` from above mentioned file with an array of token addresses, an array of their corresponding status and a signer with `WHITELISTING_TOKENS_ADMIN_ROLE` as parameters.

Expand Down Expand Up @@ -87,21 +87,21 @@ main().catch((error) => {
And to run above script run `npx hardhat run <path_to_script/script.js> --` from eth folder.

### Pause/Unpause transfers
To interact with EthErc20FastBridge pause and unpause methods use methods defined in spectre-bridge-protocol/eth/scripts/EthErc20FastBridge/pause_unPause.js
To interact with EthErc20FastBridge pause and unpause methods use methods defined in fast-bridge-protocol/eth/scripts/EthErc20FastBridge/pause_unPause.js

* To pause transfers import and use `pauseTransfer` method from above mentioned file with a signer with `PAUSABLE_ADMIN_ROLE` as parameter.

* To unpause transfers import and use `unpauseTransfer` method from above mentioned file with a signer with `UNPAUSABLE_ADMIN_ROLE` as parameter.

These methods can be used in similar to above example

### To interact with above methods use script `spectre-bridge-protocol/eth/scripts/EthErc20FastBridge/interact_with_bridge.js`
### To interact with above methods use script `fast-bridge-protocol/eth/scripts/EthErc20FastBridge/interact_with_bridge.js`
Follow below steps to execute script and start interacting
1. First, create your `.env` file(mentioned in `EthErc20Bridge scripts` section's starting)
2. Go to `spectre-bridge-protocol/eth` directory in terminal
2. Go to `fast-bridge-protocol/eth` directory in terminal
3. Run command `npm run interact:bridge -- <network_name_as_defined_in_hardhat_config>`
4. Follow guide in terminal
Note: bridge address will be picked from `deploymentAddress[network].new.bridge` (from `spectre-bridge-protocol/eth/scripts/deployment/deploymentAddresses.json`)
Note: bridge address will be picked from `deploymentAddress[network].new.bridge` (from `fast-bridge-protocol/eth/scripts/deployment/deploymentAddresses.json`)

### To interact with FastBridge using hardhat task
To call any method of EthErc20FastBridge use hardhat task `method`
Expand All @@ -111,7 +111,7 @@ to create `json_string_input`
1. create json with `signature` and `arguments` properties in below example format

{
"signature": "setWhitelistedTokens(address[],bool[])",
"methodname": "setWhitelistedTokens",
"argcount": "2",
"arguments": {
"arg1": [
Expand All @@ -130,4 +130,4 @@ to create `json_string_input`
2. pass below json to JSON.stringify() and use output as `json_string_input`

```
example: to call `setWhitelistedTokens` method run command `npx hardhat method --jsonstring '{"signature":"setWhitelistedTokens","arguments":{"arg1":["0xdAC17F958D2ee523a2206206994597C13D831ec7"],"arg2":[true]}}'`
example: to call `setWhitelistedTokens` method run command `npx hardhat method --jsonstring '{"methodname":"setWhitelistedTokens","arguments":{"arg1":["0xdAC17F958D2ee523a2206206994597C13D831ec7"],"arg2":[true]}}'`
14 changes: 7 additions & 7 deletions eth/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require("@nomicfoundation/hardhat-network-helpers");
require("hardhat-contract-sizer");
require("hardhat-abi-exporter");
require("@openzeppelin/hardhat-upgrades");
const { ethers } = require("ethers");
const { task } = require("hardhat/config");
const deploymentAddress = require("./scripts/deployment/deploymentAddresses.json");
const bridgeArtifacts = require("./artifacts/contracts/EthErc20FastBridge.sol/EthErc20FastBridge.json");
Expand Down Expand Up @@ -34,17 +33,18 @@ task("method", "Execute Fastbridge methods")
const jsonString = taskArgs.jsonstring;
const json = JSON.parse(jsonString);
const arg = json.arguments;
const functionSignature = json.signature;
const methodName = json.methodname;
const gasLimit = json.gaslimit;
console.log(arg);
const functionArguments = Object.values(arg);
console.log(functionSignature, functionArguments);
const iface = new ethers.utils.Interface(bridgeArtifacts.abi);
const methodArguments = Object.values(arg);
console.log(methodName, methodArguments);
const contractInterface = new ethers.utils.Interface(bridgeArtifacts.abi);
// Send the transaction
const txdata = iface.encodeFunctionData(functionSignature, functionArguments);
const txdata = contractInterface.encodeFunctionData(methodName, methodArguments);
const tx = await signer.sendTransaction({
to: bridgeAddress,
data: txdata,
gasLimit: 999999
gasLimit: gasLimit
});
console.log(tx);
await tx.wait();
Expand Down
6 changes: 4 additions & 2 deletions eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"test:mainnet-fork": "npx hardhat test --network hardhat",
"node": "npx hardhat node",
"dev:size-contracts": "npm run compile-all && npx hardhat size-contracts",
"deploy:all": "npx hardhat run scripts/deployment/",
"deploy:test-tokens": "npm run compile-all && npx hardhat run scripts/deployment/deploy-test-tokens.js --network goerli",
"deploy:all": "npx hardhat run scripts/deployment/ --network",
"deploy:test-tokens": "npm run compile-all && npx hardhat run scripts/deployment/deploy-test-tokens.js --network",
"deploy:bridge": "npm run compile-all && npx hardhat run scripts/deployment/deploy-bridge.js --network ",
"deploy:verify:bridge": "npm run compile-all && npx hardhat run scripts/EthErc20FastBridge/deploy_and_verify_bridge.js --network",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work for me:

olga@olga-ThinkPad-P14s-Gen-2a:~/Aurora/spectre-bridge-protocol/eth$ yarn run deploy:verify:bridge -- goerli
yarn run v1.22.19
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ npm run compile-all && npx hardhat run scripts/EthErc20FastBridge/deploy_and_verify_bridge.js --network goerli

> project-name@1.0.0 compile-all
> npx hardhat compile --force

[
  {
    version: '0.8.11',
    settings: {
      optimizer: [Object],
      metadata: [Object],
      outputSelection: [Object]
    }
  }
]
Compiled 25 Solidity files successfully
[
  {
    version: '0.8.11',
    settings: {
      optimizer: [Object],
      metadata: [Object],
      outputSelection: [Object]
    }
  }
]
Verifing Contract
Sleeping before verification...
0x5FB5a3EED9a8C1F4a49005EeE0930F79C2f1d669
Verifying implementation: 0xdEeDfE06F6331ff22FfB9BC5647CB5cDddB7f309
[
  {
    version: '0.8.11',
    settings: {
      optimizer: [Object],
      metadata: [Object],
      outputSelection: [Object]
    }
  }
]
Nothing to compile
ProviderError: HttpProviderError
    at HttpProvider.request (/home/olga/Aurora/spectre-bridge-protocol/eth/node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
    at LocalAccountsProvider.request (/home/olga/Aurora/spectre-bridge-protocol/eth/node_modules/hardhat/src/internal/core/providers/accounts.ts:181:36)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at EthersProviderWrapper.send (/home/olga/Aurora/spectre-bridge-protocol/eth/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
Successfully submitted source code for contract
contracts/EthErc20FastBridge.sol:EthErc20FastBridge at 0xdEeDfE06F6331ff22FfB9BC5647CB5cDddB7f309
for verification on the block explorer. Waiting for verification result...

Successfully verified contract EthErc20FastBridge on Etherscan.
https://goerli.etherscan.io/address/0xdEeDfE06F6331ff22FfB9BC5647CB5cDddB7f309#code
Verifying proxy: 0x5FB5a3EED9a8C1F4a49005EeE0930F79C2f1d669
Contract at 0x5FB5a3EED9a8C1F4a49005EeE0930F79C2f1d669 already verified.
Linking proxy 0x5FB5a3EED9a8C1F4a49005EeE0930F79C2f1d669 with implementation
Successfully linked proxy to implementation.

Proxy fully verified.
bridge deployed to 0x009C78a3a755EdD77242E260f37368180bBfD0f7
bridge_implementation deployed to 0xdEeDfE06F6331ff22FfB9BC5647CB5cDddB7f309
Deployment is completed.
Verifing Contract
Sleeping before verification...
0x009C78a3a755EdD77242E260f37368180bBfD0f7
Verifying implementation: 0xdEeDfE06F6331ff22FfB9BC5647CB5cDddB7f309
[
  {
    version: '0.8.11',
    settings: {
      optimizer: [Object],
      metadata: [Object],
      outputSelection: [Object],
      libraries: {}
    }
  }
]
Compiled 25 Solidity files successfully
Implementation 0xdEeDfE06F6331ff22FfB9BC5647CB5cDddB7f309 already verified.
Verifying proxy: 0x009C78a3a755EdD77242E260f37368180bBfD0f7
Verification failed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this function works 50/50. Sometimes it works, but sometimes returns strange errors. Looks like a race condition.

Do we really need this function? We already have a command to deploy and verify. I am not sure that it is worth to debug it. What do you think?

"verify:bridge": "npm run compile-all && npx hardhat run scripts/EthErc20FastBridge/verify.js --network",
"upgrade:bridge": "npm run compile-all && npx hardhat run scripts/EthErc20FastBridge/upgrade_bridge.js --network ",
"dev:abi": "npx hardhat clear-abi && npx hardhat export-abi",
"dev:coverage": "npx hardhat coverage",
Expand Down Expand Up @@ -72,6 +73,7 @@
"mocha": "^10.2.0",
"prettier": "^2.8.1",
"prettier-plugin-solidity": "^1.1.0",
"prompt-sync": "^4.2.0",
"shx": "^0.3.4",
"solc": "0.8.17",
"solhint": "^3.3.7",
Expand Down
31 changes: 4 additions & 27 deletions eth/scripts/EthErc20FastBridge/deploy_and_verify_bridge.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
const { ethers, upgrades } = require("hardhat");
const { getAddressSaver, verify } = require("../deployment/utilities/helpers");
const { getImplementationAddress } = require("@openzeppelin/upgrades-core");
const path = require("path");
const { deployBridge } = require("../deployment/deploy-bridge");
const { verifyBridge } = require("./verify");

const main = async () => {
const [deployer] = await ethers.getSigners();
const network = (await ethers.getDefaultProvider().getNetwork()).name;
const addressesPath = path.join(__dirname, "../deployment/deploymentAddresses.json");
const saveAddress = getAddressSaver(addressesPath, network, true);

const tokensAddresses = Object.values(require("../deployment/deploymentAddresses.json").tokens);
const whitelistedTokens = Object.values(require("../deployment/deploymentAddresses.json").whitelisted_tokens);

const bridge = await ethers.getContractFactory("EthErc20FastBridge", deployer);
const Bridge = await upgrades.deployProxy(bridge, [tokensAddresses, whitelistedTokens], {
unsafeAllow: ["delegatecall"]
});
await Bridge.deployed();

saveAddress("bridge_proxy", Bridge.address); // save bridge address

const currentImplAddress = await getImplementationAddress(ethers.provider, Bridge.address);

saveAddress("bridge_Implementation", currentImplAddress); // save implementation address

await deployBridge();
// verify
console.log("Verifing Contract");
await verify(Bridge.address, [tokensAddresses, whitelistedTokens]);
console.log("Verified.");
await verifyBridge();
};

main().catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions eth/scripts/EthErc20FastBridge/interact_with_bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const {
addTokenToWhitelist,
removeTokenFromWhitelist,
isTokenInWhitelist
} = require("./whitelistTokens");
} = require("./whitelist_tokens");
const { pauseTransfer, unpauseTransfer } = require("./pause_unpause");
const { withdrawStuckTokens } = require("./withdraw_Stuck_tokens");
const { withdrawStuckTokens } = require("./withdraw_stuck_tokens");
const prompt = require("prompt-sync")();

async function main() {
Expand Down
2 changes: 1 addition & 1 deletion eth/scripts/EthErc20FastBridge/pause_unpause.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getBridgeContract } = require("./whitelistTokens");
const { getBridgeContract } = require("../utilities/helpers");

async function pauseTransfer(signer) {
let bridge;
Expand Down
18 changes: 18 additions & 0 deletions eth/scripts/EthErc20FastBridge/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { verify } = require("../utilities/helpers");

const main = async () => {
const tokensAddresses = Object.values(require("../deployment/deploymentAddresses.json").tokens);
const whitelistedTokens = Object.values(require("../deployment/deploymentAddresses.json").whitelisted_tokens);
const network = (await ethers.getDefaultProvider().getNetwork());
const bridgeAddress = require("../deployment/deploymentAddresses.json")[network.name].new.bridge;

console.log("Verifing Contract");
await verify(bridgeAddress, [tokensAddresses, whitelistedTokens]);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

exports.verifyBridge = main
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
const { ethers } = require("hardhat");
const deploymentAddress = require("../deployment/deploymentAddresses.json");

async function getBridgeContract() {
console.log("Connecting with bridge...");
const network = (await ethers.getDefaultProvider().getNetwork()).name;
const bridgeAddress = deploymentAddress[network].new.bridge_proxy;
const bridge = ethers.getContractAt("/contracts/EthErc20FastBridge.sol:EthErc20FastBridge", bridgeAddress);
console.log("Connected !");
return bridge;
}
const { getBridgeContract } = require("../utilities/helpers.js")

async function bulkWhitelistStatusUpdate(tokensArray, statusArray, signer) {
let bridge;
Expand Down
4 changes: 2 additions & 2 deletions eth/scripts/EthErc20FastBridge/withdraw_Stuck_tokens.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { getBridge } = require("./whitelistTokens");
const { getBridgeContract } = require("../utilities/helpers");

async function withdrawStuckTokens(signer) {
let bridge;
try {
bridge = await getBridge();
bridge = await getBridgeContract();
await bridge.connect(signer).withdrawStuckTokens();
} catch (error) {
console.log("Failed to withdraw", error);
Expand Down
12 changes: 10 additions & 2 deletions eth/scripts/deployment/deploy-bridge.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { ethers, upgrades } = require("hardhat");
const { verify, getAddressSaver } = require("./utilities/helpers");
const { getAddressSaver } = require("../utilities/helpers");
const { getImplementationAddress } = require("@openzeppelin/upgrades-core");
const path = require("path");

async function main() {
const [deployer] = await ethers.getSigners();
const network = (await ethers.getDefaultProvider().getNetwork()).name;
const addressesPath = path.join(__dirname, "./deploymentAddresses.json");
const saveAddress = getAddressSaver(addressesPath, network, true);

const tokensAddresses = Object.values(require("./deploymentAddresses.json").tokens);
const whitelistedTokens = Object.values(require("./deploymentAddresses.json").whitelisted_tokens);
const bridge = (await ethers.getContractFactory("EthErc20FastBridge")).connect(deployer);
Expand All @@ -17,10 +18,17 @@ async function main() {
await proxy.deployed();

saveAddress("bridge", proxy.address);

const currentImplAddress = await getImplementationAddress(ethers.provider, proxy.address);

saveAddress("bridge_implementation", currentImplAddress); // save implementation address

console.log("Deployment is completed.");
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

exports.deployBridge = main
4 changes: 3 additions & 1 deletion eth/scripts/deployment/deploy-test-tokens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ethers, upgrades } = require("hardhat");
const { verify, getAddressSaver } = require("./utilities/helpers");
const { getAddressSaver } = require("../utilities/helpers");
const path = require("path");
const { test } = require("mocha");

Expand Down Expand Up @@ -31,3 +31,5 @@ main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

exports.deployTestToken = main
14 changes: 14 additions & 0 deletions eth/scripts/deployment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const {deployBridge} = require("./deploy-bridge");
const {deployTestToken} = require("./deploy-test-tokens");

const main = async () => {
console.log("deploying test tokens");
await deployTestToken();
console.log("deploying bridge with tokens whitelisted");
await deployBridge();
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const hre = require("hardhat");
const fs = require("fs");
const { ethers } = hre;
const deploymentAddress = require("../deployment/deploymentAddresses.json");

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand All @@ -10,12 +11,10 @@ async function verify(address, args) {
if (hre.network.name !== "hardhat" && hre.network.name !== "localhost") {
let retry = 20;
console.log("Sleeping before verification...");
while ((await ethers.provider.getCode(address).catch(() => "")).length <= 3 && retry >= 0) {
while ((await ethers.provider.getCode(address).catch((err) => console.log("err", err))).length <= 3 && retry >= 0) {
await sleep(5000);
--retry;
}
await sleep(30000);

console.log(address, args);

await hre
Expand Down Expand Up @@ -51,6 +50,16 @@ function getAddressSaver(path, network, isLog) {
return saveAddress;
}

async function getBridgeContract() {
console.log("Connecting with bridge...");
const network = (await ethers.getDefaultProvider().getNetwork()).name;
const bridgeAddress = deploymentAddress[network].new.bridge;
const bridge = await ethers.getContractAt("/contracts/EthErc20FastBridge.sol:EthErc20FastBridge", bridgeAddress);
console.log("Connected !");
return bridge;
}

exports.sleep = sleep;
exports.verify = verify;
exports.getAddressSaver = getAddressSaver;
exports.getBridgeContract = getBridgeContract;