Skip to content

Commit

Permalink
Get all rep addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
tinybike committed May 10, 2018
1 parent a3917b8 commit 385dfa8
Show file tree
Hide file tree
Showing 21 changed files with 5,131 additions and 1,504 deletions.
7 changes: 3 additions & 4 deletions data/freeze-rep.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"senderAddress": "0x7e614ec62cfd5761f20a9c5a2fe2bc0ac7431918",
"data": "0xa9059cbb00000000000000000000000100000000000000000000000000000000000000060000000000000000000000000000000000000000000000000de0b6b3a7640000",
"blockNumber": 4086410
}
"senderAddress": "0x01114f4bda09ed6c6715cf0baf606b5bce1dc96a",
"blockNumber": 5511415
}
16 changes: 6 additions & 10 deletions data/legacy-rep.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
"1": {
"contractAddress": "0x48c80F1f4D53D5951e5D5438B54Cba84f29F32a5",
"contractUploadBlock": 2378196
"contractAddress": "0xe94327d07fc17907b4db788e5adf2ed424addff6",
"contractUploadBlock": 4086425
},
"3": {
"contractAddress": "0x39E082EEdc796835d444dB92dF9Ee1Ca5F64Cf66",
"contractUploadBlock": 2055651
"contractAddress": "0xf52e614de10a602458472299dacf21316a9b7292",
"contractUploadBlock": 2055625
},
"4": {
"contractAddress": "0xF1FaC99605cd371e0274D847a88BAe09C84934cc",
"contractUploadBlock": 1228061
},
"10101": {
"contractAddress": "0x0bd7b480637a77d9c4226a2b793768fc6c849124",
"contractUploadBlock": 2
"contractAddress": "0x01f72ef9f920056f40de19c6940ba571bae1ab7f",
"contractUploadBlock": 1227488
}
}
14 changes: 14 additions & 0 deletions data/serpent-rep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"1": {
"contractAddress": "0x48c80F1f4D53D5951e5D5438B54Cba84f29F32a5",
"contractUploadBlock": 2378196
},
"3": {
"contractAddress": "0x7a305d9b681fb164dc5ad628b5992177dc66aec8",
"contractUploadBlock": 1383780
},
"4": {
"contractAddress": "0x9a2517fDEb1B1759D005BD50a0DDC3eeA7fA4FDF",
"contractUploadBlock": 2180437
}
}
58 changes: 0 additions & 58 deletions lib/all-rep-addresses.js

This file was deleted.

29 changes: 17 additions & 12 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
const path = require("path");
const abi = require("augur-abi");
const repFreeze = require("../data/freeze-rep.json");
const freezeRep = require("../data/freeze-rep.json");
const legacyRep = require("../data/legacy-rep.json");

module.exports.REP_CONTRACT_ADDRESS = ((require("../build/contracts/RepToken").networks || {})[process.env.EXPECTED_NETWORK_ID] || {}).address || "0x";
// const networkID = augur.rpc.getNetworkID();
// const universe = augur.contracts.addresses[networkID].Universe;
// module.exports.REP_CONTRACT_ADDRESS = augur.api.Universe.getReputationToken({ universe }, (err, reputationToken) => {
// if (err) return console.error(err);
// module.exports.REP_CONTRACT_ADDRESS = reputationToken;
// });

module.exports.LEGACY_REP_FREEZE_BLOCK = repFreeze.blockNumber;
module.exports.LEGACY_REP_FREEZE_ADDRESS = repFreeze.senderAddress;
module.exports.LEGACY_REP_FROZEN_REP_RECIPIENT_ADDRESS = "0xe1e212c353f7a682693c198ba5ff85849f8300cc";
module.exports.LEGACY_REP_FREEZE_BLOCK = freezeRep.blockNumber;
module.exports.LEGACY_REP_FREEZE_ADDRESS = freezeRep.senderAddress;

module.exports.LEGACY_REP_CONTRACT_ADDRESS = (legacyRep[process.env.EXPECTED_NETWORK_ID] || {}).contractAddress;
module.exports.LEGACY_REP_CONTRACT_UPLOAD_BLOCK = (legacyRep[process.env.EXPECTED_NETWORK_ID] || {}).contractUploadBlock;
const networkID = process.env.EXPECTED_NETWORK_ID;

module.exports.LEGACY_REP_CONTRACT_ADDRESS = legacyRep[networkID].contractAddress;
module.exports.LEGACY_REP_CONTRACT_UPLOAD_BLOCK = legacyRep[networkID].contractUploadBlock;
// module.exports.LEGACY_REP_CONTRACT_ADDRESS = augur.contracts.addresses[networkID].LegacyReputationToken;
// module.exports.LEGACY_REP_CONTRACT_UPLOAD_BLOCK = augur.contracts.uploadBlockNumbers[networkID];

