Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
110 changes: 1 addition & 109 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,112 +22,4 @@ The bridge consist of three main components:
Described in the corresponding [README](eth/README.md)

### Near
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.
1. First copy content of `.env.example` file
2. Create a new file in `spectere-bridge-protocol` 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`**

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`
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`

### Deploy and verify
Running this script will first deploy and then verify bridge.
To execute this script => run command `yarn run deploy:verify:bridge -- <network-name>`
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 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 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.

* To whitelist one token import and use method `addTokenToWhitelist` from above mentioned file with a token address and a signer with `WHITELISTING_TOKENS_ADMIN_ROLE` as parameters.

* To remove one token from whitelist use method `removeTokenFromWhitelist` from above mentioned file with tokens address and signer with `WHITELISTING_TOKENS_ADMIN_ROLE` as parameters.

* To check whether a token is whitelisted or not import and use method `isTokenInWhitelist` from above mentioned file with tokens address and signer with `WHITELISTING_TOKENS_ADMIN_ROLE` as parameters.

example : If you want whitelist whitelist one token, script would like,
```
const { ethers } = require("hardhat");
const { addTokenToWhitelist } = require("./whitelistTokens");

const WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";

async function main() {
const [signer] = await ethers.getSigners(); // signer must have WHITELISTING_TOKENS_ADMIN_ROLE
await addTokenToWhitelist(WETH, signer);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
```
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 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`
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
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`)

### To interact with FastBridge using hardhat task
To call any method of EthErc20FastBridge use hardhat task `method`
Run command `npx hardhat method --jsonstring <json_string_input>`
```
to create `json_string_input`
1. create json with `signature` and `arguments` properties in below example format

{
"signature": "setWhitelistedTokens(address[],bool[])",
"argcount": "2",
"arguments": {
"arg1": [
"0xdAC17F958D2ee523a2206206994597C13D831ec7",
"0xB8c77482e45F1F44dE1745F52C74426C631bDD52",
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
],
"arg2": [
true,
true,
true
]
}
}

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]}}'`
Described in the corresponding [README](near/README.md)
1 change: 1 addition & 0 deletions eth/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RINKEBY_URL =
ROPSTEN_URL =
KOVAN_URL =
FORKING_URL =
TASK_RPC_URL =

ETHERSCAN_API_KEY =
ETHERSCAN_URL =
Expand Down
114 changes: 110 additions & 4 deletions eth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,121 @@ npm i
npm run test:mainnet-fork
```

To generate the flatten contracts and storage layout
To generate the flatten contracts and storage layout
```
npm run flatten
npm run storage-layout
```

## EthErc20FastBridge scripts
This section will help users to deploy and interact with the fast-bridge contract.

### Setup
Before using helper scripts to deploy and interact with the contract, you should set up the environment variables.
The full list of environment variables is provided in `.env.example` file.
Usually, you don't need to set up all of them. To figure out what you need, you can take a closer look at `hardhat.config.js` file.

For example, for interacting with the contract on Goerli network it will be enough to set up:
* `PRIVATE_KEY`. For Goerli network, you can extract it from MetaMask
* `INFURA_API_KEY`. You will need to create account on https://www.infura.io/ and create the endpoint for goerli network.

For convenience, you can create a file `.env` and set the environment variables there, just like in a `.env.example` file.

**WARNING:** Be careful not to accidentally commit this file to git.

### Deploy
Deployment is configured only for `Goerli` testnet and could be done with the following scirpt
You can deploy the contracts to the `Goerli` testnet by using the following commands:
```
npm run deploy:test-tokens -- goerli
npm run deploy:bridge -- goerli
```

After running this scripts the proxy and implementation addresses of `EthErc20FastBridge` will be stored in `scripts/deployment/deploymentAddresses.json` file.

### Deploy and verify
To deploy and verify the fast bridge on goerli network use the following command:

```
yarn run deploy:verify:bridge -- goerli
```

For using this command you will also need to set up the following env variable:
* `ETHERSCAN_API_KEY`

By using this command the `scripts/EthErc20FastBridge/deploy_and_verify_bridge.js` script will be executed.

### Upgrade script
To upgrade bridge contract(using hardhat's upgrades plugin) run:
```
yarn run upgrade:bridge -- goerli
```

For using this command you will also need to set up the following env variable:
* `BRIDGE_PROXY_ADDRESS` -- the Ethereum Fast Bridge Proxy address started with `0x`

By using this command the `scripts/EthErc20FastBridge/upgrade_bridge.js` script will be executed.

### Whitelisting
To interact with EthErc20FastBridge whitelisting methods you can write your own JS script and use
functions from `scripts/EthErc20FastBridge/whitelist_tokens.js`.

The example of script to whitelist one token:
```javascript
const { ethers } = require("hardhat");
const { addTokenToWhitelist } = require("./whitelist_tokens");

const WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";

async function main() {
const [signer] = await ethers.getSigners(); // signer must have WHITELISTING_TOKENS_ADMIN_ROLE
await addTokenToWhitelist(WETH, signer);
}

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

The command to run this script:
```
npx hardhat run <path_to_script/script.js>
```

`scripts/EthErc20FastBridge/whitelist_tokens.js` functions:
* `bulkWhitelistStatusUpdate` -- bulk update whitelist status of tokens.
* `addTokenToWhitelist` -- whitelist one token.
* `removeTokenFromWhitelist` -- remove one token from whitelist.
* `isTokenInWhitelist` -- check whether a token is whitelisted or not.


### Pause/Unpause transfers
To interact with EthErc20FastBridge pause and unpause methods you can write your own JS script and use
functions from `scripts/EthErc20FastBridge/pause_unpause.js`.

Methods:
* `pauseTransfer` -- to pause all operations in Fast Bridge
* `unpauseTransfer` -- to unpause all the operations in Fast Bridge.

### To interact with above methods use script `fast-bridge-protocol/eth/scripts/EthErc20FastBridge/interact_with_bridge.js`
You can interact with Fast Bridge in goerli by running:
```bash
npm run interact:bridge -- goerli
```

Note: bridge address will be picked from `fast-bridge-protocol/eth/scripts/deployment/deploymentAddresses.json`


### To interact with FastBridge using hardhat task
You can execute any EthErc20FastBridge method by running:
```bash
npx hardhat method --jsonstring <json_string_input>
```
npm run deploy:test-tokens
npm run deploy:bridge

For example:
```
npx hardhat method --jsonstring '{"methodName":"setWhitelistedTokens","arguments":{"arg1":["0xdAC17F958D2ee523a2206206994597C13D831ec7"],"arg2":[true]}}' --network goerli
```

You should set up the following env variable:
* `TASK_RPC_URL`
17 changes: 8 additions & 9 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 All @@ -28,23 +27,23 @@ task("method", "Execute Fastbridge methods")
.setAction(async (taskArgs) => {
const network = (await ethers.getDefaultProvider().getNetwork()).name;
const bridgeAddress = deploymentAddress[network].new.bridge;
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_TASK);
const provider = new ethers.providers.JsonRpcProvider(process.env.TASK_RPC_URL);
const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

const jsonString = taskArgs.jsonstring;
const json = JSON.parse(jsonString);
const arg = json.arguments;
const functionSignature = json.signature;
console.log(arg);
const functionArguments = Object.values(arg);
console.log(functionSignature, functionArguments);
const iface = new ethers.utils.Interface(bridgeArtifacts.abi);
const methodName = json.methodName;
const gasLimit = json.gasLimit;
const methodArguments = Object.values(arg);
console.log(`calling method ${methodName} with arguments ${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
7 changes: 5 additions & 2 deletions eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"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/deploy_testnet_bridge_with_test_tokens.js --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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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 ",
"interact:bridge" : "npm run interact:bridge",
"dev:abi": "npx hardhat clear-abi && npx hardhat export-abi",
"dev:coverage": "npx hardhat coverage",
"docgen": "npx shx rm -rf docs && npx solidity-docgen --solc-module solc -t docgen -H docgen/helpers.js -o docs/",
Expand Down Expand Up @@ -72,6 +74,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_tokens_stuck");
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]);
Comment thread
olga24912 marked this conversation as resolved.
}

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

exports.verifyBridge = main
Loading