-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge-contracts.sh
236 lines (184 loc) · 7.34 KB
/
bridge-contracts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
echo "Setting up Project Directory..."
npm init -y
npm install --save-dev hardhat
npx hardhat
echo "Installing necessary dependencies..."
sudo apt update && sudo apt upgrade -y
npm install --save-dev @nomicfoundation/hardhat-toolbox
npm install --save-dev dotenv
echo "Configuring hardhat.config.js file..."
cat > hardhat.config.js <<EOL
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.28",
networks: {
opSepolia: {
url: "https://sepolia.optimism.io/",
accounts: [process.env.PRIVATE_KEY]
},
baseSepolia: {
url: "https://sepolia.base.org/",
accounts: [process.env.PRIVATE_KEY]
},
blastSepolia: {
url: "https://endpoints.omniatech.io/v1/blast/sepolia/public",
accounts: [process.env.PRIVATE_KEY]
},
arbSepolia: {
url: "https://arbitrum-sepolia-rpc.publicnode.com",
accounts: [process.env.PRIVATE_KEY]
}
}
};
EOL
echo "Setting Up Private Key..."
echo "Enter your Private Key:"
read PRIVATE_KEY
echo "PRIVATE_KEY=$PRIVATE_KEY" > .env
echo "Coding The Smart Contract..."
cat > contracts/bridge.sol <<EOL
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function transfer(address recipient, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
contract AutoBridgeReceiver {
address public immutable owner;
event ReceivedETH(address indexed sender, uint256 amount);
event ERC20Transferred(address indexed token, address indexed to, uint256 amount);
event TokensProcessed(address indexed token, uint256 amount);
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}
constructor() {
owner = msg.sender;
}
function processIncomingTokens(address token) public {
uint256 balance = IERC20(token).balanceOf(address(this));
require(balance > 0, "No tokens to process");
bool success = IERC20(token).transfer(owner, balance);
require(success, "Token transfer failed");
emit TokensProcessed(token, balance);
}
receive() external payable {
emit ReceivedETH(msg.sender, msg.value);
(bool success, ) = owner.call{value: msg.value}("");
require(success, "ETH transfer failed");
}
function emergencyWithdrawETH() external onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, "No ETH to withdraw");
(bool success, ) = owner.call{value: balance}("");
require(success, "ETH transfer failed");
}
function emergencyWithdrawERC20(address token) external onlyOwner {
uint256 balance = IERC20(token).balanceOf(address(this));
require(balance > 0, "No tokens to withdraw");
bool success = IERC20(token).transfer(owner, balance);
require(success, "Token transfer failed");
}
fallback() external payable {
emit ReceivedETH(msg.sender, msg.value);
(bool success, ) = owner.call{value: msg.value}("");
require(success, "ETH transfer failed");
}
}
EOL
echo "Creating Deployment Files..."
mkdir scripts
cat > scripts/deployonbase.js <<EOL
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
console.log("Deploying contract with account:", deployer.address);
const AutoBridgeReceiver = await hre.ethers.getContractFactory("AutoBridgeReceiver");
console.log("Deploying bridge contract...");
const receiver = await AutoBridgeReceiver.deploy();
console.log("Deployment in Progress...");
await receiver.waitForDeployment();
const contractAddress = await receiver.getAddress();
const txHash = receiver.deploymentTransaction().hash;
console.log("Bridge contract for base sepolia to op sepolia deployed -->", contractAddress);
console.log("Transaction link: https://sepolia.basescan.org/tx/" + txHash);
}
main().catch((error) => {
console.error("Deployment failed:", error);
process.exit(1);
});
EOL
cat > scripts/deployonop.js <<EOL
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
console.log("Deploying contract with account:", deployer.address);
const AutoBridgeReceiver = await hre.ethers.getContractFactory("AutoBridgeReceiver");
console.log("Deploying bridge contract...");
const receiver = await AutoBridgeReceiver.deploy();
console.log("Deployment in Progress...");
await receiver.waitForDeployment();
const contractAddress = await receiver.getAddress();
const txHash = receiver.deploymentTransaction().hash;
console.log("Bridge contract for op sepolia to base sepolia deployed -->", contractAddress);
console.log("Transaction link: https://sepolia-optimism.etherscan.io/tx/" + txHash);
}
main().catch((error) => {
console.error("Deployment failed:", error);
process.exit(1);
});
EOL
cat > scripts/deployonblast.js <<EOL
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
console.log("Deploying contract with account:", deployer.address);
const AutoBridgeReceiver = await hre.ethers.getContractFactory("AutoBridgeReceiver");
console.log("Deploying bridge contract...");
const receiver = await AutoBridgeReceiver.deploy();
console.log("Deployment in Progress...");
await receiver.waitForDeployment();
const contractAddress = await receiver.getAddress();
const txHash = receiver.deploymentTransaction().hash;
console.log("Bridge contract for blast sepolia to base/arb/op deployed -->", contractAddress);
console.log("Transaction link: https://sepolia.blastscan.io/tx/" + txHash);
}
main().catch((error) => {
console.error("Deployment failed:", error);
process.exit(1);
});
EOL
cat > scripts/deployonarb.js <<EOL
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
console.log("Deploying contract with account:", deployer.address);
const AutoBridgeReceiver = await hre.ethers.getContractFactory("AutoBridgeReceiver");
console.log("Deploying bridge contract...");
const receiver = await AutoBridgeReceiver.deploy();
console.log("Deployment in Progress...");
await receiver.waitForDeployment();
const contractAddress = await receiver.getAddress();
const txHash = receiver.deploymentTransaction().hash;
console.log("Bridge contract for arb sepolia to base sepolia -->", contractAddress);
console.log("Transaction link: https://sepolia.arbiscan.io/tx/" + txHash);
}
main().catch((error) => {
console.error("Deployment failed:", error);
process.exit(1);
});
EOL
echo "Compiling the Contract..."
npx hardhat compile
echo "Deploying Contracts On Each Network..."
npx hardhat run scripts/deployonbase.js --network baseSepolia
npx hardhat run scripts/deployonop.js --network opSepolia
npx hardhat run scripts/deployonblast.js --network blastSepolia
npx hardhat run scripts/deployonarb.js --network arbSepolia
echo "Part 1 - Completed!"
echo "Ensure You Save The Above Contract Address Somewhere, It'll Be Used In Part 2!"
echo "Follow @willzydollarrzz On X For More Guides Like This!"