Skip to content

Commit

Permalink
abi-to-sol use current solidity compiler (#22)
Browse files Browse the repository at this point in the history
* abi-to-sol use current solidity compiler - fixes #21 #20

* prepare 0.2.1

* prep v0.2.1

* update acks

* fix typo
  • Loading branch information
tintinweb committed Aug 8, 2022
1 parent d4ab0a5 commit 17d0570
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes will be documented in this file.

## v0.2.1
- fix: feed current compiler version into abi-to-sol; strip attribution and other code #20 #21
- update: compiler list
- update: built-in solc -> 0.8.16

## v0.2.0
- new: new command to fetch & load interface declaration from etherscan.io #19

Expand Down
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,49 @@ contract MainContract {
}
}
```

### Fetch Interface Declaration from Etherscan

![shell-fetch-interface](https://user-images.githubusercontent.com/2865694/183062446-c952b308-9fc7-49f9-8308-3eac09ca3b4a.gif)


`.fetch interface <address> <interfaceName> [optional: chain=mainnet]`

```
⇒ solidity-shell --fork https://mainnet.infura.io/v3/<yourApiKey>
🚀 Entering interactive Solidity ^0.8.16 shell (🧁:Ganache built-in). '.help' and '.exit' are your friends.
»
» .fetch interface 0x40cfEe8D71D67108Db46F772B7e2CD55813Bf2FB Test
» interface Test {
... omitted ...
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
function totalSupply() external view returns (uint256);
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferOwnership(address newOwner) external;
function withdraw() external;
}
» Test t = Test(0x40cfEe8D71D67108Db46F772B7e2CD55813Bf2FB)
» t.symbol()
MGX
```
____


## Acknowledgements

* Inspired by the great but unfortunately unmaintained [solidity-repl](https://github.com/raineorshine/solidity-repl).
* Fetch interfaces from Etherscan is powered by [abi-to-sol](https://github.com/gnidan/abi-to-sol).
14 changes: 12 additions & 2 deletions bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,24 @@ cheers 🙌
case 'interface':
const { getRemoteInterfaceFromEtherscan } = require('../src/compiler/remoteCompiler');

getRemoteInterfaceFromEtherscan(commandParts[2], commandParts[3], commandParts.length >= 4 ? commandParts[4] : undefined).then(interfaceSource => {
getRemoteInterfaceFromEtherscan(
commandParts[2],
commandParts[3],
commandParts.length >= 4 ? commandParts[4] : undefined,
shell.settings.installedSolidityVersion
).then(interfaceSource => {
console.log(interfaceSource);
return cb(handleRepl(interfaceSource, cb)); // recursively call
}).catch(e => {
console.error(e);
console.log("let's try once more 🤷‍♂️")
// try once more?
getRemoteInterfaceFromEtherscan(commandParts[2], commandParts[3], commandParts.length >= 4 ? commandParts[4] : undefined).then(interfaceSource => {
getRemoteInterfaceFromEtherscan(
commandParts[2],
commandParts[3],
commandParts.length >= 4 ? commandParts[4] : undefined,
shell.settings.installedSolidityVersion
).then(interfaceSource => {
console.log(interfaceSource);
return cb(handleRepl(interfaceSource, cb)); // recursively call
}).catch(e => {
Expand Down
20 changes: 9 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solidity-shell",
"version": "0.2.0",
"version": "0.2.1",
"description": "An interactive Solidity shell with lightweight session recording and remote compiler support",
"main": "src/index.js",
"bin": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"minimist": "^1.2.5",
"readline-sync": "^1.4.10",
"request": "^2.88.2",
"solc": "^0.8.15",
"solc": "^0.8.16",
"sync-request": "^6.1.0",
"vorpal": "^1.12.0",
"web3": "^1.5.2"
Expand Down
1 change: 1 addition & 0 deletions src/compiler/autogenerated/solcVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

//autogenerated with # npm run updateCompilerList
module.exports.solcVersions = [
"v0.8.16+commit.07a7930e",
"v0.8.15+commit.e14f2714",
"v0.8.14+commit.80d49f37",
"v0.8.13+commit.abaa5c0e",
Expand Down
8 changes: 5 additions & 3 deletions src/compiler/remoteCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getRemoteCompiler(solidityVersion) {
}

//.import interface 0x40cfee8d71d67108db46f772b7e2cd55813bf2fb test2
function getRemoteInterfaceFromEtherscan(address, name, chain) {
function getRemoteInterfaceFromEtherscan(address, name, chain, solidityVersion) {
return new Promise((resolve, reject) => {

let provider = `https://api${(!chain || chain == "mainnet") ? "" : `-${chain}`}.etherscan.io`
Expand All @@ -73,10 +73,12 @@ function getRemoteInterfaceFromEtherscan(address, name, chain) {
let abi = JSON.parse(data.result);
let src = generateSolidity({
name: name,
solidityVersion: "0.8.9",
solidityVersion: solidityVersion,
abi,
outputSource: false
outputSource: false,
outputAttribution: false,
});
src = src.substring(src.indexOf("\n\n") + 2); // strip license/pragma
return resolve(src)
}
})
Expand Down

0 comments on commit 17d0570

Please sign in to comment.