Skip to content

Commit 7ea2dee

Browse files
committed
feat: added scripts to change owner to new safe wallet and monitor balances
1 parent c775a35 commit 7ea2dee

File tree

2 files changed

+442
-0
lines changed

2 files changed

+442
-0
lines changed

bridge/hardhat/script/changeOwner.js

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// How to run the script: npx hardhat run ./hardhat/script/createRifToken.js --network bsctestnet
2+
const hre = require("hardhat");
3+
4+
async function main() {
5+
const {getNamedAccounts, deployments} = hre;
6+
const {deployer} = await getNamedAccounts();
7+
const network = hre.network.name;
8+
9+
let newWalletAddress = null;
10+
11+
if(network === "rsktestnet") {
12+
newWalletAddress = '0x51591ec8f296ef3e4deebe32c392c706aef42133';
13+
}
14+
if(network === "sepolia") {
15+
newWalletAddress = '0x0d4FC5C4847Eab6e5759656a8e0740Ea64A9582d';
16+
}
17+
18+
if (newWalletAddress === null) {
19+
console.log('No new owner founded');
20+
return;
21+
}
22+
23+
const Bridge = await deployments.get('BridgeV3');
24+
const BridgeProxy = await deployments.get('BridgeProxy');
25+
26+
const Federation = await deployments.get('FederationV2');
27+
const FederationProxy = await deployments.get('FederationProxy');
28+
29+
const AllowTokens = await deployments.get('AllowTokens');
30+
const AllowTokensProxy = await deployments.get('AllowTokensProxy');
31+
32+
const MultiSigWallet = await deployments.get('MultiSigWallet');
33+
34+
const bridge = new web3.eth.Contract(Bridge.abi, BridgeProxy.address);
35+
const federation = new web3.eth.Contract(Federation.abi, FederationProxy.address);
36+
const allowTokens = new web3.eth.Contract(AllowTokens.abi, AllowTokensProxy.address);
37+
const multiSigContract = new web3.eth.Contract(MultiSigWallet.abi, MultiSigWallet.address);
38+
39+
const bridgeOwner = await bridge.methods.owner().call();
40+
const federationOwner = await federation.methods.owner().call();
41+
const allowTokensOwner = await allowTokens.methods.owner().call();
42+
const multiSigOwners = await multiSigContract.methods.getOwners().call();
43+
44+
console.log('Current Deployer address: ', deployer);
45+
console.log('Current Multisig address: ', MultiSigWallet.address);
46+
console.log('Current Bridge Owner: ', bridgeOwner);
47+
console.log('List of multisig owners: ', multiSigOwners);
48+
49+
if(!multiSigOwners.includes(deployer)) {
50+
console.log('You should be a owner in the multisig wallet to perform this transaction');
51+
return;
52+
}
53+
54+
if (bridgeOwner === MultiSigWallet.address) {
55+
const changeBridgeOwnerMethod = bridge.methods
56+
.transferOwnership(newWalletAddress);
57+
await changeBridgeOwnerMethod.call({ from: MultiSigWallet.address });
58+
await multiSigContract.methods.submitTransaction(
59+
BridgeProxy.address,
60+
0,
61+
changeBridgeOwnerMethod.encodeABI()
62+
).send({ from: deployer, gasLimit: 3000000 });
63+
64+
const newOwner = await bridge.methods.owner().call();
65+
66+
if(newOwner.toLowerCase() === newWalletAddress.toLowerCase()) {
67+
console.log('Bridge owner changed successfully, the new owner now is: ', newOwner);
68+
} else {
69+
console.log('Error changing the bridge owner, owner is: ', newOwner);
70+
}
71+
} else {
72+
console.log('Multisig is not the bridge owner');
73+
}
74+
75+
if (federationOwner === MultiSigWallet.address) {
76+
const changeFederationOwnerMethod = federation.methods
77+
.transferOwnership(newWalletAddress);
78+
await changeFederationOwnerMethod.call({ from: MultiSigWallet.address });
79+
await multiSigContract.methods.submitTransaction(
80+
FederationProxy.address,
81+
0,
82+
changeFederationOwnerMethod.encodeABI()
83+
).send({ from: deployer, gasLimit: 3000000 });
84+
85+
const newOwner = await federation.methods.owner().call();
86+
87+
if(newOwner.toLowerCase() === newWalletAddress.toLowerCase()) {
88+
console.log('Federation owner changed successfully, the new owner now is: ', newOwner);
89+
} else {
90+
console.log('Error changing the federation owner, owner is: ', newOwner);
91+
}
92+
} else {
93+
console.log('Multisig is not the Federation owner');
94+
}
95+
96+
if (allowTokensOwner === MultiSigWallet.address) {
97+
const changeAllowTokensOwnerMethod = allowTokens.methods
98+
.transferOwnership(newWalletAddress);
99+
await changeAllowTokensOwnerMethod.call({ from: MultiSigWallet.address });
100+
await multiSigContract.methods.submitTransaction(
101+
AllowTokensProxy.address,
102+
0,
103+
changeAllowTokensOwnerMethod.encodeABI()
104+
).send({ from: deployer, gasLimit: 3000000 });
105+
106+
const newOwner = await allowTokens.methods.owner().call();
107+
108+
if(newOwner.toLowerCase() === newWalletAddress.toLowerCase()) {
109+
console.log('Allow Tokens owner changed successfully, the new owner now is: ', newOwner);
110+
} else {
111+
console.log('Error changing the Allow Tokens owner, owner is: ', newOwner);
112+
}
113+
} else {
114+
console.log('Multisig is not the Allow tokens owner');
115+
}
116+
}
117+
118+
// We recommend this pattern to be able to use async/await everywhere
119+
// and properly handle errors.
120+
main()
121+
.then(() => process.exit(0))
122+
.catch((error) => {
123+
console.error(error);
124+
process.exit(1);
125+
});

0 commit comments

Comments
 (0)