From be099fd48f569045c257fc567e7931afbc191128 Mon Sep 17 00:00:00 2001 From: Rekard0 <5880388+Rekard0@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:57:05 +0100 Subject: [PATCH 1/6] update relations --- packages/subgraph/schema.graphql | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 89d2daf6d..5410c4b76 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -163,12 +163,15 @@ type Dao @entity { balances: [TokenBalance!]! @derivedFrom(field: "dao") contractPermissionIds: [ContractPermissionId!]! @derivedFrom(field: "dao") permissions: [Permission!]! @derivedFrom(field: "dao") - pluginInstallations: [PluginInstallation!]! @derivedFrom(field: "dao") - plugins: [IPluginInstallation!]! @derivedFrom(field: "dao") # TODO: Delete or refactor after the plugins left the Aragon OSx subgraph proposals: [Proposal!] @derivedFrom(field: "dao") trustedForwarder: Bytes signatureValidator: Bytes standardCallbacks: [StandardCallback!] @derivedFrom(field: "dao") + + pluginPreparations: [PluginPreparation!]! @derivedFrom(field: "dao") + pluginInstallations: [PluginInstallation!]! @derivedFrom(field: "dao") + + plugins: [IPlugin!]! @derivedFrom(field: "dao") # TODO: Delete or refactor after the plugins left the Aragon OSx subgraph } # Plugins @@ -258,11 +261,13 @@ enum PluginPreparationState { Uninstalled } -interface IPluginInstallation { - id: ID! # psp installationId +interface IPlugin { + id: ID! # plugin address dao: Dao! pluginAddress: Bytes! + installation: [PluginInstallation!] @derivedFrom(field: "pluginAddress") + # TODO: Uncomment as soon as the plugins have their own subgraph # appliedPreparation: PluginPreparation # appliedSetupId: Bytes # The setupId of the application see PSP documentation for more info @@ -304,7 +309,7 @@ enum VotingMode { # TokenVoting -type TokenVotingPlugin implements IPluginInstallation @entity { +type TokenVotingPlugin implements IPlugin @entity { "TODO: attributes should be appended to Plugins once plugin is separated from Aragon OSx" id: ID! dao: Dao! @@ -384,7 +389,7 @@ type TokenVotingProposal implements Proposal @entity { # AddresslistVoting -type AddresslistVotingPlugin implements IPluginInstallation @entity { +type AddresslistVotingPlugin implements IPlugin @entity { "TODO: attributes should be appended to Plugin once plugin is seperated from Aragon OSx" id: ID! dao: Dao! @@ -455,7 +460,7 @@ type AddresslistVotingProposal implements Proposal @entity { # Admin (plugin) -type AdminPlugin implements IPluginInstallation @entity { +type AdminPlugin implements IPlugin @entity { "TODO: attributes should be appended to Plugin once plugin is separated from Aragon OSx" id: ID! dao: Dao! @@ -498,7 +503,7 @@ type AdminProposal implements Proposal @entity { # Multisig -type MultisigPlugin implements IPluginInstallation @entity { +type MultisigPlugin implements IPlugin @entity { "TODO: attributes should be appended to Plugin once plugin is seperated from Aragon OSx" id: ID! dao: Dao! From e1ee5296f73b7ec706bb696d506d1dabb883533f Mon Sep 17 00:00:00 2001 From: Rekard0 <5880388+Rekard0@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:46:24 +0100 Subject: [PATCH 2/6] fix relations --- packages/subgraph/schema.graphql | 21 ++++++++++++------- .../src/plugin/pluginSetupProcessor.ts | 4 ++-- .../tests/plugin/pluginSetupProcessor.test.ts | 9 ++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 5410c4b76..7198b4eea 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -163,15 +163,12 @@ type Dao @entity { balances: [TokenBalance!]! @derivedFrom(field: "dao") contractPermissionIds: [ContractPermissionId!]! @derivedFrom(field: "dao") permissions: [Permission!]! @derivedFrom(field: "dao") - proposals: [Proposal!] @derivedFrom(field: "dao") + proposals: [Proposal!]! @derivedFrom(field: "dao") trustedForwarder: Bytes signatureValidator: Bytes - standardCallbacks: [StandardCallback!] @derivedFrom(field: "dao") + standardCallbacks: [StandardCallback!]! @derivedFrom(field: "dao") - pluginPreparations: [PluginPreparation!]! @derivedFrom(field: "dao") - pluginInstallations: [PluginInstallation!]! @derivedFrom(field: "dao") - - plugins: [IPlugin!]! @derivedFrom(field: "dao") # TODO: Delete or refactor after the plugins left the Aragon OSx subgraph + plugins: [IPlugin!]! @derivedFrom(field: "dao") # TODO: Refactor to `PluginInstallation` after the plugins left the Aragon OSx subgraph } # Plugins @@ -239,7 +236,7 @@ type PluginPreparation @entity(immutable: true) { type PluginInstallation @entity { id: ID! # psp installationId dao: Dao! - pluginAddress: Bytes # The plugin address provided by the applied preparation + plugin: IPlugin # The plugin address as id provided by the applied preparation appliedPreparation: PluginPreparation appliedSetupId: Bytes # The setupId of the application see PSP documentation for more info appliedVersion: PluginVersion # Stored to track installations in the different plugin versions @@ -266,7 +263,7 @@ interface IPlugin { dao: Dao! pluginAddress: Bytes! - installation: [PluginInstallation!] @derivedFrom(field: "pluginAddress") + installation: [PluginInstallation!]! @derivedFrom(field: "plugin") # TODO: Uncomment as soon as the plugins have their own subgraph # appliedPreparation: PluginPreparation @@ -315,6 +312,8 @@ type TokenVotingPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! + installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + proposals: [TokenVotingProposal!]! @derivedFrom(field: "plugin") votingMode: VotingMode supportThreshold: BigInt @@ -395,6 +394,8 @@ type AddresslistVotingPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! + installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + proposals: [AddresslistVotingProposal!]! @derivedFrom(field: "plugin") votingMode: VotingMode supportThreshold: BigInt @@ -466,6 +467,8 @@ type AdminPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! + installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + proposals: [AdminProposal!]! @derivedFrom(field: "plugin") administrators: [AdministratorAdminPlugin!]! @derivedFrom(field: "plugin") } @@ -509,6 +512,8 @@ type MultisigPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! + installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + proposalCount: BigInt proposals: [MultisigProposal!]! @derivedFrom(field: "plugin") members: [MultisigApprover!]! @derivedFrom(field: "plugin") diff --git a/packages/subgraph/src/plugin/pluginSetupProcessor.ts b/packages/subgraph/src/plugin/pluginSetupProcessor.ts index e734e20c7..2fa0e52de 100644 --- a/packages/subgraph/src/plugin/pluginSetupProcessor.ts +++ b/packages/subgraph/src/plugin/pluginSetupProcessor.ts @@ -98,7 +98,7 @@ export function handleInstallationApplied(event: InstallationApplied): void { pluginEntity.appliedPluginRepo = pluginPreparationEntity.pluginRepo; pluginEntity.appliedVersion = pluginPreparationEntity.pluginVersion; } - pluginEntity.pluginAddress = event.params.plugin; + pluginEntity.plugin = event.params.plugin.toHexString(); pluginEntity.appliedPreparation = preparationId; pluginEntity.appliedSetupId = event.params.appliedSetupId; pluginEntity.state = 'Installed'; @@ -184,7 +184,7 @@ export function handleUpdateApplied(event: UpdateApplied): void { pluginEntity.appliedPluginRepo = pluginPreparationEntity.pluginRepo; pluginEntity.appliedVersion = pluginPreparationEntity.pluginVersion; } - pluginEntity.pluginAddress = event.params.plugin; + pluginEntity.plugin = event.params.plugin.toHexString(); pluginEntity.appliedPreparation = preparationId; pluginEntity.appliedSetupId = event.params.appliedSetupId; pluginEntity.state = 'Installed'; diff --git a/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts b/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts index 7047f775c..5bc71ae05 100644 --- a/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts +++ b/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts @@ -8,7 +8,8 @@ import { ADDRESS_ZERO, PLUGIN_SETUP_ID, ADDRESS_SIX, - APPLIED_PLUGIN_SETUP_ID + APPLIED_PLUGIN_SETUP_ID, + CONTRACT_ADDRESS } from '../constants'; import { createInstallationAppliedEvent, @@ -43,7 +44,7 @@ import { test('InstallationPrepared event', function() { let dao = DAO_ADDRESS; - let plugin = ADDRESS_ONE; + let plugin = CONTRACT_ADDRESS; let setupId = PLUGIN_SETUP_ID; let pluginSetupRepo = ADDRESS_TWO; let pluginVersionId = `${pluginSetupRepo}_1_1`; @@ -261,7 +262,7 @@ test('InstallationApplied event', function() { assert.fieldEquals( 'PluginInstallation', installationIdString, - 'pluginAddress', + 'plugin', plugin.toLowerCase() ); assert.fieldEquals( @@ -496,7 +497,7 @@ test('UpdateApplied event', function() { assert.fieldEquals( 'PluginInstallation', installationIdString, - 'pluginAddress', + 'plugin', plugin.toLowerCase() ); assert.fieldEquals( From 0830c228174af2716688b43dd2b9b6ebfaebc631 Mon Sep 17 00:00:00 2001 From: Rekard0 <5880388+Rekard0@users.noreply.github.com> Date: Mon, 6 Mar 2023 12:42:31 +0100 Subject: [PATCH 3/6] update change log --- packages/subgraph/CHANGELOG.md | 16 ++++++++++++++++ packages/subgraph/schema.graphql | 10 +++++----- .../tests/plugin/pluginSetupProcessor.test.ts | 10 +++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/subgraph/CHANGELOG.md b/packages/subgraph/CHANGELOG.md index af8aa3633..f2e6e7de5 100644 --- a/packages/subgraph/CHANGELOG.md +++ b/packages/subgraph/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [UPCOMING] + +### Added + +- Added `installations` to `IPlugin`. + +### Changed + +- Changed `plugin` field of `Dao` from `IPluginInstallation` to `IPlugin`. +- Changed `pluginAddress` field of `PluginInstallation` to `plugin`. +- Changed `IPluginInstallation` to `IPlugin`. + +### Removed + +- Removed `pluginInstallations` from `Dao`. + ## [1.0.1] ### Added diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 7198b4eea..f0d686427 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -263,7 +263,7 @@ interface IPlugin { dao: Dao! pluginAddress: Bytes! - installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + installations: [PluginInstallation!]! @derivedFrom(field: "plugin") # TODO: Uncomment as soon as the plugins have their own subgraph # appliedPreparation: PluginPreparation @@ -312,7 +312,7 @@ type TokenVotingPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! - installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + installations: [PluginInstallation!]! @derivedFrom(field: "plugin") proposals: [TokenVotingProposal!]! @derivedFrom(field: "plugin") votingMode: VotingMode @@ -394,7 +394,7 @@ type AddresslistVotingPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! - installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + installations: [PluginInstallation!]! @derivedFrom(field: "plugin") proposals: [AddresslistVotingProposal!]! @derivedFrom(field: "plugin") votingMode: VotingMode @@ -467,7 +467,7 @@ type AdminPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! - installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + installations: [PluginInstallation!]! @derivedFrom(field: "plugin") proposals: [AdminProposal!]! @derivedFrom(field: "plugin") administrators: [AdministratorAdminPlugin!]! @derivedFrom(field: "plugin") @@ -512,7 +512,7 @@ type MultisigPlugin implements IPlugin @entity { dao: Dao! pluginAddress: Bytes! - installation: [PluginInstallation!]! @derivedFrom(field: "plugin") + installations: [PluginInstallation!]! @derivedFrom(field: "plugin") proposalCount: BigInt proposals: [MultisigProposal!]! @derivedFrom(field: "plugin") diff --git a/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts b/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts index 5bc71ae05..ee0cd2eef 100644 --- a/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts +++ b/packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts @@ -30,7 +30,10 @@ import { import {assert, clearStore, test} from 'matchstick-as'; import {PluginPreparation} from '../../generated/schema'; import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts'; -import {getSupportsInterface} from '../../tests/dao/utils'; +import { + createDaoEntityState, + getSupportsInterface +} from '../../tests/dao/utils'; import { ADDRESSLIST_VOTING_INTERFACE, ADMIN_INTERFACE, @@ -224,6 +227,11 @@ test('InstallationPrepared event', function() { 'InstallationPrepared' ); + // TODO: once matchstick can support polymorphism, we should have a test like: + // @dev: create a DAO in state so that we can check if IPlugin will be linked to the DAO + // let daoEntity = createDaoEntityState() + // assert.i32Equals(daoEntity.plugins.length, 1); + clearStore(); }); From d5d1b362be666741e0e7bfe1c69f133a8a2ab102 Mon Sep 17 00:00:00 2001 From: Rekard0 <5880388+Rekard0@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:49:26 +0100 Subject: [PATCH 4/6] update comment --- packages/subgraph/schema.graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 1812a6874..18fd41976 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -232,7 +232,7 @@ type PluginPreparation @entity(immutable: true) { type: PluginPreparationType! } -# Don't implement IPluginInstallation. Otherwise it would show up under plugins in the DAO entity +# Don't implement IPlugin. Otherwise it would show up under plugins in the DAO entity type PluginInstallation @entity { id: ID! # psp installationId dao: Dao! From 53c2d7f6532f09b811502e80a7cf0d591ffae435 Mon Sep 17 00:00:00 2001 From: Rekard0 <5880388+Rekard0@users.noreply.github.com> Date: Mon, 6 Mar 2023 16:02:37 +0100 Subject: [PATCH 5/6] use variable --- packages/subgraph/src/plugin/pluginSetupProcessor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/subgraph/src/plugin/pluginSetupProcessor.ts b/packages/subgraph/src/plugin/pluginSetupProcessor.ts index 2fa0e52de..998cc463a 100644 --- a/packages/subgraph/src/plugin/pluginSetupProcessor.ts +++ b/packages/subgraph/src/plugin/pluginSetupProcessor.ts @@ -98,7 +98,7 @@ export function handleInstallationApplied(event: InstallationApplied): void { pluginEntity.appliedPluginRepo = pluginPreparationEntity.pluginRepo; pluginEntity.appliedVersion = pluginPreparationEntity.pluginVersion; } - pluginEntity.plugin = event.params.plugin.toHexString(); + pluginEntity.plugin = plugin; pluginEntity.appliedPreparation = preparationId; pluginEntity.appliedSetupId = event.params.appliedSetupId; pluginEntity.state = 'Installed'; @@ -184,7 +184,7 @@ export function handleUpdateApplied(event: UpdateApplied): void { pluginEntity.appliedPluginRepo = pluginPreparationEntity.pluginRepo; pluginEntity.appliedVersion = pluginPreparationEntity.pluginVersion; } - pluginEntity.plugin = event.params.plugin.toHexString(); + pluginEntity.plugin = plugin; pluginEntity.appliedPreparation = preparationId; pluginEntity.appliedSetupId = event.params.appliedSetupId; pluginEntity.state = 'Installed'; From 8a50f02ed58aeb5138eb62d8bc81b6d00f763ea3 Mon Sep 17 00:00:00 2001 From: Giorgi Lagidze Date: Mon, 6 Mar 2023 20:00:31 +0400 Subject: [PATCH 6/6] release id generation --- packages/subgraph/src/plugin/pluginRepo.ts | 14 +++++++---- .../src/plugin/pluginSetupProcessor.ts | 24 ++++++++++++++++--- packages/subgraph/src/plugin/utils.ts | 15 +++++++++++- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/packages/subgraph/src/plugin/pluginRepo.ts b/packages/subgraph/src/plugin/pluginRepo.ts index 7997f8631..bb8364a20 100644 --- a/packages/subgraph/src/plugin/pluginRepo.ts +++ b/packages/subgraph/src/plugin/pluginRepo.ts @@ -7,6 +7,8 @@ import { PluginSetup, PluginRelease } from '../../generated/schema'; +import {getPluginVersionId} from './utils'; +import {log} from '@graphprotocol/graph-ts'; export function handleVersionCreated(event: VersionCreated): void { // PluginSetup @@ -20,11 +22,15 @@ export function handleVersionCreated(event: VersionCreated): void { // PluginVersion let pluginRepoId = event.address.toHexString(); - let pluginRelease = event.params.release.toString(); - let pluginReleaseId = pluginRepoId.concat('_').concat(pluginRelease); - let pluginVersionId = pluginReleaseId + let pluginReleaseId = pluginRepoId .concat('_') - .concat(event.params.build.toString()); + .concat(event.params.release.toString()); + + let pluginVersionId = getPluginVersionId( + pluginRepoId, + event.params.release, + event.params.build + ); let entity = new PluginVersion(pluginVersionId); entity.pluginRepo = event.address.toHexString(); diff --git a/packages/subgraph/src/plugin/pluginSetupProcessor.ts b/packages/subgraph/src/plugin/pluginSetupProcessor.ts index 998cc463a..45cb19035 100644 --- a/packages/subgraph/src/plugin/pluginSetupProcessor.ts +++ b/packages/subgraph/src/plugin/pluginSetupProcessor.ts @@ -15,6 +15,7 @@ import { import { addPlugin, getPluginInstallationId, + getPluginVersionId, PERMISSION_OPERATIONS } from './utils'; @@ -23,7 +24,12 @@ export function handleInstallationPrepared(event: InstallationPrepared): void { let plugin = event.params.plugin.toHexString(); let setupId = event.params.preparedSetupId.toHexString(); let pluginRepo = event.params.pluginSetupRepo.toHexString(); - let pluginVersionId = `${pluginRepo}_${event.params.versionTag.release}_${event.params.versionTag.build}`; + let pluginVersionId = getPluginVersionId( + pluginRepo, + event.params.versionTag.release, + event.params.versionTag.build + ); + let installationId = getPluginInstallationId(dao, plugin); if (!installationId) { log.error('Failed to get installationId', [dao, plugin]); @@ -110,7 +116,13 @@ export function handleUpdatePrepared(event: UpdatePrepared): void { let plugin = event.params.setupPayload.plugin.toHexString(); let setupId = event.params.preparedSetupId.toHexString(); let pluginRepo = event.params.pluginSetupRepo.toHexString(); - let pluginVersionId = `${pluginRepo}_${event.params.versionTag.release}_${event.params.versionTag.build}`; + + let pluginVersionId = getPluginVersionId( + pluginRepo, + event.params.versionTag.release, + event.params.versionTag.build + ); + let installationId = getPluginInstallationId(dao, plugin); if (!installationId) { log.error('Failed to get installationId', [dao, plugin]); @@ -200,7 +212,13 @@ export function handleUninstallationPrepared( let plugin = event.params.setupPayload.plugin.toHexString(); let setupId = event.params.preparedSetupId.toHexString(); let pluginRepo = event.params.pluginSetupRepo.toHexString(); - let pluginVersionId = `${pluginRepo}_${event.params.versionTag.release}_${event.params.versionTag.build}`; + + let pluginVersionId = getPluginVersionId( + pluginRepo, + event.params.versionTag.release, + event.params.versionTag.build + ); + let installationId = getPluginInstallationId(dao, plugin); if (!installationId) { log.error('Failed to get installationId', [dao, plugin]); diff --git a/packages/subgraph/src/plugin/utils.ts b/packages/subgraph/src/plugin/utils.ts index c2239c99d..6e61e7014 100644 --- a/packages/subgraph/src/plugin/utils.ts +++ b/packages/subgraph/src/plugin/utils.ts @@ -4,7 +4,8 @@ import { DataSourceContext, ethereum, crypto, - ByteArray + ByteArray, + log } from '@graphprotocol/graph-ts'; import {TokenVoting as TokenVotingContract} from '../../generated/templates/TokenVoting/TokenVoting'; @@ -204,3 +205,15 @@ export function getPluginInstallationId( } return null; } + +export function getPluginVersionId( + pluginRepo: string, + release: i32, + build: i32 +): string { + return pluginRepo + .concat('_') + .concat(release.toString()) + .concat('_') + .concat(build.toString()); +}