module.exports.LEGACY_REP_CREATION_OVERFLOW_DATA = "0xa9059cbb00000000000000000000000100000000000000000000000000000000000000060000000000000000000000000000000000000000000000000de0b6b3a7640000";
module.exports.LEGACY_REP_CREATION_OVERFLOW_AMOUNT = "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000";
module.exports.LEGACY_REP_TOTAL_SUPPLY = "0x00000000000000000000000000000000000000000009195731e2ce35eb000000";
module.exports.LEGACY_REP_TRANSFER_SIGNATURE = "0x" + abi.keccak_256("Transfer(address,address,uint256)");
// module.exports.LEGACY_REP_TRANSFER_SIGNATURE = augur.contracts.abi.events.LegacyReputationToken.Transfer.signature;
module.exports.LEGACY_REP_TEST_TRANSFER_RECIPIENT = "0x7c0d52faab596c08f484e3478aebc6205f3f5d8c";

module.exports.ADDRESSES_PER_CHUNK = 25;
module.exports.PARALLEL_TRANSACTIONS = 50;
module.exports.BLOCKS_PER_CHUNK = 5000;
module.exports.REP_ADDRESS_FILE = path.join(__dirname, "..", "data", "all-rep-addresses.txt");
module.exports.REP_ADDRESS_FILE = path.join(__dirname, "..", "data", "all-rep-addresses-" + process.env.EXPECTED_NETWORK_ID + ".txt");
8 changes: 4 additions & 4 deletions lib/freeze-rep.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const fs = require("fs");
const constants = require("./constants");

