Skip to content

Commit

Permalink
APP-1920 , APP-1854 : refactor relations (#317)
Browse files Browse the repository at this point in the history
* update relations

* fix relations

* update change log

* update comment

* use variable

* release id generation

---------

Co-authored-by: Giorgi Lagidze <glagh14@freeuni.edu.ge>
  • Loading branch information
Rekard0 and novaknole committed Mar 15, 2023
1 parent e4c1f93 commit aeb68e2
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 27 deletions.
8 changes: 8 additions & 0 deletions packages/subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `installations` to `IPlugin`.
- Added `PluginRelease`.
- Added `metadata` to `PluginVersion`.

### Changed

- Changed `plugin` field of `Dao` from `IPluginInstallation` to `IPlugin`.
- Changed `pluginAddress` field of `PluginInstallation` to `plugin`.
- Changed `IPluginInstallation` to `IPlugin`.
- Changed `release: Int!` to `release: PluginRelease!` in `PluginVersion`
- Changed `versions` to `releases` in `PluginRepo`.

### Removed

- Removed `pluginInstallations` from `Dao`.

## [1.0.1]

### Added
Expand Down
34 changes: 22 additions & 12 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ 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: [IProposal!] @derivedFrom(field: "dao")
proposals: [IProposal!]! @derivedFrom(field: "dao")
trustedForwarder: Bytes
signatureValidator: Bytes
standardCallbacks: [StandardCallback!] @derivedFrom(field: "dao")
standardCallbacks: [StandardCallback!]! @derivedFrom(field: "dao")

plugins: [IPlugin!]! @derivedFrom(field: "dao") # TODO: Refactor to `PluginInstallation` after the plugins left the Aragon OSx subgraph
}

# Plugins
Expand Down Expand Up @@ -242,11 +242,11 @@ 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!
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
Expand All @@ -268,11 +268,13 @@ enum PluginPreparationState {
Uninstalled
}

interface IPluginInstallation {
id: ID! # psp installationId
interface IPlugin {
id: ID! # plugin address
dao: Dao!
pluginAddress: Bytes!

installations: [PluginInstallation!]! @derivedFrom(field: "plugin")

# 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
Expand Down Expand Up @@ -330,12 +332,14 @@ 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!
pluginAddress: Bytes!

installations: [PluginInstallation!]! @derivedFrom(field: "plugin")

proposals: [TokenVotingProposal!]! @derivedFrom(field: "plugin")
votingMode: VotingMode
supportThreshold: BigInt
Expand Down Expand Up @@ -412,12 +416,14 @@ type TokenVotingProposal implements IProposal @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!
pluginAddress: Bytes!

installations: [PluginInstallation!]! @derivedFrom(field: "plugin")

proposals: [AddresslistVotingProposal!]! @derivedFrom(field: "plugin")
votingMode: VotingMode
supportThreshold: BigInt
Expand Down Expand Up @@ -485,12 +491,14 @@ type AddresslistVotingProposal implements IProposal @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!
pluginAddress: Bytes!

installations: [PluginInstallation!]! @derivedFrom(field: "plugin")

proposals: [AdminProposal!]! @derivedFrom(field: "plugin")
administrators: [AdministratorAdminPlugin!]! @derivedFrom(field: "plugin")
}
Expand Down Expand Up @@ -529,12 +537,14 @@ type AdminProposal implements IProposal @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!
pluginAddress: Bytes!

installations: [PluginInstallation!]! @derivedFrom(field: "plugin")

proposalCount: BigInt
proposals: [MultisigProposal!]! @derivedFrom(field: "plugin")
members: [MultisigApprover!]! @derivedFrom(field: "plugin")
Expand Down
14 changes: 10 additions & 4 deletions packages/subgraph/src/plugin/pluginRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
28 changes: 23 additions & 5 deletions packages/subgraph/src/plugin/pluginSetupProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
addPlugin,
getPluginInstallationId,
getPluginVersionId,
PERMISSION_OPERATIONS
} from './utils';

Expand All @@ -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]);
Expand Down Expand Up @@ -98,7 +104,7 @@ export function handleInstallationApplied(event: InstallationApplied): void {
pluginEntity.appliedPluginRepo = pluginPreparationEntity.pluginRepo;
pluginEntity.appliedVersion = pluginPreparationEntity.pluginVersion;
}
pluginEntity.pluginAddress = event.params.plugin;
pluginEntity.plugin = plugin;
pluginEntity.appliedPreparation = preparationId;
pluginEntity.appliedSetupId = event.params.appliedSetupId;
pluginEntity.state = 'Installed';
Expand All @@ -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]);
Expand Down Expand Up @@ -184,7 +196,7 @@ export function handleUpdateApplied(event: UpdateApplied): void {
pluginEntity.appliedPluginRepo = pluginPreparationEntity.pluginRepo;
pluginEntity.appliedVersion = pluginPreparationEntity.pluginVersion;
}
pluginEntity.pluginAddress = event.params.plugin;
pluginEntity.plugin = plugin;
pluginEntity.appliedPreparation = preparationId;
pluginEntity.appliedSetupId = event.params.appliedSetupId;
pluginEntity.state = 'Installed';
Expand All @@ -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]);
Expand Down
15 changes: 14 additions & 1 deletion packages/subgraph/src/plugin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
DataSourceContext,
ethereum,
crypto,
ByteArray
ByteArray,
log
} from '@graphprotocol/graph-ts';

import {TokenVoting as TokenVotingContract} from '../../generated/templates/TokenVoting/TokenVoting';
Expand Down Expand Up @@ -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());
}
19 changes: 14 additions & 5 deletions packages/subgraph/tests/plugin/pluginSetupProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,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,
Expand All @@ -43,7 +47,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`;
Expand Down Expand Up @@ -223,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();
});

Expand Down Expand Up @@ -261,7 +270,7 @@ test('InstallationApplied event', function() {
assert.fieldEquals(
'PluginInstallation',
installationIdString,
'pluginAddress',
'plugin',
plugin.toLowerCase()
);
assert.fieldEquals(
Expand Down Expand Up @@ -496,7 +505,7 @@ test('UpdateApplied event', function() {
assert.fieldEquals(
'PluginInstallation',
installationIdString,
'pluginAddress',
'plugin',
plugin.toLowerCase()
);
assert.fieldEquals(
Expand Down

0 comments on commit aeb68e2

Please sign in to comment.