Skip to content

Commit

Permalink
chore: update and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OnahProsperity committed Nov 26, 2024
2 parents 00a0c26 + 914a8ce commit de002d4
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 17 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,26 @@ npx hardhat run scripts/tron/updateProtocolFee.ts
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td rowspan="2">Polygon Amoy</td>
<td>Gateway Proxy</td>
<td>0xCAD53Ff499155Cc2fAA2082A85716322906886c2</td>
</tr>
<tr>
<td>Gateway Implementation</td>
<td>0xd2d97002ec87ba57fcf3f6b510f20d5a80a6c33a</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td rowspan="2">Arbitrum Sepolia</td>
<td>Gateway Proxy</td>
<td>0x87B321fc77A0fDD0ca1fEe7Ab791131157B9841A</td>
</tr>
<tr>
<td>Gateway Implementation</td>
<td>0xD01abCEEeacfC91d2eCE31422DFe531004A7D2e6</td>
<td>0xd2d97002Ec87ba57FCf3f6b510f20d5A80A6C33a</td>
</tr>
<tr>
<td colspan="3"></td>
Expand All @@ -98,7 +110,7 @@ npx hardhat run scripts/tron/updateProtocolFee.ts
</tr>
<tr>
<td>Gateway Implementation</td>
<td>0xfB411Cc6385Af50A562aFCb441864E9d541CDA67</td>
<td>0xd2d97002Ec87ba57FCf3f6b510f20d5A80A6C33a</td>
</tr>
<tr>
<td colspan="3"></td>
Expand Down Expand Up @@ -185,7 +197,7 @@ npx hardhat run scripts/tron/updateProtocolFee.ts
</tr>
<tr>
<td>Gateway Implementation</td>
<td>0x647daC4807Eb82E67CE3bca930D6202190831B4a</td>
<td>0x8fd1f78d88dd008e557273b5cd517487c2a9a7de</td>
</tr>
<tr>
<td colspan="3"></td>
Expand All @@ -197,7 +209,7 @@ npx hardhat run scripts/tron/updateProtocolFee.ts
</tr>
<tr>
<td>Gateway Implementation</td>
<td>0x847dfdAa218F9137229CF8424378871A1DA8f625</td>
<td>0xd2d97002Ec87ba57FCf3f6b510f20d5A80A6C33a</td>
</tr>
<tr>
<td>Gateway Admin</td>
Expand All @@ -213,7 +225,7 @@ npx hardhat run scripts/tron/updateProtocolFee.ts
</tr>
<tr>
<td>Gateway Implementation</td>
<td>0x5E7eC39915F6CD48829d06648F6682765846602a</td>
<td>0xd2d97002ec87ba57fcf3f6b510f20d5a80a6c33a</td>
</tr>
<tr>
<td>Gateway Admin</td>
Expand Down
6 changes: 3 additions & 3 deletions scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const NETWORKS = {
},
TREASURY_FEE_PERCENT: 100, // in BPS i.e 0.1%
GATEWAY_CONTRACT: "0x1FA0EE7F9410F6fa49B7AD5Da72Cf01647090028",
IMPERSONATE_ACCOUNT: "",
},

/**
Expand Down Expand Up @@ -154,10 +153,11 @@ const NETWORKS = {
* @dev Base Sepolia
*/
84532: {
GATEWAY_IMPLEMENTATION: "0xff0E00E0110C1FBb5315D276243497b66D3a4d8a",
RPC_URL: `https://rpc.shield3.com/v3/0x14a34/${SHIELD3_API_KEY}/rpc`,
SUPPORTED_TOKENS: {
USDC: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
DAI: "0x7683022d84f726a96c4a6611cd31dbf5409c0ac9",
DAI: "0x7683022d84f726a96c4a6611cd31dbf5409c0ac9",
},
TREASURY_FEE_PERCENT: 100, // in BPS i.e 0.1%
GATEWAY_CONTRACT: "0x847dfdAa218F9137229CF8424378871A1DA8f625",
Expand All @@ -171,7 +171,7 @@ const NETWORKS = {
RPC_URL: `https://rpc.shield3.com/v3/0xaa36a7/${SHIELD3_API_KEY}/rpc`,
SUPPORTED_TOKENS: {
"6TEST": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B",
DAI: "0x77Ab54631BfBAE40383c62044dC30B229c7df9f5",
DAI: "0x77Ab54631BfBAE40383c62044dC30B229c7df9f5",
},
TREASURY_FEE_PERCENT: 100, // in BPS i.e 0.1%
GATEWAY_CONTRACT: "0xCAD53Ff499155Cc2fAA2082A85716322906886c2",
Expand Down
22 changes: 15 additions & 7 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, upgrades, network } from "hardhat";
import { confirmContinue, assertEnvironment } from "./utils";
import { confirmContinue, assertEnvironment, waitForInput, updateConfigFile } from "./utils";
import hre from "hardhat";

assertEnvironment();
Expand All @@ -19,10 +19,10 @@ async function deployGatewayProxy(): Promise<any> {

console.log("✅ Deployed Gateway: ", tx.transactionHash);

// const implementationAddress = await contract.implementation();

if (network.config.chainId !== undefined) {
await updateConfigFile(network.config.chainId, contract.address);
}
console.log(`Proxy Contract Address: ${contract.address}`);
// console.log("Implementation Contract Address:", implementationAddress);

return tx;
}
Expand All @@ -46,16 +46,24 @@ async function deployGateway(): Promise<any> {
address: contract.address,
});

