Skip to content

Commit

Permalink
Subgraph map ProposalCreated & ProposalExecuted
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 committed Oct 2, 2023
1 parent fa19c40 commit 31523f2
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 2,244 deletions.
1 change: 0 additions & 1 deletion packages/contracts/deployments/baseGoerli/.chainId

This file was deleted.

380 changes: 0 additions & 380 deletions packages/contracts/deployments/baseGoerli/MyPluginSetup.json

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/contracts/deployments/goerli/.chainId

This file was deleted.

380 changes: 0 additions & 380 deletions packages/contracts/deployments/goerli/MyPluginSetup.json

This file was deleted.

503 changes: 0 additions & 503 deletions packages/contracts/deployments/goerli/VocdoniVotingSetup.json

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const config: HardhatUserConfig = {
// https://hardhat.org/hardhat-network/#solidity-optimizer-support
optimizer: {
enabled: true,
runs: 1000000,
runs: 20000,
},
},
},
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/subgraph/manifest/subgraph.placeholder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ templates:
eventHandlers:
- event: ProposalCreated(indexed uint256,indexed bytes32,indexed address,uint64,uint64,uint64,(address,uint256,bytes)[],uint256)
handler: handleProposalCreated
- event: ProposalExecuted(indexed uint256)
handler: handleProposalExecuted
file: ./src/plugin/plugin.ts

8 changes: 4 additions & 4 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ type PluginProposal implements IProposal @entity {
allowFailureMap: BigInt!
failureMap: BigInt
plugin: Plugin!

pluginProposalId: BigInt!
vochainProposalId: Bytes!

creator: Bytes!
metadata: String
createdAt: BigInt!
startDate: BigInt!
endDate: BigInt!
creationBlockNumber: BigInt!
snapshotBlock: BigInt!
minApprovals: Int!
approvals: Int
potentiallyExecutable: Boolean!
expirationDate: BigInt!
executed: Boolean!
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down
18 changes: 4 additions & 14 deletions packages/subgraph/src/osx/pluginSetupProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,25 @@ import {
updatePreparationDataForUninstallationPrepared,
updatePreparationDataForUpdatePrepared,
} from '../plugin/pluginSetupProcessor';
import {DataSourceContext, log} from '@graphprotocol/graph-ts';
import {Address, DataSourceContext, log} from '@graphprotocol/graph-ts';

export function handleInstallationPrepared(event: InstallationPrepared): void {
const pluginRepo = event.params.pluginSetupRepo.toHexString();

if (pluginRepo === PLUGIN_REPO_ADDRESS) {
log.warning(
'========== FOUND Comparing pluginRepo {} == PLUGIN_REPO_ADDRESS {}',
[pluginRepo, PLUGIN_REPO_ADDRESS]
);
}
const pluginRepo = event.params.pluginSetupRepo;

// Check if the prepared plugin is our plugin.
const isThisPlugin = pluginRepo === PLUGIN_REPO_ADDRESS;
const isThisPlugin =
pluginRepo === Address.fromHexString(PLUGIN_REPO_ADDRESS);

if (!isThisPlugin) {
return;
}

log.warning('==========handleInstallationPrepared passed the repo check', []);

//////////////////////////////////////////////////////////////
// Index DAO
//////////////////////////////////////////////////////////////
const dao = event.params.dao;
const daoId = getDaoId(dao);

log.warning('==========found a dao {}', [daoId]);

let doaEntity = Dao.load(daoId);
if (!doaEntity) {
doaEntity = new Dao(daoId);
Expand Down
75 changes: 69 additions & 6 deletions packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {getPluginInstallationId} from '../../commons/ids';
import {Plugin} from '../../generated/schema';
import {ProposalCreated} from '../../generated/templates/Plugin/VocdoniVoting';
import {Action, Plugin, PluginProposal} from '../../generated/schema';
import {
ProposalCreated,
ProposalExecuted,
} from '../../generated/templates/Plugin/VocdoniVoting';
import {Address, dataSource} from '@graphprotocol/graph-ts';

export function handleProposalCreated(event: ProposalCreated): void {
Expand All @@ -16,10 +19,70 @@ export function handleProposalCreated(event: ProposalCreated): void {

if (installationId) {
let pluginEntity = Plugin.load(installationId.toHexString());
if (!pluginEntity) {
pluginEntity = new Plugin(installationId.toHexString());
pluginEntity.dao = daoId;
pluginEntity.save();
if (pluginEntity) {
const proposalId = event.params.proposalId;
const proposalEntityId = [
pluginAddress.toHexString(),
proposalId.toHexString(),
].join('_');

let proposalEntity = PluginProposal.load(proposalEntityId);
if (!proposalEntity) {
proposalEntity = new PluginProposal(proposalEntityId);

proposalEntity.dao = daoId;
proposalEntity.allowFailureMap = event.params.allowFailureMap;
proposalEntity.plugin = pluginAddress.toHexString();

proposalEntity.pluginProposalId = proposalId;
proposalEntity.vochainProposalId = event.params.vochainProposalId;

proposalEntity.creator = event.params.creator;
proposalEntity.startDate = event.params.startDate;
proposalEntity.endDate = event.params.endDate;
proposalEntity.expirationDate = event.params.expirationDate;
proposalEntity.createdAt = event.block.timestamp;
proposalEntity.creationBlockNumber = event.block.number;

proposalEntity.executed = false;

// store action entities
const actions = event.params.actions;
for (let index = 0; index < actions.length; index++) {
const action = actions[index];

const actionId = [proposalEntityId, index.toString()].join('_');

let actionEntity = new Action(actionId);
actionEntity.to = action.to;
actionEntity.value = action.value;
actionEntity.data = action.data;
actionEntity.dao = daoId;
actionEntity.proposal = proposalEntityId;
actionEntity.save();
}

proposalEntity.save();
}
}
}
}

export function handleProposalExecuted(event: ProposalExecuted): void {
const pluginAddress = event.address;

const proposalId = event.params.proposalId;
const proposalEntityId = [
pluginAddress.toHexString(),
proposalId.toHexString(),
].join('_');

const proposalEntity = PluginProposal.load(proposalEntityId);
if (proposalEntity) {
proposalEntity.executed = true;
proposalEntity.executionDate = event.block.timestamp;
proposalEntity.executionBlockNumber = event.block.number;
proposalEntity.executionTxHash = event.transaction.hash;
proposalEntity.save();
}
}
Loading

0 comments on commit 31523f2

Please sign in to comment.