Hello hardhat
This commit is contained in:
parent
c865c154a4
commit
1425c3664a
@ -1,19 +1,18 @@
|
||||
pragma solidity ^0.4.24;
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||
import "@aragon/os/contracts/kernel/IKernel.sol";
|
||||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
||||
|
||||
interface ITokenBalance {
|
||||
function balanceOf(address contributorAccount) public view returns (uint256);
|
||||
function balanceOf(address contributorAccount) external view returns (uint256);
|
||||
}
|
||||
interface IContributionBalance {
|
||||
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint32 amount);
|
||||
function balanceOf(address owner) public view returns (uint256);
|
||||
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) external view returns (uint32 amount);
|
||||
function balanceOf(address owner) external view returns (uint256);
|
||||
}
|
||||
|
||||
contract Contributor is AragonApp {
|
||||
bytes32 public constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb;
|
||||
bytes32 public constant MANAGE_CONTRIBUTORS_ROLE = keccak256("MANAGE_CONTRIBUTORS_ROLE");
|
||||
contract Contributor is Initializable {
|
||||
IContributionBalance contributionContract;
|
||||
ITokenBalance tokenContract;
|
||||
|
||||
struct Contributor {
|
||||
address account;
|
||||
@ -27,23 +26,23 @@ contract Contributor is AragonApp {
|
||||
mapping (uint32 => Contributor) public contributors;
|
||||
uint32 public contributorsCount;
|
||||
|
||||
// ensure alphabetic order
|
||||
enum Apps { Contribution, Contributor, Proposal, Reimbursement, Token }
|
||||
bytes32[5] public appIds;
|
||||
|
||||
event ContributorProfileUpdated(uint32 id, bytes32 oldHashDigest, bytes32 newHashDigest); // what should be logged
|
||||
event ContributorAccountUpdated(uint32 id, address oldAccount, address newAccount);
|
||||
event ContributorAdded(uint32 id, address account);
|
||||
|
||||
function initialize(address root, bytes32[5] _appIds) public onlyInit {
|
||||
appIds = _appIds;
|
||||
|
||||
initialized();
|
||||
function initialize() public initializer {
|
||||
|
||||
}
|
||||
|
||||
function getContract(uint8 appId) public view returns (address) {
|
||||
IKernel k = IKernel(kernel());
|
||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[appId]);
|
||||
// TODO who can call this when?
|
||||
function setContributionContract(address contribution) public {
|
||||
contributionContract = IContributionBalance(contribution);
|
||||
}
|
||||
|
||||
// TODO who can call this when?
|
||||
function setTokenContract(address token) public {
|
||||
tokenContract = ITokenBalance(token);
|
||||
}
|
||||
|
||||
function coreContributorsCount() public view returns (uint32) {
|
||||
@ -56,7 +55,7 @@ contract Contributor is AragonApp {
|
||||
return count;
|
||||
}
|
||||
|
||||
function updateContributorAccount(uint32 id, address oldAccount, address newAccount) public auth(MANAGE_CONTRIBUTORS_ROLE) {
|
||||
function updateContributorAccount(uint32 id, address oldAccount, address newAccount) public {
|
||||
require(newAccount != address(0), "invalid new account address");
|
||||
require(getContributorAddressById(id) == oldAccount, "contributor does not exist");
|
||||
|
||||
@ -66,7 +65,7 @@ contract Contributor is AragonApp {
|
||||
emit ContributorAccountUpdated(id, oldAccount, newAccount);
|
||||
}
|
||||
|
||||
function updateContributorProfileHash(uint32 id, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) {
|
||||
function updateContributorProfileHash(uint32 id, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public {
|
||||
Contributor storage c = contributors[id];
|
||||
bytes32 oldHashDigest = c.hashDigest;
|
||||
c.hashDigest = hashDigest;
|
||||
@ -76,7 +75,7 @@ contract Contributor is AragonApp {
|
||||
ContributorProfileUpdated(id, oldHashDigest, c.hashDigest);
|
||||
}
|
||||
|
||||
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) {
|
||||
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public {
|
||||
require(!addressExists(account));
|
||||
uint32 _id = contributorsCount + 1;
|
||||
assert(!contributors[_id].exists); // this can not be acually
|
||||
@ -119,7 +118,7 @@ contract Contributor is AragonApp {
|
||||
return contributors[id].account;
|
||||
}
|
||||
|
||||
function getContributorByAddress(address account) internal view returns (Contributor) {
|
||||
function getContributorByAddress(address account) internal view returns (Contributor memory) {
|
||||
uint32 id = contributorIds[account];
|
||||
return contributors[id];
|
||||
}
|
||||
@ -132,17 +131,15 @@ contract Contributor is AragonApp {
|
||||
hashFunction = c.hashFunction;
|
||||
hashSize = c.hashSize;
|
||||
isCore = isCoreTeam(id);
|
||||
address token = getContract(uint8(Apps.Token));
|
||||
balance = ITokenBalance(token).balanceOf(c.account);
|
||||
address contribution = getContract(uint8(Apps.Contribution));
|
||||
totalKreditsEarned = IContributionBalance(contribution).totalKreditsEarnedByContributor(_id, true);
|
||||
contributionsCount = IContributionBalance(contribution).balanceOf(c.account);
|
||||
balance = tokenContract.balanceOf(c.account);
|
||||
totalKreditsEarned = contributionContract.totalKreditsEarnedByContributor(_id, true);
|
||||
contributionsCount = contributionContract.balanceOf(c.account);
|
||||
exists = c.exists;
|
||||
}
|
||||
|
||||
function canPerform(address _who, address _where, bytes32 _what, uint256[] memory _how) public returns (bool) {
|
||||
address sender = _who;
|
||||
if (sender == address(-1)) {
|
||||
if (sender == address(0)) {
|
||||
sender = tx.origin;
|
||||
}
|
||||
// _what == keccak256('VOTE_PROPOSAL_ROLE')
|
||||
|
63
apps/contributor/hardhat.config.js
Normal file
63
apps/contributor/hardhat.config.js
Normal file
@ -0,0 +1,63 @@
|
||||
require("@nomiclabs/hardhat-waffle");
|
||||
require('hardhat-deploy');
|
||||
require("hardhat-deploy-ethers");
|
||||
require('@openzeppelin/hardhat-upgrades');
|
||||
|
||||
const promptly = require('promptly');
|
||||
|
||||
// This is a sample Hardhat task. To learn how to create your own go to
|
||||
// https://hardhat.org/guides/create-task.html
|
||||
task("accounts", "Prints the list of accounts", async () => {
|
||||
const accounts = await ethers.getSigners();
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log(account.address);
|
||||
}
|
||||
});
|
||||
|
||||
task('fund', "Send eth to an address", async () => {
|
||||
const to = await promptly.prompt('Address:');
|
||||
const value = await promptly.prompt('Value:');
|
||||
|
||||
const signer = await ethers.getSigners();
|
||||
|
||||
const fundTransaction = await signer[0].sendTransaction({to: to, value: ethers.utils.parseEther(value)});
|
||||
console.log(fundTransaction);
|
||||
});
|
||||
|
||||
task("create-wallet", "Creates a new wallet json", async () => {
|
||||
const wallet = ethers.Wallet.createRandom();
|
||||
|
||||
console.log('New wallet:');
|
||||
console.log(`Address: ${wallet.address}`);
|
||||
console.log(`Public key: ${wallet.publicKey}`);
|
||||
console.log(`Private key: ${wallet.privateKey}`);
|
||||
console.log(`Mnemonic: ${JSON.stringify(wallet.mnemonic)}`);
|
||||
|
||||
const password = await promptly.prompt('Encryption password: ')
|
||||
const encryptedJSON = await wallet.encrypt(password);
|
||||
|
||||
console.log('Encrypted wallet JSON:');
|
||||
console.log(encryptedJSON);
|
||||
});
|
||||
|
||||
// You need to export an object to set up your config
|
||||
// Go to https://hardhat.org/config/ to learn more
|
||||
|
||||
/**
|
||||
* @type import('hardhat/config').HardhatUserConfig
|
||||
*/
|
||||
module.exports = {
|
||||
solidity: "0.8.0",
|
||||
// defaultNetwork: 'localhost',
|
||||
networks: {
|
||||
hardhat: {
|
||||
chainId: 1337
|
||||
}
|
||||
},
|
||||
namedAccounts: {
|
||||
deployer: {
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
};
|
9784
apps/contributor/package-lock.json
generated
9784
apps/contributor/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,13 +3,16 @@
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@aragon/os": "^4.4.0"
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.0",
|
||||
"@openzeppelin/contracts-upgradeable": "^4.1.0",
|
||||
"hardhat": "^2.0.3",
|
||||
"hardhat-deploy": "^0.7.0-beta.35",
|
||||
"hardhat-deploy-ethers": "^0.3.0-beta.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aragon/test-helpers": "^2.1.0",
|
||||
"eth-gas-reporter": "^0.2.17",
|
||||
"ganache-cli": "^6.9.1",
|
||||
"solidity-coverage": "^0.5.11"
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@openzeppelin/hardhat-upgrades": "^1.8.2",
|
||||
"ethers": "^5.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "npm run start:aragon:ipfs",
|
||||
|
10
apps/contributor/scripts/create-proxy.js
Normal file
10
apps/contributor/scripts/create-proxy.js
Normal file
@ -0,0 +1,10 @@
|
||||
const { ethers, upgrades } = require("hardhat");
|
||||
|
||||
async function main() {
|
||||
const Contributor = await ethers.getContractFactory("Contributor");
|
||||
const contributor = await upgrades.deployProxy(Contributor, []);
|
||||
await contributor.deployed();
|
||||
console.log("Contributor deployed to:", contributor.address);
|
||||
}
|
||||
|
||||
main();
|
Loading…
x
Reference in New Issue
Block a user