Load contract APIs from hardhat artifacts #215

Merged
bumi merged 4 commits from fix-hardhat-build into hardhat 2022-05-20 10:27:30 +00:00
16 changed files with 19 additions and 80 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
build
flattened_contracts
node_modules
**/node_modules
.ganache-db

View File

@ -71,12 +71,6 @@ To run these scripts use `hardhat run`. For example: `hardhat run scripts/list-c
Some scripts are also defined as npm script, see package.json.
### cli.js
Call any function on any contract:
$ hardhat run scripts/cli.js
### repl.js
Similar to cli.js but only provides a REPL with an initialized `kredits`

View File

@ -61,7 +61,7 @@ task("create-wallet", "Creates a new wallet json", async () => {
*/
module.exports = {
solidity: "0.8.2",
// defaultNetwork: 'localhost',
defaultNetwork: "localhost",
networks: {
hardhat: {
chainId: 1337,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[{"constant":true,"inputs":[],"name":"ens","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"fac","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"appId","type":"bytes32"}],"name":"latestVersionAppBase","outputs":[{"name":"base","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_fac","type":"address"},{"name":"_ens","type":"address"},{"name":"_appIds","type":"bytes32[4]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"dao","type":"address"}],"name":"DeployInstance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"dao","type":"address"},{"indexed":false,"name":"appProxy","type":"address"},{"indexed":false,"name":"appId","type":"bytes32"}],"name":"InstalledApp","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"appProxy","type":"address"},{"indexed":false,"name":"appId","type":"bytes32"}],"name":"InstalledApp","type":"event"},{"constant":false,"inputs":[],"name":"newInstance","outputs":[{"name":"dao","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,17 +0,0 @@
const Base = require('./base');
const EthersUtils = require('ethers').utils;
class Acl extends Base {
hasPermission (fromAddress, contractAddress, roleID, params = null) {
let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID));
return this.hasPermission(
fromAddress,
contractAddress,
roleHash,
params
);
}
}
module.exports = Acl;

View File

@ -4,6 +4,4 @@ module.exports = {
Proposal: require('./proposal'),
Token: require('./token'),
Reimbursement: require('./reimbursement'),
Kernel: require('./kernel'),
Acl: require('./acl'),
};

View File

@ -1,24 +0,0 @@
const namehash = require('ethers').utils.namehash;
const Base = require('./base');
const KERNEL_APP_ADDR_NAMESPACE = '0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb';
class Kernel extends Base {
constructor (contract) {
super(contract);
this.apm = 'open.aragonpm.eth'; // can be overwritten if needed
}
getApp (appName) {
if (appName === 'Acl') {
return this.contract.acl();
}
return this.contract.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName));
}
appNamehash (appName) {
return namehash(`kredits-${appName.toLowerCase()}.${this.apm}`);
}
}
module.exports = Kernel;

View File

@ -9,15 +9,15 @@
"scripts": {
"wallet:create": "hardhat create-wallet",
"devchain": "hardhat node --network hardhat",
"deploy:dao": "hardhat run scripts/create-proxy.js --network localhost",
"deploy:dao": "hardhat run scripts/create-proxy.js",
"postshrinkwrap": "node scripts/fix-package-lock.js &>/dev/null || true",
"build": "npm run build:contracts && npm run build:json",
"build:contracts": "hardhat compile --force",
"build:json": "node ./scripts/build-json.js",
"seeds": "hardhat run scripts/seeds.js --network localhost",
"fund": "hardhat fund --network localhost",
"seeds": "hardhat run scripts/seeds.js",
"fund": "hardhat fund",
"bootstrap": "npm run build && npm run deploy:dao && npm run seeds",
"repl": "hardhat console --network localhost",
"repl": "hardhat console",
"lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"",
"lint:contract-tests": "eslint apps/*/test",
"lint:wrapper": "eslint lib/",

View File

@ -1,24 +1,18 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
const contractsPath = path.join(__dirname, '..', 'build', 'contracts');
const libPath = path.join(__dirname, '..', 'lib');
const abisPath = path.join(libPath, 'abis');
const contractsPath = path.join(__dirname, "..", "artifacts", "contracts");
const libPath = path.join(__dirname, "..", "lib");
const abisPath = path.join(libPath, "abis");
const files = [
'Contributor',
'Contribution',
'Kernel',
'Proposal',
'Token',
'Reimbursement',
'ACL'
];
const files = ["Contributor", "Contribution", "Token", "Reimbursement"];
files.forEach((fileName) => {
let file = require(`${contractsPath}/${fileName}.json`);
let file = require(`${contractsPath}/${fileName}.sol/${fileName}.json`);
let abiFile = path.join(abisPath, `${fileName}.json`);
fs.writeFileSync(abiFile, JSON.stringify(file.abi));
});
console.log("Don't forget to reaload the JSON files from your application; i.e. restart kredits-web");
console.log(
"Don't forget to reaload the JSON files from your application; i.e. restart kredits-web"
);