Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions contracts/community/Community.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract Community is ICommunity {
uint256[] public projectIds;
uint256 public totalMembersAllowed;
uint256 public rolesCount;
mapping (RoleUtils.Roles => uint256) public roleMembershipsLeft;
mapping(RoleUtils.Roles => uint256) public roleMembershipsLeft;
bool public claimableSkillWallets;

// add JSON Schema base URL
Expand All @@ -71,7 +71,10 @@ contract Community is ICommunity {
_rolesCount == 2 || _rolesCount == 3,
"Only 2 or 3 roles accepted"
);
require(_totalMembersAllowed >= _rolesCount, "Total members are less than roles");
require(
_totalMembersAllowed >= _rolesCount,
"Total members are less than roles"
);

metadataUri = _url;
distributedTownAddr = _distributedTownAddr;
Expand All @@ -86,25 +89,28 @@ contract Community is ICommunity {
ditoCreditsAddr
);
gigsAddr = GigsFactory(provider.gigsFactory()).deploy();

totalMembersAllowed = _totalMembersAllowed;
rolesCount = _rolesCount;
uint256 totalroleMemberships = 0;
uint256[3] memory roleCoefs = RoleUtils.getRolesCoefs(_rolesCount);
for (uint256 i = 0; i < _rolesCount; i++) {
//probably use math lib here or have limit for max totalMembersAllowed
uint256 roleMemberships = _totalMembersAllowed * roleCoefs[i] / 100;
uint256 roleMemberships = (_totalMembersAllowed *
roleCoefs[i]) / 100;
if (roleMemberships == 0) roleMemberships = 1;
roleMembershipsLeft[RoleUtils.Roles(i + 1)] = roleMemberships;
totalroleMemberships += roleMemberships;
}

uint256 leftoverMemberships = _totalMembersAllowed - totalroleMemberships;
uint256 leftoverMemberships = _totalMembersAllowed -
totalroleMemberships;
if (leftoverMemberships > 0) {
roleMembershipsLeft[RoleUtils.Roles.ROLE1]++;
if (leftoverMemberships == 2) roleMembershipsLeft[RoleUtils.Roles.ROLE2]++;
if (leftoverMemberships == 2)
roleMembershipsLeft[RoleUtils.Roles.ROLE2]++;
}

claimableSkillWallets = _claimableSkillWallets;

if (_isDitoNative) {
Expand Down Expand Up @@ -133,9 +139,13 @@ contract Community is ICommunity {
creditsToTransfer = currentCommunity.creditsToTransfer();

rolesCount = currentCommunity.rolesCount();
roleMembershipsLeft[RoleUtils.Roles(1)] = currentCommunity.roleMembershipsLeft(RoleUtils.Roles(1));
roleMembershipsLeft[RoleUtils.Roles(2)] = currentCommunity.roleMembershipsLeft(RoleUtils.Roles(2));
if (rolesCount == 3) roleMembershipsLeft[RoleUtils.Roles(3)] = currentCommunity.roleMembershipsLeft(RoleUtils.Roles(3));
roleMembershipsLeft[RoleUtils.Roles(1)] = currentCommunity
.roleMembershipsLeft(RoleUtils.Roles(1));
roleMembershipsLeft[RoleUtils.Roles(2)] = currentCommunity
.roleMembershipsLeft(RoleUtils.Roles(2));
if (rolesCount == 3)
roleMembershipsLeft[RoleUtils.Roles(3)] = currentCommunity
.roleMembershipsLeft(RoleUtils.Roles(3));

status = STATUS.IN_PROGRESS;
migratedFrom = _migrateFrom;
Expand Down Expand Up @@ -181,15 +191,8 @@ contract Community is ICommunity {
status = STATUS.MIGRATED;
}

function joinNewMember(
string memory uri,
uint256 role,
uint256 credits
) public override {
if (creditsToTransfer == 0) {
credits = 0;
}
_joinNewMember(msg.sender, uri, role, credits);
function joinNewMember(string memory uri, uint256 role) public override {
_joinNewMember(msg.sender, uri, role, 0);
}

// check if it's called only from deployer.
Expand All @@ -204,7 +207,10 @@ contract Community is ICommunity {
"No free spots left!"
);

require(roleMembershipsLeft[RoleUtils.Roles(role)] > 0, "All role positions are taken");
require(
roleMembershipsLeft[RoleUtils.Roles(role)] > 0,
"All role positions are taken"
);

require(!isMember(_member), "Already a member");

Expand Down
5 changes: 2 additions & 3 deletions contracts/community/ICommunity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ interface ICommunity {
// check if it's called only from deployer.
function joinNewMember(
string memory uri,
uint256 role,
uint256 credits
) external;
uint256 role
) external;

//function rolesCount() external view returns (uint256);
//function roleMembershiftsLeft(RoleUtils.Roles) external view returns (uint256);
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/MockCommunityV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ contract MockCommunityV2 is ICommunity {
status = STATUS.MIGRATED;
}

function joinNewMember(string memory uri, uint role, uint256 credits) public override {
_joinNewMember(msg.sender, uri, role, credits);
function joinNewMember(string memory uri, uint role) public override {
_joinNewMember(msg.sender, uri, role, 0);
}

// check if it's called only from deployer.
Expand Down
6 changes: 3 additions & 3 deletions scripts/deployDistributedTown.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const main = async () => {
const gigStatuses = await GigStatuses.deploy();
await gigStatuses.deployed();
console.log('gigStatusesAddress', gigStatuses.address)
const skillWalletAddress = '0x044F5A0F1fEE8cEa95Da4574de375A4Ea1DF39EF';
const skillWalletAddress = '0xdC8fDfBdddcce3b8DfFc345Bd426789a7b2534A1';

const addressProvider = await deploy('AddressProvider', [], {},
{
Expand All @@ -35,8 +35,8 @@ const main = async () => {
await distributedTown.deployed();

const a = await distributedTown.deployGenesisCommunities(0);
// await distributedTown.deployGenesisCommunities(1);
// await distributedTown.deployGenesisCommunities(2);
await distributedTown.deployGenesisCommunities(1);
await distributedTown.deployGenesisCommunities(2);
console.log(await a.wait());
console.log(a);

Expand Down
123 changes: 123 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
const skillWalletAddress = "0xdC8fDfBdddcce3b8DfFc345Bd426789a7b2534A1";
const communityAddress = "0x8d67dBEF4F5259B48BFb35458174bEaeE60734b8";

const { assert } = require("chai");
var ethers = require("ethers");

var communityAbi = require("../artifacts/contracts/community/Community.sol/Community.json")
.abi;

var gigsAbi = require("../artifacts/contracts/gigs/Gigs.sol/Gigs.json").abi;
var skillWalletAbi = require("./skillWalletAbi.json").abi;

const helpers = require("../test/helpers");
const fs = require("fs");

function mnemonic() {
try {
return fs.readFileSync("./mnemonic.txt").toString().trim();
} catch (e) {
console.log(e);
}
return "";
}

let keyPair = {
pubKey:
"0442f1fa140d9fcb8ddca188ffc83d1512bcb3be4de464512169c4555f3f7a6ca5e3afb51f7604cdbbf4234b6958852d0b4c57b0ba18af4350a652e889f7f6660a",
};

const provider = new ethers.providers.JsonRpcProvider(
// 'https://polygon-rpc.com/'
"https://matic-mumbai.chainstacklabs.com/"
);

// Wallet connected to a provider
const senderWalletMnemonic = ethers.Wallet.fromMnemonic(
mnemonic(),
"m/44'/60'/0'/0/0"
);

let signer = senderWalletMnemonic.connect(provider);

const skillWalletContract = new ethers.Contract(skillWalletAddress, skillWalletAbi, signer)

const communityContract = new ethers.Contract(
communityAddress,
communityAbi,
signer
);

async function joinCommunity() {
// const newKeyPair = helpers.generateKeyPair();
// keyPair = newKeyPair;

const url =
"https://hub.textile.io/ipfs/bafkreicezefuc6einewxdqhlpefelzjponwdqt4vmp2byosq5uwpn7hgoq";
const joinedTx = await communityContract.joinNewMember(url, 1);
const joinCommunityTxResult = await joinedTx.wait();
const { events } = joinCommunityTxResult;
const memberAddedEventEmitted = events.find((e) => e.event === "MemberAdded");

assert.isOk(memberAddedEventEmitted, "MemberAdded event emitted");
console.log("[joinCommunity]:", "MemberAdded event emitted");
assert.isAbove(+memberAddedEventEmitted.args[1], -1, "TokenID is valid");
console.log("[joinCommunity]:", "TokenID is valid");
return memberAddedEventEmitted.args[1];
}


async function claim() {
// const newKeyPair = helpers.generateKeyPair();
// keyPair = newKeyPair;

const claimTx = await skillWalletContract.claim();
const claimTxResult = await claimTx.wait();
const { events } = claimTxResult;
const claimEventEmitted = events.find((e) => e.event === "SkillWalletClaimed");

assert.isOk(claimEventEmitted, "SkillWalletClaimed event emitted");
console.log("[claim]:", "SkillWalletClaimed event emitted");
return;
}


async function getOSMAddr() {
const osmAddr = await skillWalletContract.getOSMAddress();
console.log(osmAddr);
}

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function getCommunity(tokenID) {
const com = await skillWalletContract.getActiveCommunity(tokenID);
console.log("[active community]", com);
}

async function test() {
// await joinCommunity();
await claim();
// await getOSMAddr();
// const tokenId = 14;

// await getCommunity(tokenId);
// // // const tokenId = await joinCommunity()
// // // await claim();

// await addPubKeyToSkillWallet(tokenId)
// const activateRes = await validateSW(tokenId, 0);
// await isSkillWalletActivated(tokenId)
// console.log(
// '[sleep]',
// 'waiting 10 seconds for the chainlink validation to pass',
// )
// await sleep(10000)
// await isSkillWalletActivated(tokenId)

// await getmetadata(tokenId)
// await addDiscordID();
}

test();
Loading