if (network.config.chainId !== undefined) {
await updateConfigFile(network.config.chainId, contract.address);
}

console.log(`Proxy Contract Address: ${contract.address}`);
// console.log("Implementation Contract Address:", implementationAddress);

return tx;
}


async function main() {
// Deploy Gateway
await deployGateway();
const response = await waitForInput("\nDo you want to deploy a new Gateway proxy? y\n");
const responseStr = response as string; // Cast response to string
if (responseStr.toLowerCase() !== "y") {
await deployGateway();
} else {
await deployGatewayProxy();
}
}

main().catch((error) => {
Expand Down
63 changes: 61 additions & 2 deletions scripts/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ethers, upgrades, network } from "hardhat";
import { NETWORKS } from "./config";
import hre from "hardhat";
import { confirmContinue } from "./utils";
import { confirmContinue, waitForInput } from "./utils";

const networkConfig = NETWORKS[network.config.chainId as keyof typeof NETWORKS];

async function main() {
async function upgradeProxy() {
await confirmContinue({
contract: "Gateway",
network: network.name,
Expand Down Expand Up @@ -40,6 +40,65 @@ async function main() {
}
}

async function manualUpgrade() {
await confirmContinue({
contract: "Gateway",
network: network.name,
chainId: network.config.chainId,
});

try {

const [signer] = await ethers.getSigners(); // Get the signer (the account performing the upgrade)
const balance = await signer.getBalance(); // Get the balance of the signer's address

if (balance.eq(0)) {
throw new Error(`Can't upgrade ${network.config.chainId} with 0 balance`);
}
const proxyContractAddress = networkConfig.GATEWAY_CONTRACT;
const proxy = await ethers.getContractAt("TransparentUpgradeableProxy", proxyContractAddress);
// Get the proxy admin address
const proxyAdminAddress = await proxy.admin();
console.log(`Proxy Admin Address: ${proxyAdminAddress}`);

// Get the Proxy Admin contract
const proxyAdmin = await ethers.getContractAt("ProxyAdmin", proxyAdminAddress);

// Check if IMPLEMENTATION exists in networkConfig
if (!('IMPLEMENTATION' in networkConfig)) {
throw new Error(`No implementation address found for chainId: ${network.config.chainId}`);
}
// Fetch the new implementation address from deployment.json
const newImplementationAddress = networkConfig.IMPLEMENTATION;

if (!newImplementationAddress) {
throw new Error(`No implementation address found for chainId: ${network.config.chainId}`);
}

console.log(`Upgrading proxy to new implementation: ${newImplementationAddress}`);

// Call the upgrade function on the Proxy Admin contract
await proxyAdmin.upgrade(proxyContractAddress, newImplementationAddress);

console.log(`✅ Successfully upgraded proxy at ${proxyContractAddress} to new implementation at ${newImplementationAddress}`);
} catch (error) {
if (error instanceof Error) {
console.error("❌ Upgrade failed: ", error.message);
} else {
console.error("❌ Upgrade failed: Unknown error occurred");
}
}

}

async function main() {
const response = await waitForInput("\nDo you want to deploy and upgrade? y/N\n");
if (response !== "y") {
await manualUpgrade();
} else {
await upgradeProxy();
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
Expand Down
43 changes: 43 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import readline from "readline";
import dotenv from "dotenv";
import { artifacts, ethers, network } from "hardhat";
import { NETWORKS } from "./config";
import { promises as fs } from 'fs';
import * as path from 'path';
const TronWeb = require("tronweb");

dotenv.config();
Expand Down Expand Up @@ -86,6 +88,47 @@ export async function confirmContinue(params: any) {
}


export async function updateConfigFile(chainId: number, implementationAddress: string): Promise<void> {
try {
const configFilePath = path.join(__dirname, 'config.ts');
// Read the existing config file
let configContent = await fs.readFile(configFilePath, 'utf-8');

// Create a regex to match the network object for the specific chainId
const networkRegex = new RegExp(`(${chainId}:\\s*{[\\s\\S]*?)(},?)`, 'g');

if (networkRegex.test(configContent)) {
configContent = configContent.replace(networkRegex, (match) => {
const lines = match.split('\n');
const updatedLines = lines.map(line => {
if (line.trim().startsWith('GATEWAY_IMPLEMENTATION:')) {
return line.replace(/IMPLEMENTATION:.*/, `GATEWAY_IMPLEMENTATION: "${implementationAddress}",`);
}
return line;
});

if (!updatedLines.some(line => line.trim().startsWith('GATEWAY_IMPLEMENTATION:'))) {
// If IMPLEMENTATION doesn't exist, add it before the closing brace
updatedLines.splice(-1, 0, `\t\GATEWAY_IMPLEMENTATION: "${implementationAddress}",`);
}

return updatedLines.join('\n');
});
} else {
console.error(`Network configuration for chainId ${chainId} not found in config file.`);
return;
}

// Write the updated content back to the file
await fs.writeFile(configFilePath, configContent, 'utf-8');

console.log(`Updated config.ts with chainId: ${chainId} and implementation address: ${implementationAddress}`);
} catch (error) {
console.error('Error updating config file:', error);
}
}


/**
* Retrieves the wallet and contract instances.
*
Expand Down

0 comments on commit de002d4

Please sign in to comment.