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
111 changes: 85 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,89 @@ Follow below steps to execute script and start interacting
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
]
1. To call any method of EthErc20FastBridge use hardhat task `method`
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest removing this generic task and creating separate hardhat tasks for each contract method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have implemented separate tasks for each contract method in this PR, just not removed this generic function which could work as add-on functionality. Please let me know if you differ from this thought. I can remove the generic task.

Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation for methods transferTokens and withdrawStuckTokens is missed. This tasks also can be useful for debugging.

I prefer to remove the generic method, but it is up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
``` bash
{
"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]}}'`
```
2. pass below json to JSON.stringify() and use output as `json_string_input`


For example: to call `setWhitelistedTokens` method run command
``` bash
npx hardhat method --jsonstring '{"signature":"setWhitelistedTokens","arguments":{"arg1":["0xdAC17F958D2ee523a2206206994597C13D831ec7"],"arg2":[true]}}'
```

2. To deploy fast-bridge run
``` bash
npx hardhat deploy_fastbridge --verification <bool> --network <network_name>
```
here `--verification` is an optional parameter with default value `false` if passed `true` than contract is verified just after the deployment.
3. To verify already deployed contract on same network run
``` bash
npx hardhat verify_bridge --proxyaddress <fastbridge_proxy_address> --network <network_name>
```
4. To whitelists single erc20 token in fast-bridge run `npx hardhat whitelists_token --tokenaddress <token_address> --network <network_name>`, here the pvt key of signer need to have the authorised role to make successful txn and key is picked from .env file so you need to setup it before running the cmd.
<br>For example:
``` bash
npx hardhat whitelists_token --tokenaddress 0xb2d75C5a142A68BDA438e6a318C7FBB2242f9693 --network mumbai
```
5. To whitelists token in bulk run
``` bash
npx hardhat whitelists_token_in_bulk --tokenaddresses <comma_separated_token_addresses> --whiteliststatus <comma_separated_bool_value> --network <network_name>
```
*For example*:-
``` bash
npx hardhat whitelists_token_in_bulk --tokenaddresses 0xF0b0c5E2c3A35213992bD9b45Af352D6D4035203,0xaa2D6608241B6B930BCcaFE245eFDf052e46C9aA --whiteliststatus true,true,true --network mumbai
```
Here also signer need to have the access role to make txn successful.
6. To check whether the token is whitelisted or not run
``` bash
npx hardhat is_token_whitelisted --tokenaddress <token_address> --bridgeproxyaddress <fastbridge_proxy_address> --network <network_name>
```
7. To remove token from whitelists run
``` bash
npx hardhat remove_token_from_whitelists --tokenaddress <token_address> --network <network_name>
```
For example:
``` bash
npx hardhat remove_token_from_whitelists --tokenaddress 0xb2d75C5a142A68BDA438e6a318C7FBB2242f9693 --network mumbai
```
8. To pause fast_bridge run
``` bash
npx hardhat pause_fastbridge --network <network_name>
```
here the signer needs to have desired role to do so.
9. To unpause fast_bridge run
``` bash
npx hardhat unpause_fastbridge --network <network_name>
```
here also the signer needs to have proper access role to do so.
10. To upgrade the fastbridge run
``` bash
npx hardhat upgrade_fastbridge --network <network_name>
```
here the signer needs to have the proper admin role to upgrade the fast-bridge contract.
11. To withdraw stucked erc-20 tokens on fastbridge run:-
``` bash
npx hardhat withdraw_stuck_tokens --tokenaddress <erc-20 address> --network <network_name>
```
Here, the caller must have `DEFAULT_ADMIN_ROLE` to make withdraw success.
46 changes: 9 additions & 37 deletions eth/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ 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");
require('hardhat-storage-layout');

require("./scripts/EthErc20FastBridge/tasks.js");
require("hardhat-storage-layout");

const PRIVATE_KEYS = process.env.PRIVATE_KEYS ? process.env.PRIVATE_KEYS.split(",") : [];
const PRIVATE_KEY = process.env.PRIVATE_KEY || "11".repeat(32);
Expand All @@ -23,35 +19,6 @@ const FORKING = true;
const ENABLED_OPTIMIZER = true;
const OPTIMIZER_RUNS = 200;

task("method", "Execute Fastbridge methods")
.addParam("jsonstring", "JSON string with function signature and arguments")
.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 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);
// Send the transaction
const txdata = iface.encodeFunctionData(functionSignature, functionArguments);
const tx = await signer.sendTransaction({
to: bridgeAddress,
data: txdata,
gasLimit: 999999
});
console.log(tx);
await tx.wait();

console.log("Transaction mined!");
});

module.exports = {
solidity: {
version: "0.8.11",
Expand Down Expand Up @@ -97,6 +64,12 @@ module.exports = {
? `https://goerli.infura.io/v3/${INFURA_API_KEY}`
: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
accounts: [`${PRIVATE_KEY}`]
},
mumbai: {
url: INFURA_API_KEY
? `https://mumbai.infura.io/v3/${INFURA_API_KEY}`
: `https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
accounts: [`${PRIVATE_KEY}`]
}
},
gasReporter: {
Expand All @@ -120,5 +93,4 @@ module.exports = {
if (process.env.FORKING_BLOCK_NUMBER)
module.exports.networks.hardhat.forking.blockNumber = +process.env.FORKING_BLOCK_NUMBER;

if (process.env.HARDFORK)
module.exports.networks.hardhat.hardfork = process.env.HARDFORK;
if (process.env.HARDFORK) module.exports.networks.hardhat.hardfork = process.env.HARDFORK;
57 changes: 57 additions & 0 deletions eth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"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: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",
"upgrade:bridge": "npm run compile-all && npx hardhat run scripts/EthErc20FastBridge/upgrade_bridge.js --network ",
"deploy:bridge": "npx hardhat deploy_fastbridge --network ",
"deploy:verify:bridge": "npx hardhat deploy_fastbridge --verification true --network ",
"upgrade:bridge": "npx hardhat upgrade_fastbridge --network ",
"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 @@ -69,16 +69,17 @@
"hardhat": "^2.12.4",
"hardhat-abi-exporter": "^2.10.1",
"hardhat-contract-sizer": "^2.6.1",
"hardhat-storage-layout": "^0.1.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",
"solhint-plugin-prettier": "^0.0.5",
"solidity-docgen": "0.5.17",
"web3": "^1.8.1",
"hardhat-storage-layout": "^0.1.7"
"web3": "^1.8.1"
},
"engines": {
"node": ">= 16.0.0",
Expand Down
36 changes: 0 additions & 36 deletions eth/scripts/EthErc20FastBridge/deploy_and_verify_bridge.js

This file was deleted.

2 changes: 1 addition & 1 deletion eth/scripts/EthErc20FastBridge/interact_with_bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main() {
console.log("to execute bulkWhitelistStatusUpdate(tokensArray, statusArray, signer)");
const inputTokens = prompt("please enter space separated token addresses : ");
let addressArray = inputTokens.trim().split(" ");
const inputStatuses = prompt("please enter space separated token addresses : ");
const inputStatuses = prompt("please enter space separated token whitelists status in bool : ");
let statusArray = inputStatuses.trim().split(" ");
console.log(addressArray);

Expand Down
Loading