-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vondas-network/dev
v1.0.0 release
- Loading branch information
Showing
60 changed files
with
7,000 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,111 @@ | ||
# loupe | ||
# loupe | ||
One tool for Smart Contract extraction | ||
|
||
|
||
# What does it do? | ||
*loupe* excels at one thing, Smart Contract extraction. It can extract master Solidity files which contain multiple contracts in one file as well as Solidity files that are aggregated into a nested JSON file. The type of Solidity file returned by *loupe* is blockchain dependent. | ||
|
||
## Ethereum/Binance | ||
On Ethereum/Binance, we found most Smart Contracts are either an individual Smart contract with multiple functions or a Smart Contract that containes multiple Solidity files. | ||
|
||
## Avalanche | ||
On Avalanche, we found most responses to be JSON files containing multiple Solidity files nested within an object. | ||
|
||
0x053502bf08b7d3a54891bb66fb966ea4c4ba7d02 | ||
|
||
## Preparing files for compiling | ||
|
||
# Requirements | ||
- [Node.js](https://nodejs.org/en/download/) | ||
- [@vondas/viewfinder](https://www.npmjs.com/package/@vondas/viewfinder) | ||
- [dotenv](https://www.npmjs.com/package/dotenv) | ||
- API keys (*listed below*) | ||
|
||
# Support Blockchains | ||
An *API key* is required for each Etherscan clone, free tiers are available. | ||
|
||
## Testnet | ||
|
||
| Testnet | Blockchain | Endpoint | | ||
| ------- | ---------- | -------------------------------- | | ||
| Ropsten | Ethereum | https://api-ropsten.etherscan.io | | ||
| Kovan | Ethereum | https://api-kovan.etherscan.io | | ||
| Rinkeby | Ethereum | https://api-rinkeby.etherscan.io | | ||
|
||
## Mainnet | ||
|
||
| Mainnet | Endpoint | Docs | | ||
| --------- | ----------------------------------- | -------------------------------------------- | | ||
| Ethereum | https://api.etherscan.io | https://docs.etherscan.io/ | | ||
| Avalanche | https://api.snowtrace.io | https://snowtrace.io/apis | | ||
| Binance | https://api.bscscan.com | https://docs.bscscan.com/ | | ||
| Heco | https://api.hecoinfo.com | https://hecoinfo.com/apis | | ||
| Cronos | https://api.cronoscan.com | https://cronoscan.com/apis | | ||
| Moonriver | https://api-moonriver.moonscan.io | https://moonriver.moonscan.io/apis | | ||
| Moonbeam | https://blockscout.moonbeam.network | https://blockscout.moonbeam.network/api-docs | | ||
| Arbitrum | https://api.arbiscan.io | https://arbiscan.io/apis | | ||
| Fantom | https://api.ftmscan.com | https://ftmscan.com/apis | | ||
| Hooscan | https://api.hooscan.com | https://hooscan.com/apis | | ||
| Optimism | https://api-optimistic.etherscan.io | https://optimistic.etherscan.io/apis | | ||
|
||
# Usage | ||
|
||
## Create .env file for Environmental Variables | ||
|
||
- In the root folder, create a new file for the environmental variables called `.env` | ||
- Copy/paste the text below into the `.env` file | ||
- Remove `XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` and add the associated *API Key* | ||
- Save `.env` | ||
|
||
````bash | ||
# ADD API KEYS HERE | ||
ETHEREUM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
AVALANCHE_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
BINANCE_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
HECO_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
CRONOS_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
MOONRIVER_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
MOONBEAM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
ARBITRUM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
FANTOM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
HOOSCAN_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
OPTIMISM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
```` | ||
- The *API keys* above are associated with an array located in `init.js` | ||
``` | ||
var chainKey = { | ||
"keyEthereum": process.env.ETHEREUM_API_KEY, | ||
"keyAvalanche": process.env.AVALANCHE_API_KEY, | ||
"keyBinance": process.env.BINANCE_API_KEY, | ||
"keyHeco": process.env.HECO_API_KEY, | ||
"keyCronos": process.env.CRONOS_API_KEY, | ||
"keyMoonriver": process.env.MOONRIVER_API_KEY, | ||
"keyMoonbeam": process.env.MOONBEAM_API_KEY, | ||
"keyArbitrum": process.env.ARBITRUM_API_KEY, | ||
"keyFantom": process.env.FANTOM_API_KEY, | ||
"keyHooscan": process.env.HOOSCAN_API_KEY, | ||
"keyOptimism": process.env.OPTIMISM_API_KEY | ||
} | ||
``` | ||
|
||
# Installation | ||
## npm | ||
``` | ||
npm i @vondas/loupe | ||
``` | ||
|
||
# Usage | ||
``` | ||
//Load express module with `require` directive | ||
let dotenv_module; | ||
dotenv_module = require("dotenv"); | ||
dotenv_module.config(); | ||
const loupe = require('./lib/loupe'); | ||
const blockchains = ['ethereum', 'avalanche', 'binance', 'heco', 'cronos', 'moonriver', 'moonbeam', 'arbitrum', 'fantom', 'hooscan', 'optimism']; | ||
const blockchain = blockchains[1]; | ||
const contract_address = '0x6cddb55d0ac3204a0bc4f3e3eb03407b1ad59e5c'; | ||
console.log(blockchain, contract_address); | ||
loupe.getSmartContracts(blockchain, contract_address); | ||
``` |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...bf08b7d3a54891bb66fb966ea4c4ba7d02/0x053502bf08b7d3a54891bb66fb966ea4c4ba7d02-nested.json
Large diffs are not rendered by default.
Oops, something went wrong.
190 changes: 190 additions & 0 deletions
190
...54891bb66fb966ea4c4ba7d02/0x053502bf08b7d3a54891bb66fb966ea4c4ba7d02-solidity/Address.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev Collection of functions related to the address type | ||
*/ | ||
library Address { | ||
/** | ||
* @dev Returns true if `account` is a contract. | ||
* | ||
* [IMPORTANT] | ||
* ==== | ||
* It is unsafe to assume that an address for which this function returns | ||
* false is an externally-owned account (EOA) and not a contract. | ||
* | ||
* Among others, `isContract` will return false for the following | ||
* types of addresses: | ||
* | ||
* - an externally-owned account | ||
* - a contract in construction | ||
* - an address where a contract will be created | ||
* - an address where a contract lived, but was destroyed | ||
* ==== | ||
*/ | ||
function isContract(address account) internal view returns (bool) { | ||
// This method relies on extcodesize, which returns 0 for contracts in | ||
// construction, since the code is only stored at the end of the | ||
// constructor execution. | ||
|
||
uint256 size; | ||
// solhint-disable-next-line no-inline-assembly | ||
assembly { size := extcodesize(account) } | ||
return size > 0; | ||
} | ||
|
||
/** | ||
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to | ||
* `recipient`, forwarding all available gas and reverting on errors. | ||
* | ||
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost | ||
* of certain opcodes, possibly making contracts go over the 2300 gas limit | ||
* imposed by `transfer`, making them unable to receive funds via | ||
* `transfer`. {sendValue} removes this limitation. | ||
* | ||
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. | ||
* | ||
* IMPORTANT: because control is transferred to `recipient`, care must be | ||
* taken to not create reentrancy vulnerabilities. Consider using | ||
* {ReentrancyGuard} or the | ||
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. | ||
*/ | ||
function sendValue(address payable recipient, uint256 amount) internal { | ||
require(address(this).balance >= amount, "Address: insufficient balance"); | ||
|
||
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value | ||
(bool success, ) = recipient.call{ value: amount }(""); | ||
require(success, "Address: unable to send value, recipient may have reverted"); | ||
} | ||
|
||
/** | ||
* @dev Performs a Solidity function call using a low level `call`. A | ||
* plain`call` is an unsafe replacement for a function call: use this | ||
* function instead. | ||
* | ||
* If `target` reverts with a revert reason, it is bubbled up by this | ||
* function (like regular Solidity function calls). | ||
* | ||
* Returns the raw returned data. To convert to the expected return value, | ||
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. | ||
* | ||
* Requirements: | ||
* | ||
* - `target` must be a contract. | ||
* - calling `target` with `data` must not revert. | ||
* | ||
* _Available since v3.1._ | ||
*/ | ||
function functionCall(address target, bytes memory data) internal returns (bytes memory) { | ||
return functionCall(target, data, "Address: low-level call failed"); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with | ||
* `errorMessage` as a fallback revert reason when `target` reverts. | ||
* | ||
* _Available since v3.1._ | ||
*/ | ||
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { | ||
return functionCallWithValue(target, data, 0, errorMessage); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], | ||
* but also transferring `value` wei to `target`. | ||
* | ||
* Requirements: | ||
* | ||
* - the calling contract must have an ETH balance of at least `value`. | ||
* - the called Solidity function must be `payable`. | ||
* | ||
* _Available since v3.1._ | ||
*/ | ||
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { | ||
return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but | ||
* with `errorMessage` as a fallback revert reason when `target` reverts. | ||
* | ||
* _Available since v3.1._ | ||
*/ | ||
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { | ||
require(address(this).balance >= value, "Address: insufficient balance for call"); | ||
require(isContract(target), "Address: call to non-contract"); | ||
|
||
// solhint-disable-next-line avoid-low-level-calls | ||
(bool success, bytes memory returndata) = target.call{ value: value }(data); | ||
return _verifyCallResult(success, returndata, errorMessage); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], | ||
* but performing a static call. | ||
* | ||
* _Available since v3.3._ | ||
*/ | ||
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { | ||
return functionStaticCall(target, data, "Address: low-level static call failed"); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], | ||
* but performing a static call. | ||
* | ||
* _Available since v3.3._ | ||
*/ | ||
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { | ||
require(isContract(target), "Address: static call to non-contract"); | ||
|
||
// solhint-disable-next-line avoid-low-level-calls | ||
(bool success, bytes memory returndata) = target.staticcall(data); | ||
return _verifyCallResult(success, returndata, errorMessage); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], | ||
* but performing a delegate call. | ||
* | ||
* _Available since v3.4._ | ||
*/ | ||
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { | ||
return functionDelegateCall(target, data, "Address: low-level delegate call failed"); | ||
} | ||
|
||
/** | ||
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], | ||
* but performing a delegate call. | ||
* | ||
* _Available since v3.4._ | ||
*/ | ||
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { | ||
require(isContract(target), "Address: delegate call to non-contract"); | ||
|
||
// solhint-disable-next-line avoid-low-level-calls | ||
(bool success, bytes memory returndata) = target.delegatecall(data); | ||
return _verifyCallResult(success, returndata, errorMessage); | ||
} | ||
|
||
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { | ||
if (success) { | ||
return returndata; | ||
} else { | ||
// Look for revert reason and bubble it up if present | ||
if (returndata.length > 0) { | ||
// The easiest way to bubble the revert reason is using memory via assembly | ||
|
||
// solhint-disable-next-line no-inline-assembly | ||
assembly { | ||
let returndata_size := mload(returndata) | ||
revert(add(32, returndata), returndata_size) | ||
} | ||
} else { | ||
revert(errorMessage); | ||
} | ||
} | ||
} | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
...1bb66fb966ea4c4ba7d02/0x053502bf08b7d3a54891bb66fb966ea4c4ba7d02-solidity/BeaconProxy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./IBeacon.sol"; | ||
import "./Proxy.sol"; | ||
import "./ERC1967Upgrade.sol"; | ||
|
||
/** | ||
* @dev This contract implements a proxy that gets the implementation address for each call from a {UpgradeableBeacon}. | ||
* | ||
* The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't | ||
* conflict with the storage layout of the implementation behind the proxy. | ||
* | ||
* _Available since v3.4._ | ||
*/ | ||
contract BeaconProxy is Proxy, ERC1967Upgrade { | ||
/** | ||
* @dev Initializes the proxy with `beacon`. | ||
* | ||
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This | ||
* will typically be an encoded function call, and allows initializating the storage of the proxy like a Solidity | ||
* constructor. | ||
* | ||
* Requirements: | ||
* | ||
* - `beacon` must be a contract with the interface {IBeacon}. | ||
*/ | ||
constructor(address beacon, bytes memory data) payable { | ||
assert(_BEACON_SLOT == bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1)); | ||
_upgradeBeaconToAndCall(beacon, data, false); | ||
} | ||
|
||
/** | ||
* @dev Returns the current beacon address. | ||
*/ | ||
function _beacon() internal view virtual returns (address) { | ||
return _getBeacon(); | ||
} | ||
|
||
/** | ||
* @dev Returns the current implementation address of the associated beacon. | ||
*/ | ||
function _implementation() internal view virtual override returns (address) { | ||
return IBeacon(_getBeacon()).implementation(); | ||
} | ||
|
||
/** | ||
* @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}. | ||
* | ||
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. | ||
* | ||
* Requirements: | ||
* | ||
* - `beacon` must be a contract. | ||
* - The implementation returned by `beacon` must be a contract. | ||
*/ | ||
function _setBeacon(address beacon, bytes memory data) internal virtual { | ||
_upgradeBeaconToAndCall(beacon, data, false); | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
...54891bb66fb966ea4c4ba7d02/0x053502bf08b7d3a54891bb66fb966ea4c4ba7d02-solidity/Context.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/* | ||
* @dev Provides information about the current execution context, including the | ||
* sender of the transaction and its data. While these are generally available | ||
* via msg.sender and msg.data, they should not be accessed in such a direct | ||
* manner, since when dealing with meta-transactions the account sending and | ||
* paying for execution may not be the actual sender (as far as an application | ||
* is concerned). | ||
* | ||
* This contract is only required for intermediate, library-like contracts. | ||
*/ | ||
abstract contract Context { | ||
function _msgSender() internal view virtual returns (address) { | ||
return msg.sender; | ||
} | ||
|
||
function _msgData() internal view virtual returns (bytes calldata) { | ||
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 | ||
return msg.data; | ||
} | ||
} | ||
|
Oops, something went wrong.