Skip to content

Commit

Permalink
added master node delegatee
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed Oct 12, 2023
1 parent a033577 commit 388329d
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ packages/subgraph/tests/.latest.json
packages/subgraph/tests/helpers/extended-schema.ts

packages/contracts/deployments/
packages/contracts/dao-initial-data.json

.vscode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"apothem": {
"daoEnsSubDomain": "thisissometext-0",
"daoEnsSubDomain": "dao-number-3000",
"metadata": {
"name": "DAOFIN",
"description": "This is DAOFIN",
Expand All @@ -17,8 +17,11 @@
]
},
"amounts": ["1", "2"],
"xdcValidatorAddress": "0x0000000000000000000000000000000000000088",
"judiciaryList": ["0x5bfC74606bdA5092cefdede1A89c14624F6bF198"],
"xdcValidatorAddress": "0xB0658F0295bbBf918eec097F5730AE0AD6D8CF8a",
"judiciaryList": [
"0x5bfC74606bdA5092cefdede1A89c14624F6bF198",
"0x168c49bC0dcF7544318c4b094769E4d72a319944"
],
"masterNodeVotingSettings": {
"supportThreshold": "0",
"minParticipation": "2",
Expand All @@ -36,6 +39,7 @@
"minParticipation": "0",
"minDuration": "0",
"minVotingPower": "1"
}
},
"dummyMasterNodeAddresses": ["0x7cFB093b4fca4845D73c72B23daa6C9A47C0b3f7"]
}
}
27 changes: 25 additions & 2 deletions packages/contracts/deploy/03_create_dao/01_create_dao.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DaoData from '../../dao-initial-data.json';
import {DaofinPluginSetupParams} from '../../plugin-settings';
import {ADDRESS_ZERO} from '../../test/unit-testing/daofin-common';
import {XDCValidator__factory} from '../../typechain';
import {
JudiciaryCommittee,
MasterNodeCommittee,
Expand Down Expand Up @@ -38,12 +39,12 @@ export type DaofinPluginInstall = {
electionPeriods: BigNumberish[];
};
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const [deployer] = await hre.ethers.getSigners();
const [, deployer] = await hre.ethers.getSigners();
const network = process.env.NETWORK_NAME
? process.env.NETWORK_NAME
: hre.network.name;

const {METADATA} = DaofinPluginSetupParams;
const {METADATA, XDCMasterNodeTestingAddress} = DaofinPluginSetupParams;

// @ts-ignore
const daoFactoryAddress = activeContractsList[network].DAOFactory;
Expand Down Expand Up @@ -218,6 +219,28 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log => pspInterface.parseLog(log).args[1]
),
});
console.log(network);

if (network === 'apothem' || network === 'anvil') {
const validatorContract = XDCValidator__factory.connect(
XDCMasterNodeTestingAddress,
deployer
);

for (let i = 0; i < daoParams.dummyMasterNodeAddresses.length; i++) {
const address = daoParams.dummyMasterNodeAddresses[i];
console.log({address});

const isExist = await validatorContract.isCandidate(address);
console.log('XDCValidatorMock', `${address} : ${isExist}`);

if (isExist) return;
const tx = await validatorContract.addCandidate(address);
console.log('XDCValidatorMock', `${address} : ${tx.hash}`);

await tx.wait();
}
}
};

