Compare commits

..

2 Commits

Author SHA1 Message Date
Râu Cao
96a18d3c5c Bundle import txs into blocks, wait for confirmations
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-24 12:41:40 +02:00
Râu Cao
b3dabb41e1 Add RSK testnet contract addresses
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-23 18:46:57 +02:00
18 changed files with 79 additions and 111 deletions

View File

@@ -1,14 +0,0 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
version-resolver:
major:
labels:
- release/major
minor:
labels:
- release/minor
- feature
patch:
labels:
- release/patch
default: patch

View File

@@ -1,11 +0,0 @@
name: Release Drafter
on:
pull_request:
types: [closed]
jobs:
release_drafter_job:
name: Update release notes draft
runs-on: ubuntu-latest
steps:
- name: Release Drafter
uses: https://github.com/raucao/gitea-release-drafter@dev

View File

@@ -1,5 +1,4 @@
[![npm](https://img.shields.io/npm/v/@kredits/contracts.svg)](https://www.npmjs.com/package/@kredits/contracts)
[![Build Status](https://drone.kosmos.org/api/badges/kredits/contracts/status.svg)](https://drone.kosmos.org/kredits/contracts)
[![npm](https://img.shields.io/npm/v/kredits-contracts.svg)](https://www.npmjs.com/package/kredits-contracts)
# Kredits Contracts
@@ -27,27 +26,27 @@ To run a local development chain run:
### Bootstrap
1. Run an EVM node and ipfs
1. Run an Ethereum node and ipfs
$ npm run devchain
$ ipfs daemon
2. Compile contracts and build ABIs
2. Compile contracts and build ABIs
(compiled artifacts will be in `/artifacts`)
$ npm run build
3. Deploy new upgradable contract proxies
3. Deploy new upgradable contract proxies
$ npm run deploy:dao
4. Execute seeds to create demo contributors, contributions, etc. (optional)
4. Execute seeds to create demo contributors, contributions, etc. (optional)
$ npm run seeds
**Step 2-4 is also summarized in `npm run bootstrap`**
5. Show contract addresses
5. Show contract addresses
$ cat lib/addresses.json
@@ -57,16 +56,6 @@ If you need to fund development accounts with devchain coins:
$ npm run fund # or hardhat fund --network localhost
## Specs / Testing
With a local development chain running:
$ hardhat test
If you add or change contract code, please make sure to add and/or adapt tests
accordingly. Don't worry, it's easy! You can use existing tests as a template
for new ones.
## Contract architecture
We use the [OpenZeppelin hardhat
@@ -156,3 +145,12 @@ To run the console on one of the non localhost networks you can also just pass
on the --network argument.
$ hardhat console --network rsk
## Known Issues
When resetting ganache Metamask might have an invalid transaction nonce and
transactions get rejected. Nonces in Ethereum must be incrementing and have no
gap.
To solve this reset the metamask account (Account -> Settings -> Reset Account)

View File

@@ -15,7 +15,7 @@ const contractCalls = [
name: 'raucao',
kind: 'person',
url: '',
github_username: 'raucao',
github_username: 'skddc',
github_uid: 842,
gitea_username: 'raucao',
wiki_username: 'Basti',
@@ -33,7 +33,7 @@ const contractCalls = [
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 500, kind: 'dev', description: '[67P/kredits-contracts] Test this thing', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 2, contributorIpfsHash: 'QmcHzEeAM26HV2zHTf5HnZrCtCtGdEccL5kUtDakAB7ozB', date: '2019-04-11', amount: 1500, kind: 'dev', description: '[67P/kredits-web] Reviewed stuff', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 5000, kind: 'dev', description: '[67P/kredits-contracts] Add tests', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 1500, kind: 'dev', description: '[67P/kredits-contracts] Add tests', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 1500, kind: 'dev', description: '[67P/kredits-contracts] Introduce contribution token', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 2, contributorIpfsHash: 'QmcHzEeAM26HV2zHTf5HnZrCtCtGdEccL5kUtDakAB7ozB', date: '2019-04-11', amount: 5000, kind: 'dev', description: '[67P/kredits-web] Expense UI, first draft', url: '' }, { gasLimit: 350000 }]],

View File

@@ -13,7 +13,6 @@ interface IContributionBalance {
contract Contributor is Initializable {
address public deployer;
address public profileManager;
IContributionBalance public contributionContract;
IToken public tokenContract;
@@ -44,9 +43,8 @@ contract Contributor is Initializable {
_;
}
function initialize(address profileManagerAddress) public initializer {
function initialize() public initializer {
deployer = msg.sender;
profileManager = profileManagerAddress;
}
function setContributionContract(address contribution) public onlyCore {
@@ -86,12 +84,11 @@ contract Contributor is Initializable {
c.hashFunction = hashFunction;
c.hashSize = hashSize;
emit ContributorProfileUpdated(id, oldHashDigest, c.hashDigest);
ContributorProfileUpdated(id, oldHashDigest, c.hashDigest);
}
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public {
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public onlyCore {
require(!addressExists(account), "Address already in use");
require((msg.sender == profileManager) || addressIsCore(msg.sender), "Only core and profile manager");
uint32 _id = contributorsCount + 1;
assert(!contributors[_id].exists); // this can not be acually
Contributor storage c = contributors[_id];

View File

@@ -16,7 +16,6 @@ contract Reimbursement is Initializable {
struct ReimbursementData {
uint32 recipientId;
uint256 amount;
// TODO remove token entirely
address token;
bytes32 hashDigest;
uint8 hashFunction;

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,9 @@
{
"31": {
"Contributor": "0xf1073Dab6e305583F95e451Cba449bB867a6e3Fd",
"Contribution": "0x1C531F824e339cD37D75B7F391cB8E42e0E0d4bd",
"Token": "0x56F64C3BB45e6a248F4C783f5a1633E53D6A2371",
"Reimbursement": "0x9C5fFBFba2570A9b31D60338453C5480Ce74B342"
"Contributor": "0x9C66a36fa6296EBb81d8F5D4642B05dF2CE85a8D",
"Contribution": "0xa12630a995337e45bDD746B6baedc1Ce2a1DCC9D",
"Token": "0x12Eb86338076450f86E5B552556028c7D21eaf1F",
"Reimbursement": "0xe2FE7cb00e2f94b8bA0AE526dfbe313f34c66E3C"
},
"1337": {
"Contributor": "0xCc66f9A3cA2670972938FAD91d0865c4a62DFB25",

View File

@@ -16,7 +16,7 @@ class Reimbursement extends Record {
}
getData (id) {
return this.contract.get(id);
return this.contract.getReimbursement(id);
}
async add (attrs, callOptions = {}) {

View File

@@ -69,10 +69,7 @@ class Kredits {
if (wallet) {
signer = wallet.connect(ethProvider);
} else if (ethProvider.getSigner) {
// Only useful for reading data, not writing. The (unused) address is
// necessary because without an address, ethers.js will try to look up
// the provider's account 0, which doesn't work on our public RSK nodes.
signer = ethProvider.getSigner('0xfa77675540E550b911a6AABF3805ac17C6641ec1');
signer = ethProvider.getSigner();
}
return new Kredits(ethProvider, signer, kreditsOptions);
}

8
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@kredits/contracts",
"version": "7.1.0",
"name": "kredits-contracts",
"version": "7.0.0-beta.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@kredits/contracts",
"version": "7.1.0",
"name": "kredits-contracts",
"version": "7.0.0-beta.0",
"license": "MIT",
"dependencies": {
"@kosmos/schemas": "^3.1.0",

View File

@@ -1,7 +1,7 @@
{
"name": "@kredits/contracts",
"version": "7.1.0",
"description": "Smart contracts and JavaScript API for Kredits",
"name": "kredits-contracts",
"version": "7.0.0-beta.0",
"description": "Ethereum contracts and npm wrapper for Kredits",
"main": "./lib/kredits.js",
"directories": {
"test": "test"

View File

@@ -36,7 +36,7 @@ async function main() {
const blocksVetoPeriod = 40320; // 7 days; 15 seconds block time
await deployContractProxy('Contributor', [ '0x0000000000000000000000000000000000000000' ] );
await deployContractProxy('Contributor');
await deployContractProxy('Contribution', [ blocksVetoPeriod ]);
await deployContractProxy('Token');
await deployContractProxy('Reimbursement');

View File

@@ -1,13 +1,13 @@
const fs = require('fs');
const Kredits = require('../../lib/kredits');
const PARALLEL_TXS = 5;
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
const count = await kredits.Contribution.count;
console.log(`Currently ${count} entries`);
try {
const data = fs.readFileSync("./data/contributions.json");
@@ -20,21 +20,42 @@ async function main() {
const confirmationPeriod = 40320 // blocks
const unconfirmedHeight = currentBlockHeight + confirmationPeriod;
for (const contributionId of ids) {
const c = contributions[contributionId.toString()];
const txBundlesAmount = Math.ceil(ids.length / PARALLEL_TXS);
let txBundles = [];
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
for (let i = 0; i < txBundlesAmount; i++) {
txBundles.push(ids.slice((i * PARALLEL_TXS), (i * PARALLEL_TXS) + PARALLEL_TXS));
}
const result = await kredits.Contribution.contract.add(
c.amount, c.contributorId,
c.hashDigest, c.hashFunction, c.hashSize,
confirmedAtBlock, c.vetoed
);
console.log(`Adding contribution #${contributionId}: ${result.hash}`);
await result.wait();
};
for (const txBundle of txBundles) {
console.log(`Adding contributions #${txBundle[0]} to #${txBundle[txBundle.length - 1]}`)
let resultPromises = [];
for (const contributionId of txBundle) {
const c = contributions[contributionId.toString()];
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
const result = await kredits.Contribution.contract.add(
c.amount, c.contributorId,
c.hashDigest, c.hashFunction, c.hashSize,
confirmedAtBlock, c.vetoed
);
resultPromises.push(result.wait());
console.log(`Added contribution #${contributionId}: ${result.hash}`);
}
console.log(`Waiting for confirmations...`);
await Promise.all(resultPromises);
console.log('Transactions confirmed');
}
} catch(e) {
console.error(e);
console.log(e);
}
}

View File

@@ -6,8 +6,7 @@ async function main() {
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
const count = await kredits.Contributor.count;
console.log(`Currently ${count} entries`);
try {
const data = fs.readFileSync("./data/contributors.json");
const contributors = JSON.parse(data);
@@ -23,11 +22,11 @@ async function main() {
contributor.hashFunction,
contributor.hashSize,
);
console.log(`Adding contributor #${contributorId}: ${result.hash}`);
await result.wait();
// await result.wait();
console.log(`Added contributor #${contributorId}: ${result.hash}`);
};
} catch(e) {
console.error(e);
console.log(e);
}
}

View File

@@ -6,8 +6,6 @@ async function main() {
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
const count = await kredits.Contributors.count;
console.log(`Currently ${count} entries`);
const table = new Table({
head: ['ID', 'Account', 'Name', 'Core?', 'Balance', 'Kredits earned', 'Contributions count', 'IPFS']

View File

@@ -9,7 +9,7 @@ describe("Contribution contract", async function () {
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7];
const contributorFactory = await ethers.getContractFactory("Contributor");
Contributor = await upgrades.deployProxy(contributorFactory, ["0x2946fFfd31096435cb0fc927D306E1C006C5D1aF"]);
Contributor = await upgrades.deployProxy(contributorFactory);
for (const account of accounts) {
await Contributor.addContributor(account.address, "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8", 18, 32);
}

View File

@@ -1,14 +1,14 @@
const { expect } = require("chai");
const { ethers, upgrades } = require("hardhat");
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8;
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7;
let Contribution, Contributor, Token;
describe("Contributor contract", async function () {
before(async function () {
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8] = await ethers.getSigners();
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
const contributorFactory = await ethers.getContractFactory("Contributor");
Contributor = await upgrades.deployProxy(contributorFactory, [addr8.address]);
Contributor = await upgrades.deployProxy(contributorFactory);
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
const tokenFactory = await ethers.getContractFactory("Token");
@@ -30,10 +30,6 @@ describe("Contributor contract", async function () {
expect(await Contributor.deployer()).to.equal(owner.address);
expect(await Contributor.deployer()).to.not.equal(addr1.address);
});
it("sets a profile manager address", async function () {
expect(await Contributor.profileManager()).to.equal(addr8.address);
});
});
describe("add()", function () {
@@ -42,7 +38,7 @@ describe("Contributor contract", async function () {
"0x608FD4b95116Ea616990Aaeb1d4f1ce07612f261",
"0x1d9de6de5c72eedca6d7a5e8a9159e2f5fe676506aece3000acefcc821723429",
18, 32
)).to.be.revertedWith("Only core and profile manager");
)).to.be.revertedWith("Core only");
expect(await Contributor.contributorsCount()).to.equal(8);
});
@@ -74,18 +70,6 @@ describe("Contributor contract", async function () {
18, 32
)).to.emit(Contributor, "ContributorAdded").withArgs(10, "0x765E88b4F9a59C3a3b300C6eFF9E6E9fDDf9FbD9");
});
it("allows the profile manager account to create a contributor profile", async function () {
await Contributor.connect(addr8).addContributor(
"0x954712B8703Df5255A219B139ba7BFC256E72a15",
"0x1d9de6de5c72eedca6d7a5e8a9159e2f5fe676506aece3000acefcc821723429",
18, 32
);
expect(await Contributor.contributorsCount()).to.equal(11);
const c = await Contributor.getContributorById(11);
expect(c['account']).to.equal("0x954712B8703Df5255A219B139ba7BFC256E72a15");
});
});
describe("withdraw()", function () {