Skip to content

Commit c2b1536

Browse files
leomassazzaliamzebedee
authored andcommitted
Remove web3 from remove-fee-periods (#1342)
* wip commit * wip commit * wip * wip * Remove log line from script * remove empty comment
1 parent 9e82766 commit c2b1536

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

publish/src/commands/import-fee-periods.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
const path = require('path');
44
const fs = require('fs');
5-
const w3utils = require('web3-utils');
6-
const Web3 = require('web3');
5+
const ethers = require('ethers');
76
const { red, gray, green, yellow } = require('chalk');
87

98
const {
@@ -68,16 +67,17 @@ const importFeePeriods = async ({
6867
privateKey = envPrivateKey;
6968
}
7069

71-
const web3 = new Web3(new Web3.providers.HttpProvider(providerUrl));
72-
73-
let account;
70+
const provider = new ethers.providers.JsonRpcProvider(providerUrl);
71+
let wallet;
7472
if (useFork) {
75-
account = getUsers({ network, user: 'owner' }).address; // protocolDAO
73+
const account = getUsers({ network, user: 'owner' }).address; // protocolDAO
74+
wallet = provider.getSigner(account);
7675
} else {
77-
web3.eth.accounts.wallet.add(privateKey);
78-
account = web3.eth.accounts.wallet[0].address;
76+
wallet = new ethers.Wallet(privateKey, provider);
7977
}
80-
console.log(gray(`Using account with public key ${account}`));
78+
79+
if (!wallet.address) wallet.address = wallet._address;
80+
console.log(gray(`Using account with public key ${wallet.address}`));
8181

8282
const { address: targetContractAddress, source } = deployment.targets['FeePool'];
8383

@@ -93,11 +93,11 @@ const importFeePeriods = async ({
9393
if (lastEntry.address !== targetContractAddress) {
9494
sourceContractAddress = lastEntry.address;
9595
} else if (secondLastEntry.address !== targetContractAddress) {
96-
sourceContractAddress = targetContractAddress.address;
96+
sourceContractAddress = secondLastEntry.address;
9797
} else {
9898
throw Error('Cannot determine which is the last version of FeePool for the network');
9999
}
100-
} else if (!w3utils.isAddress(sourceContractAddress)) {
100+
} else if (!ethers.utils.isAddress(sourceContractAddress)) {
101101
throw Error(
102102
'Invalid address detected for source (please check your inputs): ',
103103
sourceContractAddress
@@ -115,14 +115,15 @@ const importFeePeriods = async ({
115115
console.log(gray(`Reading from old FeePool at: ${sourceContractAddress}`));
116116
console.log(gray(`Importing into new FeePool at: ${targetContractAddress}`));
117117
}
118-
const sourceContract = new web3.eth.Contract(abi, sourceContractAddress);
119-
const targetContract = new web3.eth.Contract(abi, targetContractAddress);
120118

121-
const feePeriodLength = await sourceContract.methods.FEE_PERIOD_LENGTH().call();
119+
const sourceContract = new ethers.Contract(sourceContractAddress, abi, wallet);
120+
const targetContract = new ethers.Contract(targetContractAddress, abi, wallet);
121+
122+
const feePeriodLength = await sourceContract.FEE_PERIOD_LENGTH();
122123

123124
// Check sources
124125
for (let i = 0; i <= feePeriodLength - 1; i++) {
125-
const period = await sourceContract.methods.recentFeePeriods(i).call();
126+
const period = await sourceContract.recentFeePeriods(i);
126127
if (!skipTimeCheck) {
127128
if (period.feePeriodId === '0') {
128129
throw Error(
@@ -138,21 +139,27 @@ const importFeePeriods = async ({
138139
}
139140

140141
// remove redundant index keys (returned from struct calls)
142+
const filteredPeriod = {};
141143
Object.keys(period)
142-
.filter(key => /^[0-9]+$/.test(key))
143-
.forEach(key => delete period[key]);
144-
feePeriods.push(period);
144+
.filter(key => /^[0-9]+$/.test(key) === false)
145+
.forEach(key => (filteredPeriod[key] = period[key]));
146+
147+
feePeriods.push(filteredPeriod);
145148
console.log(
146-
gray(`loaded feePeriod ${i} from FeePool (startTime: ${new Date(period.startTime * 1000)})`)
149+
gray(
150+
`loaded feePeriod ${i} from FeePool (startTime: ${new Date(
151+
filteredPeriod.startTime * 1000
152+
)})`
153+
)
147154
);
148155
}
149156

150157
// Check target does not have existing periods
151158
if (!override) {
152159
for (let i = 0; i < feePeriodLength; i++) {
153-
const period = await targetContract.methods.recentFeePeriods(i).call();
160+
const period = await targetContract.recentFeePeriods(i);
154161
// ignore any initial entry where feePeriodId is 1 as this is created by the FeePool constructor
155-
if (period.feePeriodId !== '1' && period.startTime !== '0') {
162+
if (period.feePeriodId.toString() !== '1' && period.startTime.toString() !== '0') {
156163
throw Error(
157164
`The new target FeePool already has imported fee periods (one or more entries has ` +
158165
`startTime as 0. Please check to make sure you are using the latest FeePool ` +
@@ -204,11 +211,12 @@ const importFeePeriods = async ({
204211
feePeriod.rewardsClaimed,
205212
];
206213
console.log(yellow(`Attempting action FeePool.importFeePeriod(${importArgs})`));
207-
const { transactionHash } = await targetContract.methods.importFeePeriod(...importArgs).send({
208-
from: account,
209-
gasLimit: Number(gasLimit),
210-
gasPrice: w3utils.toWei(gasPrice.toString(), 'gwei'),
214+
const tx = await targetContract.importFeePeriod(...importArgs, {
215+
gasLimit: ethers.BigNumber.from(gasLimit),
216+
gasPrice: ethers.utils.parseUnits(gasPrice, 'gwei'),
211217
});
218+
const { transactionHash } = await tx.wait();
219+
212220
index++;
213221

214222
console.log(

publish/src/commands/purge-synths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const purgeSynths = async ({
9595
} else {
9696
wallet = new ethers.Wallet(privateKey, provider);
9797
}
98-
console.log(wallet);
98+
9999
if (!wallet.address) wallet.address = wallet._address;
100100
console.log(gray(`Using account with public key ${wallet.address}`));
101101
console.log(gray(`Using gas of ${gasPrice} GWEI with a max of ${gasLimit}`));

publish/src/util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const readline = require('readline');
66
const { gray, cyan, yellow, redBright, green } = require('chalk');
77
const { table } = require('table');
88
const w3utils = require('web3-utils');
9+
const { BigNumber } = require('ethers');
910

1011
const {
1112
constants: {
@@ -35,7 +36,13 @@ const {
3536
});
3637

3738
const { networks } = require('../..');
38-
const stringify = input => JSON.stringify(input, null, '\t') + '\n';
39+
const JSONreplacer = (key, value) => {
40+
if (typeof value === 'object' && value.type && value.type === 'BigNumber') {
41+
return BigNumber.from(value).toString();
42+
}
43+
return value;
44+
};
45+
const stringify = input => JSON.stringify(input, JSONreplacer, '\t') + '\n';
3946

4047
const ensureNetwork = network => {
4148
if (!networks.includes(network)) {

0 commit comments

Comments
 (0)