Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This repo doesn't work right now. I fixed it #9

Open
youngkidwarrior opened this issue Jul 27, 2021 · 2 comments
Open

This repo doesn't work right now. I fixed it #9

youngkidwarrior opened this issue Jul 27, 2021 · 2 comments

Comments

@youngkidwarrior
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/erc20-snapshot/balances.js b/node_modules/erc20-snapshot/balances.js
index e781348..7fd62d7 100644
--- a/node_modules/erc20-snapshot/balances.js
+++ b/node_modules/erc20-snapshot/balances.js
@@ -10,6 +10,7 @@ module.exports.createBalances = async data => {
     const wallet = event.to;
 
     let deposits = (balances.get(wallet) || {}).deposits || new BigNumber(0);
+    
     let withdrawals = (balances.get(wallet) || {}).withdrawals || new BigNumber(0);
 
     if (event.value) {
@@ -35,6 +36,7 @@ module.exports.createBalances = async data => {
     setWithdrawals(event);
   }
   
+
   for (const [key, value] of balances.entries()) {
     if (key === "0x0000000000000000000000000000000000000000") {
       continue;
@@ -44,7 +46,7 @@ module.exports.createBalances = async data => {
 
     closingBalances.push({
       wallet: key,
-      balance: balance.div(10 ** parseInt(data.decimals)).toFixed(data.decimals)
+      balance: balance.div(10 ** parseInt(data.decimals)).toFixed(18)
     });
   }
 
diff --git a/node_modules/erc20-snapshot/contract.js b/node_modules/erc20-snapshot/contract.js
index abea66b..bf47db2 100644
--- a/node_modules/erc20-snapshot/contract.js
+++ b/node_modules/erc20-snapshot/contract.js
@@ -9,6 +9,6 @@ const web3 = new Web3(new Web3.providers.HttpProvider((Config || {}).provider ||
 const contractAddress = (Config || {}).contractAddress;
 
 module.exports.getContract = () => {
-  const contract = web3.eth.Contract(Parameters.abi, contractAddress);
+  const contract = new web3.eth.Contract(Parameters.abi, contractAddress);
   return contract;
 };
diff --git a/node_modules/erc20-snapshot/events/block-by-block.js b/node_modules/erc20-snapshot/events/block-by-block.js
index 25100d7..352cb53 100644
--- a/node_modules/erc20-snapshot/events/block-by-block.js
+++ b/node_modules/erc20-snapshot/events/block-by-block.js
@@ -11,6 +11,7 @@ const range = (start, end) => {
 
 module.exports.tryBlockByBlock = async (contract, start, end, symbol) => {
   const blocks = range(start, end);
+  console.log('blocks: ', blocks);
 
   let counter = 0;
   for await (const i of blocks) {
diff --git a/node_modules/erc20-snapshot/events/block-reader.js b/node_modules/erc20-snapshot/events/block-reader.js
index cccc91b..b4daaaa 100644
--- a/node_modules/erc20-snapshot/events/block-reader.js
+++ b/node_modules/erc20-snapshot/events/block-reader.js
@@ -16,7 +16,7 @@ const getMinimal = pastEvents => {
       transactionHash: tx.transactionHash,
       from: tx.returnValues["0"],
       to: tx.returnValues["1"],
-      value: tx.returnValues["2"]._hex
+      value: tx.returnValues["2"]
     };
   });
 };
diff --git a/node_modules/erc20-snapshot/events/blockchain.js b/node_modules/erc20-snapshot/events/blockchain.js
index 3756939..c0ad4c4 100644
--- a/node_modules/erc20-snapshot/events/blockchain.js
+++ b/node_modules/erc20-snapshot/events/blockchain.js
@@ -61,7 +61,7 @@ module.exports.get = async () => {
   var fromBlock = parseInt(Config.fromBlock) || 0;
   const blocksPerBatch = parseInt(Config.blocksPerBatch) || 0;
   const delay = parseInt(Config.delay) || 0;
-  const toBlock = blockHeight;
+  const toBlock = parseInt(Config.toBlock) || blockHeight;
 
   const lastDownloadedBlock = await LastDownloadedBlock.get(symbol);
 
diff --git a/node_modules/erc20-snapshot/index.js b/node_modules/erc20-snapshot/index.js
index bce42cf..107fac5 100755
--- a/node_modules/erc20-snapshot/index.js
+++ b/node_modules/erc20-snapshot/index.js
@@ -10,6 +10,7 @@ const start = async () => {
   await Config.checkConfig();
   const format = Config.getConfig().format;
   const result = await Events.get();
 
   console.log("Calculating balances of %s (%s)", result.name, result.symbol);
   const balances = await Balances.createBalances(result);

This issue body was partially generated by patch-package.

@vincedepalma
Copy link

You cant assume tokens are fixed at 18 decimals, fro example many stablecoins are only 6 decimals

balance: balance.div(10 ** parseInt(data.decimals)).toFixed(18)

@gonzaotc
Copy link

Worked!, thanks for the solution man, let's merge this! @binodnp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants