diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..c14b634 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,7 @@ +dist/ +deployments/ +artifacts/ +cache/ +coverage/ +node_modules/ +package.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..086aadd --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,22 @@ +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features + sourceType: 'module', // Allows for the use of imports + }, + env: { + commonjs: true, + }, + plugins: ['@typescript-eslint'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'prettier', + ], + rules: { + 'no-empty': 'off', + 'no-empty-function': 'off', + '@typescript-eslint/no-empty-function': 'off', + }, +}; diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..967fd70 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,55 @@ +name: Bug Report +description: Report a bug +type: "bug" + +body: + - type: textarea + attributes: + label: What happened? + description: Please provide as much information as possible, this helps us address the issue. + validations: + required: true + - type: textarea + attributes: + label: What did you expect to happen? + validations: + required: true + - type: textarea + attributes: + label: How can we reproduce it (as minimally and precisely as possible)? + description: Please provide steps to reproduce. Provide code that can be run if possible. + validations: + required: true + - type: input + attributes: + label: AutoGen version + description: What version or commit of the library was used + validations: + required: true + - type: dropdown + attributes: + label: Which package was this bug in + options: + - Core + - AgentChat + - Extensions + - AutoGen Studio + - Magentic One + - AutoGen Bench + - Other + validations: + required: true + - type: input + attributes: + label: Model used + description: If a model was used, please describe it here, indicating whether it is a local model or a cloud-hosted model + placeholder: gpt-4, mistral-7B etc + - type: input + attributes: + label: Python version + - type: input + attributes: + label: Operating system + - type: textarea + attributes: + label: Any additional info you think would be helpful for fixing this bug diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..76afcbc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Questions or general help 💬 + url: https://github.com/microsoft/autogen/discussions + about: Please ask and answer questions here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..1b1de6f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,18 @@ +name: Feature Request +description: Request a new feature or enhancement +type: "feature" + +body: + - type: textarea + attributes: + label: What feature would you like to be added? + description: Please describe the desired feature. Be descriptive, provide examples and if possible, provide a proposed solution. + validations: + required: true + + - type: textarea + attributes: + label: Why is this needed? + description: Why is it important that this feature is implemented? What problem or need does it solve? + validations: + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..df41ac4 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +## Why are these changes needed? + + + +## Related issue number + + + +## Checks + +- [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. +- [ ] I've made sure all auto checks have passed. diff --git a/.github/workflows/linux-test.yml b/.github/workflows/linux-test.yml new file mode 100644 index 0000000..64c37fc --- /dev/null +++ b/.github/workflows/linux-test.yml @@ -0,0 +1,22 @@ +name: ubuntu test + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main ] + +jobs: + build: + name: Build and Test ubuntu + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - uses: pnpm/action-setup@v4 + with: + version: 10 + - name: build + run: | + pnpm install + pnpm run build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4cbfff --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist +node_modules +pnpm-lock.yaml diff --git a/README.md b/README.md index 7ac8c73..3aa7025 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ # TronStudio TRON Smart Contract Code Develep + +# Build + +Install dependencies + +``` +npm install +``` + +Build + +``` +npm run build +``` +# Useage + +see https://github.com/sun-protocol/tron-studio-demo \ No newline at end of file diff --git a/package.json b/package.json index 12511b2..a359d4f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@sun-protocol/tron-studio", - "version": "0.0.5", - "description": "Hardhat Plugin For Replicable Deployments And Tests", + "version": "0.0.6", + "description": "Environment configuration and partial optimization", "repository": "https://github.com/sun-protocol/TronStudio", "author": "dev", "license": "MIT", @@ -76,7 +76,7 @@ "chokidar": "^3.5.2", "debug": "^4.3.2", "enquirer": "^2.3.6", - "ethers": "^5.7.0", + "ethers": "^5.8.0", "form-data": "^4.0.0", "fs-extra": "^10.0.0", "match-all": "^1.2.6", diff --git a/src/DeploymentsManager.ts b/src/DeploymentsManager.ts index 2844d22..cebd665 100644 --- a/src/DeploymentsManager.ts +++ b/src/DeploymentsManager.ts @@ -17,7 +17,7 @@ import path from 'path'; import {BigNumber} from '@ethersproject/bignumber'; import debug from 'debug'; -const log = debug('hardhat:wighawag:hardhat-deploy'); +const log = debug('hardhat:sun-protocol:tron-studio'); import { addDeployments, @@ -35,6 +35,7 @@ import {TransactionResponse} from '@ethersproject/providers'; import {Artifact, HardhatRuntimeEnvironment, Network} from 'hardhat/types'; import {store} from './globalStore'; import {bnReplacer} from './internal/utils'; +import TronWeb from 'tronweb'; export class DeploymentsManager { public deploymentsExtension: DeploymentsExtension; @@ -834,7 +835,20 @@ export class DeploymentsManager { byzantium: receipt.byzantium, } : undefined; - + if (this.isTronNetworkWithTronSolc) { + const tronweb = new TronWeb( + this.env.config.networks.localhost.url, + this.env.config.networks.localhost.url, + false, + false); + deployment.address = tronweb.address.fromHex(deployment.address); + if(actualReceipt){ + actualReceipt.from = tronweb.address.fromHex(actualReceipt.from); + if(actualReceipt.contractAddress) { + actualReceipt.contractAddress = tronweb.address.fromHex(actualReceipt.contractAddress); + } + } + } // from : https://stackoverflow.com/a/14810722/1663971 function objectMap(object: any, mapFn: (obj: any) => any) { return Object.keys(object).reduce(function (result: any, key) { diff --git a/src/index.ts b/src/index.ts index 3f01781..7fbe162 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1105,8 +1105,9 @@ subtask( hre, runSuper ) => { - let nw = hre.hardhatArguments["network"]?hre.hardhatArguments["network"]:"localhost"; - if (hre.config.networks[nw].tron) { + const nw = hre.hardhatArguments["network"]?hre.hardhatArguments["network"]:"localhost"; + if (hre.config.networks[nw].tron && (hre.config as any)?.tronSolc?.enable) { + // are we using tron-solc compiler and is the network a Tron network return await loadTronSolc(args.solcVersion); } return runSuper(); diff --git a/src/tron/solc.ts b/src/tron/solc.ts index 240424c..6ed2cc0 100644 --- a/src/tron/solc.ts +++ b/src/tron/solc.ts @@ -1,7 +1,7 @@ -const path = require("path"); -import { access, constants, promises as fsPromises } from 'fs'; +/* eslint-disable @typescript-eslint/no-explicit-any */ +import * as path from 'path'; +import { constants, promises as fsPromises } from 'fs'; import fetch from 'node-fetch'; -import { writeFile } from 'fs/promises'; import { createWriteStream } from 'fs'; import { pipeline } from 'stream'; import { promisify } from 'util'; @@ -36,21 +36,192 @@ export async function loadTronSolc(solcVersion: string) { let longVersion = ''; if (solcVersion == "0.8.23") { - compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.23/soljson.js' + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.23/soljson.js'; compilerPath = path.join( __dirname, "soljson-tv_0.8.23.js" ); longVersion = "0.8.23"; } else if (solcVersion == "0.8.22") { - compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.22/soljson.js' + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.22/soljson.js'; compilerPath = path.join( __dirname, "soljson-tv_0.8.22.js" ); longVersion = "0.8.22"; + } else if (solcVersion == "0.8.21") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.21/soljson.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.21.js" + ); + longVersion = "0.8.21"; + } else if (solcVersion == "0.8.20") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.20/soljson.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.20.js" + ); + longVersion = "0.8.20"; + } else if (solcVersion == "0.8.18") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.18/soljson.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.18.js" + ); + longVersion = "0.8.18"; + } else if (solcVersion == "0.8.11") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.11/solidity-js_0.8.11_Rousseau_v4.4.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.11.js" + ); + longVersion = "0.8.11"; + } else if (solcVersion == "0.8.7") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.7/solidity-js_0.8.7_Rousseau_v4.4.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.7.js" + ); + longVersion = "0.8.7"; + } else if (solcVersion == "0.8.6") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.6/solidity-js_0.8.6_Bacon_v4.3.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.6.js" + ); + longVersion = "0.8.6"; + } else if (solcVersion == "0.7.7") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.7.7/solidity-js_0.7.7_Bacon_v4.3.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.7.7.js" + ); + longVersion = "0.7.7"; + } else if (solcVersion == "0.6.13") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.6.13/solidity-js_0.6.13_Bacon_v4.3.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.6.13.js" + ); + longVersion = "0.6.13"; + } else if (solcVersion == "0.5.18") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.18/solidity-js_0.5.18_Bacon_v4.3.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.18.js" + ); + longVersion = "0.5.18"; + } else if (solcVersion == "0.8.0") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.8.0/solidity-js_0.8.0_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.8.0.js" + ); + longVersion = "0.8.0"; + } else if (solcVersion == "0.7.6") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.7.6/solidity-js_0.7.6_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.7.6.js" + ); + longVersion = "0.7.6"; + } else if (solcVersion == "0.7.0") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.7.0/solidity-js_0.7.0_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.7.0.js" + ); + longVersion = "0.7.0"; + } else if (solcVersion == "0.6.12") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.6.12/solidity-js_0.6.12_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.6.12.js" + ); + longVersion = "0.6.12"; + } else if (solcVersion == "0.6.8") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.6.8/solidity-js_0.6.8_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.6.8.js" + ); + longVersion = "0.6.8"; + } else if (solcVersion == "0.6.2") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.6.2/solidity-js_0.6.2_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.6.2.js" + ); + longVersion = "0.6.2"; + } else if (solcVersion == "0.5.17") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.17/solidity-js_0.5.17_Plato_v4.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.17.js" + ); + longVersion = "0.5.17"; + } else if (solcVersion == "0.5.16") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.16/solidity-js_0.5.16_GreatVoyage_v4.1.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.16.js" + ); + longVersion = "0.5.16"; + } else if (solcVersion == "0.6.0") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.6.0/solidity-js_0.6.0_GreatVoyage_v4.1.2.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.6.0.js" + ); + longVersion = "0.6.0"; + } else if (solcVersion == "0.5.15") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.15/solidity-js_0.5.15_GreatVoyage_v4.1.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.15.js" + ); + longVersion = "0.5.15"; + } else if (solcVersion == "0.5.14") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.14/solidity-js_0.5.14_GreatVoyage_v4.1.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.14.js" + ); + longVersion = "0.5.14"; + } else if (solcVersion == "0.5.12") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.12/solidity-js_0.5.12_GreatVoyage_v4.0.1.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.12.js" + ); + longVersion = "0.5.12"; + } else if (solcVersion == "0.5.8") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.8/soljson.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.8.js" + ); + longVersion = "0.5.8"; + } else if (solcVersion == "0.5.4") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/tv_0.5.4/tron-solidity-0.5.4_Odyssey_v3.6.0.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.5.4.js" + ); + longVersion = "0.5.4"; + } else if (solcVersion == "0.4.25") { + compilerRemotePath = 'https://github.com/tronprotocol/solidity/releases/download/0.4.25_Odyssey_v3.2.3/tron-solidity-0.4.25_Odyssey_v3.2.3.js'; + compilerPath = path.join( + __dirname, + "soljson-tv_0.4.25.js" + ); + longVersion = "0.4.25"; + } else { + throw new Error(`unkown solcVersion = ${solcVersion}`); } - let needDownload = !await checkFileExists(compilerPath); + + const needDownload = !await checkFileExists(compilerPath); if (needDownload) { await downloadFile(compilerRemotePath, compilerPath); }