Skip to content

Commit

Permalink
feat(global): makes it working and rm husky
Browse files Browse the repository at this point in the history
  • Loading branch information
allemanfredi committed Sep 10, 2021
1 parent 3d5cad8 commit be4b362
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 1,810 deletions.
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions .husky/pre-commit

This file was deleted.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ Simple contract to get token balances in one single call. The contract is create

 

### Addresses

```js
Factory: 0xB10CeCcBe00572deE94cF0514581d3695A8Cd596
BalanceChecker: 0x07c7BBC98a251C85f1dD7958BA4786dc5eacF24d
```

 

### Available Chains

* Ethereum
* Binance Smart Chain
* Polygon (coming soon)
* Fantom (coming soon)
* xDai (coming soon)

 

***

 
Expand All @@ -18,6 +37,8 @@ ROPSTEN_PRIVATE_KEY=
ROSPTENT_NODE=
ETH_MAINNET_NODE=
ETHERSCAN_API_KEY=
BSC_MAINNET_NODE=
BSC_MAINNET_PRIVATE_KEY=
```


Expand Down
44 changes: 14 additions & 30 deletions contracts/BalanceChecker.sol
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
// NOTE: taken from here: https://etherscan.io/address/0xb1f8e55c7f64d203c1400b9d8555d050f94adf39#code
pragma solidity ^0.4.21;
pragma solidity ^0.7.3;

interface ERC20 {
function balanceOf(address) public view returns (uint256);
}
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract BalanceChecker {
function() public payable {
revert();
}

function tokenBalance(address user, address token) public view returns (uint256) {
uint256 tokenCode;
assembly {
tokenCode := extcodesize(token)
}

if (tokenCode > 0 && token.call(bytes4(0x70a08231), user)) {
return ERC20(token).balanceOf(user);
} else {
return 0;
}
}

function balances(address[] users, address[] tokens) external view returns (uint256[]) {
uint256[] memory addrBalances = new uint256[](tokens.length * users.length);
function balances(address[] calldata _users, address[] calldata _tokens) external view returns (uint256[] memory) {
uint256[] memory addrBalances = new uint256[](_tokens.length * _users.length);

for (uint256 i = 0; i < users.length; i++) {
for (uint256 j = 0; j < tokens.length; j++) {
uint256 addrIdx = j + tokens.length * i;
if (tokens[j] != address(0x0)) {
addrBalances[addrIdx] = tokenBalance(users[i], tokens[j]);
for (uint256 i = 0; i < _users.length; i++) {
for (uint256 j = 0; j < _tokens.length; j++) {
uint256 addrIdx = j + _tokens.length * i;
if (_tokens[j] != address(0x0000000000000000000000000000000000000000)) {
addrBalances[addrIdx] = IERC20(_tokens[j]).balanceOf(_users[i]);
} else {
addrBalances[addrIdx] = users[i].balance;
addrBalances[addrIdx] = address(_users[i]).balance;
}
}
}

return addrBalances;
}

fallback() external payable {
revert("This contract does not accept ethers");
}
}
2 changes: 1 addition & 1 deletion contracts/Factory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.21;
pragma solidity ^0.7.3;

contract Factory {
event Deployed(address addr, uint256 salt);
Expand Down
18 changes: 12 additions & 6 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getEnvironmentVariable = (_envVar) => process.env[_envVar]
*/
module.exports = {
solidity: {
version: '0.4.21',
version: '0.7.3',
settings: {
optimizer: {
enabled: true,
Expand All @@ -30,18 +30,24 @@ module.exports = {
url: `${getEnvironmentVariable('ROPSTEN_NODE')}`,
accounts: [getEnvironmentVariable('ROPSTEN_PRIVATE_KEY')],
gas: 200e9,
gasPrice: 30e9,
gasPrice: 10e9,
},
mainnet: {
url: `${getEnvironmentVariable('ETH_MAINNET_NODE')}`,
accounts: [getEnvironmentVariable('MAINNET_PRIVATE_KEY')],
gasPrice: 30e9,
gas: 200e9
gasPrice: 85e9,
gas: 200e9,
},
bsc: {
url: getEnvironmentVariable('BSC_MAINNET_NODE'),
accounts: [getEnvironmentVariable('BSC_MAINNET_PRIVATE_KEY')],
gasPrice: 7e9,
gas: 200e9,
},
},
/*etherscan: {
etherscan: {
apiKey: getEnvironmentVariable('ETHERSCAN_API_KEY'),
},*/
},
gasReporter: {
enabled: true,
},
Expand Down
Loading

0 comments on commit be4b362

Please sign in to comment.