Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Signal Scheme #494

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
32899a9
first test adding metadata to GenericschemeProposal
plsdlr Nov 15, 2019
b688aca
Add Meta Field (string) to Generic Scheme Proposal. When Proposal is …
plsdlr Nov 16, 2019
a5ea7c5
Add new type GenericSignal in schema for UGenericScheme. Generic Sche…
plsdlr Nov 17, 2019
94dc03c
add entitiy in domain/schema.grapql, add mappings as signal.ts, add w…
plsdlr Nov 24, 2019
8bc854b
deleted meta from UGeneric scheme
plsdlr Nov 26, 2019
12a656c
testwrite into entity @signal / testread entity
plsdlr Nov 26, 2019
d321cf6
Add Address from DAO as ID of Signal
plsdlr Nov 26, 2019
42867e8
finished test - to get data from the graph run: npm run test -- test/…
plsdlr Dec 1, 2019
8bcbfa7
cleaned code up , add writesignal
plsdlr Dec 5, 2019
6e1fee2
added reading of ipfs files
plsdlr Dec 5, 2019
dadbbd0
add instruction and datavalues for test
plsdlr Dec 5, 2019
8e94988
add read Proposal Handler in signal.ts
plsdlr Jan 2, 2020
ba1b05b
building json
plsdlr Jan 2, 2020
ce20265
in progress
plsdlr Jan 2, 2020
c68079e
add generatestring, replace, generate and append - all in debug mode…
plsdlr Jan 5, 2020
00d966f
fixed small bug
plsdlr Jan 10, 2020
8aadf08
WIP
plsdlr Jan 16, 2020
259bcb4
add 2 testcases
plsdlr Jan 16, 2020
2ce6df2
fixed timer
plsdlr Jan 16, 2020
ac51f78
Merge branch 'master' into signalscheme
plsdlr Jan 19, 2020
2ef4277
modifyed Signal Test to fit new merged master
plsdlr Jan 19, 2020
28d1cda
add save character test
plsdlr Jan 22, 2020
561eaf1
small fix
plsdlr Jan 22, 2020
9cadf6e
before testnet
plsdlr Jan 23, 2020
daffbfc
update deps and migration image
shekhar-shubhendu Feb 19, 2020
e5ef415
add signal scheme mapping
shekhar-shubhendu Feb 19, 2020
5aa73e7
add signal scheme test
shekhar-shubhendu Feb 19, 2020
382b4fc
update private test dao
shekhar-shubhendu Feb 19, 2020
36395e8
add sample mapping
shekhar-shubhendu Feb 19, 2020
a14d154
merge upstream
shekhar-shubhendu Mar 3, 2020
dc3883a
update signal scheme writing logic
shekhar-shubhendu Mar 4, 2020
d9da1dd
update lint issues
shekhar-shubhendu Mar 6, 2020
d957df9
update signal scheme tests
shekhar-shubhendu Mar 7, 2020
3c9a88b
refactor test
shekhar-shubhendu Mar 7, 2020
ca3827d
Merge branch 'master' into signalscheme
shekhar-shubhendu Mar 9, 2020
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
39 changes: 39 additions & 0 deletions daos/private/testdao37.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "Hubristic Colorist",
"Avatar": "0x66301c44C22E0AEcd8ee8e6073A8300dC138A7af",
"DAOToken": "0xa6b58AE81c37b45BbeAC4C86866fA4b48e378139",
"Reputation": "0xB9e9DfAcb27f42357215aC3942810786C0cb75e2",
"Controller": "0xf577703d169b02e6807f80a4fCe029f7F91124CB",
"Schemes": [
{
"name": "GenericScheme",
"alias": "GenericSchemeAlias",
"address": "0xCE792fA3A9cd660fFD1be077CB1358A08Cf9106B",
"arcVersion": "0.0.1-rc.37"
},
{
"name": "ContributionRewardExt",
"alias": "ContributionRewardExt",
"address": "0xA10f1c26d7D4BCB1a93F84652177D2E2b320378B",
"arcVersion": "0.0.1-rc.36"
}
],
"StandAloneContracts": [
{
"name": "Wallet",
"address": "0x0E1598278e34793C83A4B1989d410DD0D7652b92",
"arcVersion": "0.0.1-rc.37"
},
{
"name": "ContributionRewardExt",
"address": "0xA10f1c26d7D4BCB1a93F84652177D2E2b320378B",
"arcVersion": "0.0.1-rc.36"
},
{
"name": "Competition",
"address": "0xD65d9Cb0fC54c95Ed021D74cB5164b5B30bB4B86",
"arcVersion": "0.0.1-rc.36"
}
],
"arcVersion": "0.0.1-rc.37"
}
15 changes: 15 additions & 0 deletions daos/rinkeby/devtest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "DevTest",
"Avatar": "0xBeB9C86C8D54e5C7cA2a7Dc67E50419FB98D9c05",
"DAOToken": "0x57bae8c98F913c10bBC23342596dE2E58E45466D",
"Reputation": "0x57bE0441440dFA2faE4Dd80Ec355Bc6db8257563",
"Controller": "0xB460481416B688b7E1c0D407f033567C687Fb607",
"Schemes": [
{
"name": "GenericScheme",
"alias": "GenericSchemeAlias",
"address": "0xad96d9685783bF29cB31eB038A44eC808aC17265"
}
],
"arcVersion": "0.0.1-rc.31"
}
14 changes: 14 additions & 0 deletions ops/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"mapping": "DAOToken",
"arcVersion": "0.0.1-rc.16"
},
{
"name": "NewSignalScheme",
"dao": "address",
"mapping": "SignalScheme",
mrrobot16 marked this conversation as resolved.
Show resolved Hide resolved
"arcVersion": "0.0.1-rc.37",
"address": "0x383A20B3635a10a4da8f733E8eA256cBcAcB4D4E"
},
{
"name": "GenesisProtocol",
"contractName": "GenesisProtocol",
Expand Down Expand Up @@ -737,6 +744,13 @@
"mapping": "DAOToken",
"arcVersion": "0.0.1-rc.19"
},
{
"name": "NewSignalScheme",
"dao": "address",
"mapping": "SignalScheme",
"arcVersion": "0.0.1-rc.37",
"address": "0xE06d896da40B73Cb02650220E480e20F38e7bE18"
},
{
"name": "Reputation",
"contractName": "Reputation",
Expand Down
127 changes: 64 additions & 63 deletions src/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, BigDecimal, BigInt, Bytes, Entity, store, Value} from '@graphprotocol/graph-ts';
import { Address, BigDecimal, BigInt, Bytes, Entity, store, Value } from '@graphprotocol/graph-ts';
import { setContractsInfo, setTemplatesInfo } from '../contractsInfo';
import { Transfer } from '../types/DAOToken/DAOToken';
import {
Expand Down Expand Up @@ -36,22 +36,23 @@ import {
import {
daoBountyRedemption,
insertGPRewards,
insertGPRewardsToHelper ,
reputationRedemption ,
insertGPRewardsToHelper,
reputationRedemption,
tokenRedemption,
} from './reward';
import { writeSignal } from './signal';
import { insertStake } from './stake';
import { getToken, insertToken, updateTokenTotalSupply } from './token';
import { insertVote } from './vote';

function isProposalValid(proposalId: string ): boolean {
function isProposalValid(proposalId: string): boolean {
let p = Proposal.load(proposalId);
return ((p != null) && (equalsBytes(p.paramsHash, new Bytes(32)) == false));
return ((p != null) && (equalsBytes(p.paramsHash, new Bytes(32)) == false));
}

function handleGPProposalPrivate(proposalId: string): void {
let gpProposal = GenesisProtocolProposal.load(proposalId);
if (gpProposal != null) {
let gpProposal = GenesisProtocolProposal.load(proposalId);
if (gpProposal != null) {
updateGPProposal(
gpProposal.address as Address,
gpProposal.proposalId,
Expand All @@ -66,7 +67,7 @@ function handleGPProposalPrivate(proposalId: string): void {
3, // Queued
gpProposal.address as Address,
);
}
}
}

export function handleNewContributionProposal(
Expand All @@ -92,26 +93,26 @@ export function handleNewContributionProposal(
}

export function handleNewSchemeRegisterProposal(
proposalId: string,
timestamp: BigInt,
avatar: Bytes,
votingMachine: Bytes,
descriptionHash: string,
schemeAddress: Address,
): void {
if (!daoModule.exists(avatar as Address)) {
return;
}
updateSRProposal(
proposalId,
timestamp,
avatar as Address,
votingMachine as Address,
descriptionHash,
schemeAddress,
);
handleGPProposalPrivate(proposalId);
}
proposalId: string,
timestamp: BigInt,
avatar: Bytes,
votingMachine: Bytes,
descriptionHash: string,
schemeAddress: Address,
): void {
if (!daoModule.exists(avatar as Address)) {
return;
}
updateSRProposal(
proposalId,
timestamp,
avatar as Address,
votingMachine as Address,
descriptionHash,
schemeAddress,
);
handleGPProposalPrivate(proposalId);
}

export function handleNewCallProposal(
avatar: Address,
Expand All @@ -138,12 +139,12 @@ export function handleStake(event: Stake): void {
if (equalsBytes(proposal.paramsHash, new Bytes(32))) {
return;
}
if (event.params._vote.toI32() == 1) {
if (event.params._vote.toI32() == 1) {
proposal.stakesFor = proposal.stakesFor.plus(event.params._amount);
} else {
proposal.stakesAgainst = proposal.stakesAgainst.plus(event.params._amount);
}
proposal.confidence = (new BigDecimal(proposal.stakesFor)) / (new BigDecimal(proposal.stakesAgainst));
proposal.confidence = (new BigDecimal(proposal.stakesFor)) / (new BigDecimal(proposal.stakesAgainst));
saveProposal(proposal);
insertStake(
eventId(event),
Expand Down Expand Up @@ -192,24 +193,20 @@ export function handleVoteProposal(event: VoteProposal): void {

export function confidenceLevelUpdate(proposalId: Bytes, confidenceThreshold: BigInt): void {
if (isProposalValid(proposalId.toHex())) {
updateProposalconfidence(proposalId, confidenceThreshold);
updateProposalconfidence(proposalId, confidenceThreshold);
}
}

export function handleRegisterScheme(avatar: Address,
nativeTokenAddress: Address,
nativeReputationAddress: Address,
scheme: Address ,
paramsHash: Bytes,
timestamp: BigInt): void {
export function handleRegisterScheme(avatar: Address, nativeTokenAddress: Address, nativeReputationAddress: Address,
scheme: Address, paramsHash: Bytes, timestamp: BigInt): void {
// Detect the first register scheme event which indicates a new DAO
let isFirstRegister = store.get(
'FirstRegisterSchemeFlag',
avatar.toHex(),
);
if (isFirstRegister == null) {
setContractsInfo();
let dao = daoModule.insertNewDAO(avatar, nativeTokenAddress , nativeReputationAddress);
let dao = daoModule.insertNewDAO(avatar, nativeTokenAddress, nativeReputationAddress);
insertToken(hexToAddress(dao.nativeToken), avatar.toHex());
insertReputation(
hexToAddress(dao.nativeReputation),
Expand Down Expand Up @@ -265,20 +262,20 @@ export function handleNativeTokenTransfer(event: Transfer): void {
}

export function handleExecuteProposal(event: ExecuteProposal): void {
if (isProposalValid(event.params._proposalId.toHex())) {
updateProposalExecution(event.params._proposalId, event.params._totalReputation, event.block.timestamp);
}
if (isProposalValid(event.params._proposalId.toHex())) {
updateProposalExecution(event.params._proposalId, event.params._totalReputation, event.block.timestamp);
}
}

export function handleStateChange(event: StateChange): void {
if (isProposalValid(event.params._proposalId.toHex())) {
updateProposalState(event.params._proposalId, event.params._proposalState, event.address);
if ((event.params._proposalState == 1) ||
(event.params._proposalState == 2)) {
insertGPRewards(event.params._proposalId, event.block.timestamp, event.address, event.params._proposalState);
}
updateProposalState(event.params._proposalId, event.params._proposalState, event.address);
if ((event.params._proposalState == 1) ||
(event.params._proposalState == 2)) {
insertGPRewards(event.params._proposalId, event.block.timestamp, event.address, event.params._proposalState);
}

addProposalStateChangeEvent(event.params._proposalId, event.transaction.from, event.block.timestamp);
addProposalStateChangeEvent(event.params._proposalId, event.transaction.from, event.block.timestamp);
}
}

Expand All @@ -288,20 +285,20 @@ export function handleExecutionStateChange(event: GPExecuteProposal): void {
}
}

export function handleGPRedemption(proposalId: Bytes, beneficiary: Address , timestamp: BigInt , type: string): void {
if (isProposalValid(proposalId.toHex())) {
if (type == 'token') {
tokenRedemption(proposalId, beneficiary, timestamp);
} else if (type == 'reputation') {
reputationRedemption(proposalId, beneficiary, timestamp);
} else {
daoBountyRedemption(proposalId, beneficiary, timestamp);
}
export function handleGPRedemption(proposalId: Bytes, beneficiary: Address, timestamp: BigInt, type: string): void {
if (isProposalValid(proposalId.toHex())) {
if (type == 'token') {
tokenRedemption(proposalId, beneficiary, timestamp);
} else if (type == 'reputation') {
reputationRedemption(proposalId, beneficiary, timestamp);
} else {
daoBountyRedemption(proposalId, beneficiary, timestamp);
}
}
}

export function daoRegister(dao: Address, tag: string): void {
daoModule.register(dao, tag);
daoModule.register(dao, tag);
}

export function addDaoMember(reputationHolder: ReputationHolder): void {
Expand All @@ -321,10 +318,14 @@ export function addDaoMember(reputationHolder: ReputationHolder): void {
}

export function removeDaoMember(reputationHolder: ReputationHolder): void {
let dao = getReputation(reputationHolder.contract.toHex()).dao;
if (dao == null) {
// reputation that's not attached to a DAO
return;
}
daoModule.decreaseDAOmembersCount(dao);
let dao = getReputation(reputationHolder.contract.toHex()).dao;
if (dao == null) {
// reputation that's not attached to a DAO
return;
}
daoModule.decreaseDAOmembersCount(dao);
}

export function addSignal(signalId: string, proposalId: string): void {
writeSignal(signalId, proposalId);
}
5 changes: 5 additions & 0 deletions src/domain/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,8 @@ type Event @entity {
dao: DAO
timestamp: BigInt!
}

type Signal @entity{
id: ID!
data: String
}
Loading