function freezeRep(rpc, senderAddress, freezeRepFile, callback) {
function freezeRep(augur, senderAddress, freezeRepFile, callback) {
const testTransferPayload = {
name: "transfer",
params: [constants.LEGACY_REP_TEST_TRANSFER_RECIPIENT, "0x1"],
signature: ["address", "uint256"],
from: senderAddress,
to: constants.LEGACY_REP_CONTRACT_ADDRESS,
};
rpc.callContractFunction(testTransferPayload, (preFreezeTransferResponse) => {
augur.rpc.callContractFunction(testTransferPayload, (preFreezeTransferResponse) => {
if (preFreezeTransferResponse !== "0x0000000000000000000000000000000000000000000000000000000000000001") {
return callback("Pre-freeze REP transfer failed (expected success)");
}
rpc.transact({
augur.rpc.transact({
name: "transfer",
data: constants.LEGACY_REP_CREATION_OVERFLOW_DATA,
from: senderAddress,
to: constants.LEGACY_REP_CONTRACT_ADDRESS,
}, null, res => console.log("freeze rep sent:", res), (res) => {
console.log("freeze rep success:", res);
rpc.callContractFunction(testTransferPayload, (postFreezeTransferResponse) => {
augur.rpc.callContractFunction(testTransferPayload, (postFreezeTransferResponse) => {
if (postFreezeTransferResponse === "0x0000000000000000000000000000000000000000000000000000000000000001") {
return callback("Post-freeze REP transfer succeeded (expected failure)");
}
Expand Down
61 changes: 61 additions & 0 deletions lib/get-all-rep-addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const fs = require("fs");
const async = require("async");
const BigNumber = require("bignumber.js");
const speedomatic = require("speedomatic");

let totalLegacyRepSupply = new BigNumber(0);
// let totalMigrated = new BigNumber(0);

function writeAddressListToFile(repAddressFile, allRepAddresses, callback) {
fs.writeFile(repAddressFile, allRepAddresses.join("\n"), "utf8", (err) => callback(err, allRepAddresses));
}

function checkRepBalance(augur, address, legacyRepContractAddress, callback) {
if (speedomatic.strip0xPrefix(address).length > 40) {
console.log("skipping invalid address", address);
return callback(null);
}
augur.api.LegacyReputationToken.balanceOf({ _owner: address, tx: { to: legacyRepContractAddress } }, (err, repBalance) => {
if (err) return callback(err);
if (new BigNumber(repBalance, 10).gt(0)) {
totalLegacyRepSupply = totalLegacyRepSupply.plus(new BigNumber(repBalance, 10));
return callback(null, address);
}
callback(null);
});
}

function getAllRepAddresses(augur, allRepAddresses, legacyRepContractAddress, repAddressFile, fromBlock, legacyRepFreezeBlock, blocksPerChunk, callback) {
if (fromBlock > legacyRepFreezeBlock) {
console.log("Total legacy REP supply:", totalLegacyRepSupply.toFixed(), speedomatic.unfix(totalLegacyRepSupply, "string"));
return writeAddressListToFile(repAddressFile, allRepAddresses, callback);
}
const toBlock = Math.min(fromBlock + blocksPerChunk, legacyRepFreezeBlock);
const migratedEventSignature = augur.events.hashEventAbi({ name: "Migrated", inputs: [{ type: "address" }, { type: "uint256" }] });
augur.rpc.getLogs({
fromBlock: fromBlock,
toBlock: toBlock,
address: legacyRepContractAddress,
topics: [[augur.contracts.abi.events.LegacyReputationToken.Transfer.signature, migratedEventSignature]],
}, (err, logs) => {
if (err) return callback(err);
console.log("got", logs.length, "transfer or migrated logs between blocks", fromBlock, "and", toBlock);
if (!logs.length) return getAllRepAddresses(augur, allRepAddresses, legacyRepContractAddress, repAddressFile, toBlock + 1, legacyRepFreezeBlock, blocksPerChunk, callback);
async.eachSeries(logs, (log, nextLog) => {
const toAddress = speedomatic.formatEthereumAddress((log.topics[0] === migratedEventSignature) ? log.topics[1] : log.topics[2]);
if (allRepAddresses.indexOf(toAddress) !== -1) return async.setImmediate(() => nextLog());
checkRepBalance(augur, toAddress, legacyRepContractAddress, (err, address) => {
if (err) return nextLog(err);
if (address) allRepAddresses.push(address);
nextLog();
});
}, (err) => {
if (err) return callback(err);
getAllRepAddresses(augur, allRepAddresses, legacyRepContractAddress, repAddressFile, toBlock + 1, legacyRepFreezeBlock, blocksPerChunk, callback);
});
});
}

module.exports.writeAddressListToFile = writeAddressListToFile;
module.exports.checkRepBalance = checkRepBalance;
module.exports.getAllRepAddresses = getAllRepAddresses;
4 changes: 2 additions & 2 deletions lib/migrate-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function chunkRepAddresses(allRepAddresses, addressesPerChunk) {
}

function migrateRepChunk(rpc, repAddressChunk, repContractAddress, senderAddress, onSent, callback) {
rpc.transact({
augur.rpc.transact({
name: "migrateBalances",
params: [repAddressChunk],
signature: ["address[]"],
Expand All @@ -30,7 +30,7 @@ function migrateRepChunk(rpc, repAddressChunk, repContractAddress, senderAddress
numAddresses += repAddressChunk.length;
if (!res.gasFees) return callback(null);
totalGasFees = totalGasFees.plus(new BigNumber(res.gasFees, 10));
rpc.getTransactionReceipt(res.hash, (receipt) => {
augur.rpc.getTransactionReceipt(res.hash, (receipt) => {
totalGas = totalGas.plus(new BigNumber(receipt.gasUsed, 10));
callback(null);
});
Expand Down
6 changes: 3 additions & 3 deletions lib/unpause.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ function unpause(rpc, senderAddress, callback) {
from: senderAddress,
to: constants.REP_CONTRACT_ADDRESS,
};
rpc.callContractFunction(testTransferPayload, (preFreezeTransferResponse) => {
augur.rpc.callContractFunction(testTransferPayload, (preFreezeTransferResponse) => {
if (preFreezeTransferResponse === "0x0000000000000000000000000000000000000000000000000000000000000001") {
return callback("Pre-unpause REP transfer succeeded (expected failure)");
}
rpc.transact({
augur.rpc.transact({
name: "unpause",
from: senderAddress,
to: constants.REP_CONTRACT_ADDRESS,
}, null, res => console.log("unpause sent:", res), (res) => {
console.log("unpause success:", res);
rpc.callContractFunction(testTransferPayload, (postFreezeTransferResponse) => {
augur.rpc.callContractFunction(testTransferPayload, (postFreezeTransferResponse) => {
if (postFreezeTransferResponse !== "0x0000000000000000000000000000000000000000000000000000000000000001") {
return callback("Post-unpause REP transfer failed (expected success)");
}
Expand Down
6 changes: 3 additions & 3 deletions lib/verify-rep-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function verifySingleAddressRepMigration(rpc, repAddress, callback) {
signature: ["address"],
};
async.parallel({
new: (next) => rpc.callContractFunction(Object.assign({}, balanceOf, {
new: (next) => augur.rpc.callContractFunction(Object.assign({}, balanceOf, {
to: constants.REP_CONTRACT_ADDRESS,
}), newRepBalance => next(null, newRepBalance)),
old: (next) => rpc.callContractFunction(Object.assign({}, balanceOf, {
old: (next) => augur.rpc.callContractFunction(Object.assign({}, balanceOf, {
to: constants.LEGACY_REP_CONTRACT_ADDRESS,
}), oldRepBalance => next(null, oldRepBalance)),
}, (_, repBalances) => {
Expand All @@ -24,7 +24,7 @@ function verifySingleAddressRepMigration(rpc, repAddress, callback) {

function verifyRepMigration(rpc, allRepAddresses, callback) {
console.log("Verifying REP balances match...");
rpc.callContractFunction({
augur.rpc.callContractFunction({
name: "totalSupply",
to: constants.REP_CONTRACT_ADDRESS,
}, (totalSupply) => {
Expand Down
Loading

0 comments on commit 385dfa8

Please sign in to comment.