export default func;
Expand Down
16 changes: 8 additions & 8 deletions packages/contracts/plugin-info.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"apothem": {
"repo": "beny-plugin-repo-10014",
"address": "0x6119cF5BBb8Eb87ea9b2e9c5B0fE67Dc03F93afe",
"repo": "beny-plugin-repo-2000",
"address": "0x5C27C4831C8E511fB197E6018710F496600aC9ed",
"args": [],
"blockNumberOfDeployment": 55230972,
"blockNumberOfDeployment": 55471685,
"releases": {
"1": {
"builds": {
"1": {
"setup": {
"name": "DaofinPluginSetup",
"address": "0x6F6f570F45833E249e27022648a26F4076F48f78",
"address": "0x4bf010f1b9beDA5450a8dD702ED602A104ff65EE",
"args": [],
"blockNumberOfDeployment": 55167967
"blockNumberOfDeployment": 55471690
},
"implementation": {
"name": "DaofinPlugin",
"address": "0x25141BdAc698910858129c81cfd9C32a8B3b3f87",
"address": "0x4E0C596bE5FE217cB80AeB4C47C72701DFF0F6BC",
"args": [],
"blockNumberOfDeployment": 55167967
"blockNumberOfDeployment": 55471690
},
"helpers": [],
"buildMetadataURI": "ipfs://QmYkd6CnaDpeeHg2YnaHCFFRtdvBYw1p3R25skJKCgqZot",
"blockNumberOfPublication": 55230979
"blockNumberOfPublication": 55471694
}
},
"releaseMetadataURI": "ipfs://QmbJWAESqCsf4RFCqEY7jecCashj8usXiyDNfKtZCwwzGb"
Expand Down
4 changes: 3 additions & 1 deletion packages/contracts/plugin-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import daofinBuildMetadata from './src/build-metadata.json';
import daofinReleaseMetadata from './src/release-metadata.json';

export const DaofinPluginSetupParams: PluginSetupParams = {
PLUGIN_REPO_ENS_NAME: 'beny-plugin-repo-10014',
PLUGIN_REPO_ENS_NAME: 'beny-plugin-repo-2000',
PLUGIN_CONTRACT_NAME: 'DaofinPlugin',
PLUGIN_SETUP_CONTRACT_NAME: 'DaofinPluginSetup',
VERSION: {
Expand All @@ -13,6 +13,7 @@ export const DaofinPluginSetupParams: PluginSetupParams = {
build: daofinBuildMetadata,
release: daofinReleaseMetadata,
},
XDCMasterNodeTestingAddress: '0xB0658F0295bbBf918eec097F5730AE0AD6D8CF8a',
};

// Types
Expand All @@ -29,4 +30,5 @@ export type PluginSetupParams = {
build: {[k: string]: any};
release: {[k: string]: any};
};
XDCMasterNodeTestingAddress: string;
};
2 changes: 1 addition & 1 deletion packages/js-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@xinfin/osx-daofin-sdk-client",
"author": "Aragon Association",
"version": "1.0.50",
"version": "1.0.52",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/osx-daofin-sdk-client.esm.js",
Expand Down
23 changes: 22 additions & 1 deletion packages/js-client/src/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ProposalMetadata, findLog } from '@xinfin/osx-client-common';
import {
DaofinPlugin,
DaofinPlugin__factory,
XDCValidator__factory,
} from '@xinfin/osx-daofin-contracts-ethers';
import {
ProposalCreationStepValue,
Expand Down Expand Up @@ -265,7 +266,7 @@ export class DaofinClientMethods
this.web3.getProvider()
);
const isJudiciaryMember = await daofin.isJudiciaryMember(member);
if (!isJudiciaryMember) return null;
if (isJudiciaryMember === undefined) return null;
return isJudiciaryMember;
};
public async *updateOrJoinMasterNodeDelegatee(
Expand Down Expand Up @@ -305,4 +306,24 @@ export class DaofinClientMethods
if (!isPeopleHouse) return null;
return isPeopleHouse;
};
isXDCValidatorCadidate: (member: string) => Promise<boolean> = async (
member
) => {
const signer = this.web3.getConnectedSigner();
const daofin = DaofinPlugin__factory.connect(
this.pluginAddress,
this.web3.getProvider()
);
const settings = await this.getGlobalSettings();
if (!settings) return null;

const validatorContract = XDCValidator__factory.connect(
await settings.xdcValidator,
this.web3.getProvider()
);
const isCandidate = await validatorContract.isCandidate(member);
if (isCandidate === undefined) return null;

return isCandidate;
};
}
1 change: 1 addition & 0 deletions packages/js-client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface IDaofinClientMethods {
) => AsyncGenerator<UpdateOrJoinMasterNodeDelegateeStepValue>;
isMasterNodeDelegatee: (delegatee: string) => Promise<boolean>;
isPeopleHouse: (member: string) => Promise<boolean>;
isXDCValidatorCadidate: (member: string) => Promise<boolean>;
}
export interface IDaofinClientEncoding {}
export interface IDaofinClientDecoding {
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/manifest/subgraph.placeholder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ templates:
handler: handleProposalCreated
- event: Deposited(address,uint256)
handler: handleDeposited
- event: MasterNodeDelegateeUpdated(address,address)
handler: handleMasterNodeDelegateeUpdated
file: ./src/plugin/plugin.ts

15 changes: 15 additions & 0 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Plugin implements PluginInstallation @entity {
proposals: [PluginProposal!]! @derivedFrom(field: "plugin")
deposits: [PluginDeposit!]! @derivedFrom(field: "plugin")
judiciaries: [PluginJudiciary!]! @derivedFrom(field: "plugin")
masterNodeDelegatees: [PluginMasterNodeDelegatee!]!
@derivedFrom(field: "plugin")
}

type PluginMember @entity {
Expand Down Expand Up @@ -126,3 +128,16 @@ type PluginJudiciary @entity {
action: BigInt!
creationDate: BigInt
}
type PluginMasterNodeDelegatee @entity {
id: ID! # pluginId + block number
masterNode: Bytes!
member: Bytes!
action: BigInt!
state: String
snapshotBlock: BigInt
plugin: Plugin!
dao: Dao!
txHash: Bytes
creationDate: BigInt
updatedDate: BigInt
}
55 changes: 54 additions & 1 deletion packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ import {
PluginDeposit,
PluginJudiciary,
Dao,
PluginMasterNodeDelegatee,
} from '../../generated/schema';
import {
ProposalCreated,
Deposited,
DaofinPlugin,
JudiciaryChanged,
UpdateOrJoinMasterNodeDelegateeCall,

Check failure on line 16 in packages/subgraph/src/plugin/plugin.ts

View workflow job for this annotation

GitHub Actions / tests

'UpdateOrJoinMasterNodeDelegateeCall' is defined but never used. Allowed unused vars must match /_/u

Check failure on line 16 in packages/subgraph/src/plugin/plugin.ts

View workflow job for this annotation

GitHub Actions / tests

'UpdateOrJoinMasterNodeDelegateeCall' is defined but never used. Allowed unused vars must match /_/u
MasterNodeDelegateeUpdated,
} from '../../generated/templates/DaofinPlugin/DaofinPlugin';
import {
getDepositId,
getJudiciaryId,
getMasterNodeDelegateeId,
getProposalId,
} from '../../utils/proposals';
import {Address, dataSource} from '@graphprotocol/graph-ts';
import {
Address,
BigInt,
ByteArray,

Check failure on line 28 in packages/subgraph/src/plugin/plugin.ts

View workflow job for this annotation

GitHub Actions / tests

'ByteArray' is defined but never used. Allowed unused vars must match /_/u

Check failure on line 28 in packages/subgraph/src/plugin/plugin.ts

View workflow job for this annotation

GitHub Actions / tests

'ByteArray' is defined but never used. Allowed unused vars must match /_/u
Bytes,

Check failure on line 29 in packages/subgraph/src/plugin/plugin.ts

View workflow job for this annotation

GitHub Actions / tests

'Bytes' is defined but never used. Allowed unused vars must match /_/u

Check failure on line 29 in packages/subgraph/src/plugin/plugin.ts

View workflow job for this annotation

GitHub Actions / tests

'Bytes' is defined but never used. Allowed unused vars must match /_/u
dataSource,
} from '@graphprotocol/graph-ts';

export function handleProposalCreated(event: ProposalCreated): void {
let context = dataSource.context();
Expand Down Expand Up @@ -127,3 +137,46 @@ export function handleJudiciaryChanged(event: JudiciaryChanged): void {
entity.snapshotBlock = event.block.number;
entity.save();
}
export function handleMasterNodeDelegateeUpdated(
event: MasterNodeDelegateeUpdated
): void {
let context = dataSource.context();
let daoId = context.getString('daoAddress');
let pluginInstallationId = context.getString('pluginInstallationId');
let dao = Dao.load(daoId.toString());
if (!dao) return;
let plugin = Plugin.load(pluginInstallationId);
if (!plugin) return;

let id = getMasterNodeDelegateeId(
pluginInstallationId,
event.params._masterNode
);
let entity = PluginMasterNodeDelegatee.load(id);
if (entity) {
if (entity.masterNode == event.params._masterNode) {
if (entity.member != event.params._delegatee) {
entity.state = 'CHANGED';
entity.member = event.params._delegatee;
entity.updatedDate = event.block.timestamp;

entity.save();
}
}
} else {
entity = new PluginMasterNodeDelegatee(id);

entity.dao = daoId;
entity.plugin = pluginInstallationId;

entity.member = event.params._delegatee;
entity.masterNode = event.params._masterNode;
entity.creationDate = event.block.timestamp;
entity.snapshotBlock = event.block.number;

entity.action = BigInt.fromString('0');
entity.txHash = event.transaction.hash;

entity.save();
}
}
6 changes: 6 additions & 0 deletions packages/subgraph/utils/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ export function getJudiciaryId(
.concat('_')
.concat(bigIntToBytes32(blockNumber));
}
export function getMasterNodeDelegateeId(
pluginId: string,
masterNode: Address
): string {
return pluginId.concat('_').concat(masterNode.toHexString());
}

0 comments on commit 388329d

Please sign in to comment.