diff --git a/packages/subgraph/.eslintignore b/packages/subgraph/.eslintignore deleted file mode 100644 index c45f7e7..0000000 --- a/packages/subgraph/.eslintignore +++ /dev/null @@ -1,12 +0,0 @@ -# directories -imported -generated -tests - -# files -*.env -*.log -.DS_Store -.pnp.* -extended-schema.ts - diff --git a/packages/subgraph/.eslintrc.yml b/packages/subgraph/.eslintrc.yml deleted file mode 100644 index 37f4cb6..0000000 --- a/packages/subgraph/.eslintrc.yml +++ /dev/null @@ -1,22 +0,0 @@ -extends: - - 'eslint:recommended' - - 'plugin:@typescript-eslint/eslint-recommended' - - 'plugin:@typescript-eslint/recommended' - - 'prettier' -parser: '@typescript-eslint/parser' -parserOptions: - project: 'tsconfig.json' -plugins: - - '@typescript-eslint' -root: true -rules: - '@typescript-eslint/no-floating-promises': - - error - - ignoreIIFE: true - ignoreVoid: true - '@typescript-eslint/no-inferrable-types': 'off' - '@typescript-eslint/no-explicit-any': 'off' - '@typescript-eslint/no-unused-vars': - - error - - argsIgnorePattern: '_' - varsIgnorePattern: '_' diff --git a/packages/subgraph/abis/ERC165.json b/packages/subgraph/abis/ERC165.json deleted file mode 100644 index 1304472..0000000 --- a/packages/subgraph/abis/ERC165.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "_format": "hh-sol-artifact-1", - "contractName": "ERC165", - "sourceName": "@openzeppelin/contracts/utils/introspection/ERC165.sol", - "abi": [ - { - "inputs": [ - { - "internalType": "bytes4", - "name": "interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - } - ], - "bytecode": "0x", - "deployedBytecode": "0x", - "linkReferences": {}, - "deployedLinkReferences": {} -} diff --git a/packages/subgraph/commons/erc165.ts b/packages/subgraph/commons/erc165.ts deleted file mode 100644 index 592249a..0000000 --- a/packages/subgraph/commons/erc165.ts +++ /dev/null @@ -1,23 +0,0 @@ -import {ethereum, Bytes} from '@graphprotocol/graph-ts'; - -export function supportsInterface( - contract: ethereum.SmartContract, - interfaceId: string, - // eslint-disable-next-line @typescript-eslint/no-inferrable-types - expected: boolean = true -): boolean { - const result = ethereum.call( - new ethereum.SmartContractCall( - contract._name, // '', - contract._address, // address, - 'supportsInterface', // '', - 'supportsInterface(bytes4):(bool)', - [ethereum.Value.fromFixedBytes(Bytes.fromHexString(interfaceId) as Bytes)] - ) - ); - - return ( - result != null && - (result as Array)[0].toBoolean() == expected - ); -} diff --git a/packages/subgraph/commons/ids.ts b/packages/subgraph/commons/ids.ts deleted file mode 100644 index 36608b6..0000000 --- a/packages/subgraph/commons/ids.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { - Address, - Bytes, - ethereum, - crypto, - ByteArray, - log, -} from '@graphprotocol/graph-ts'; - -export function getDaoId(dao: Address): string { - return dao.toHexString(); -} - -export function getPluginPreparationId( - dao: Address, - plugin: Address, - setupId: Bytes -): string | null { - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - log.critical('Failed to get installationId for dao {}, plugin {}', [ - dao.toHexString(), - plugin.toHexString(), - ]); - - return null; - } - - const preparationId = installationId - .toHexString() - .concat('_') - .concat(setupId.toHexString()); - - return preparationId; -} - -export function getPluginInstallationId( - dao: Address, - plugin: Address -): Bytes | null { - const installationIdTupleArray = new ethereum.Tuple(); - installationIdTupleArray.push(ethereum.Value.fromAddress(dao)); - installationIdTupleArray.push(ethereum.Value.fromAddress(plugin)); - - const installationIdTuple = installationIdTupleArray as ethereum.Tuple; - const installationIdTupleEncoded = ethereum.encode( - ethereum.Value.fromTuple(installationIdTuple) - ); - - if (installationIdTupleEncoded) { - return Bytes.fromHexString( - crypto - .keccak256( - ByteArray.fromHexString(installationIdTupleEncoded.toHexString()) - ) - .toHexString() - ); - } - return null; -} - -export function getPluginVersionId( - pluginRepo: string, - release: i32, - build: i32 -): string { - return pluginRepo - .concat('_') - .concat(release.toString()) - .concat('_') - .concat(build.toString()); -} diff --git a/packages/subgraph/manifest/data/goerli.json b/packages/subgraph/manifest/data/goerli.json deleted file mode 100644 index 5f82e60..0000000 --- a/packages/subgraph/manifest/data/goerli.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", - "network": "goerli", - "dataSources": { - "PluginSetupProcessors": [ - { - "name": "PluginSetupProcessor", - "address": "0xE8B5d8D66a02CD1b9Bd32a4064D7ABa45F51305e", - "startBlock": 8548226 - } - ] - } -} diff --git a/packages/subgraph/manifest/data/localhost.json b/packages/subgraph/manifest/data/localhost.json deleted file mode 100644 index fc78a36..0000000 --- a/packages/subgraph/manifest/data/localhost.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", - "network": "rinkeby", - "dataSources": { - "PluginSetupProcessors": [ - { - "name": "PluginSetupProcessor", - "address": "0x2B8C4DD137104d1E869105cd0106e7D9EF955BfE", - "startBlock": 7727664 - } - ] - } -} diff --git a/packages/subgraph/manifest/data/mainnet.json b/packages/subgraph/manifest/data/mainnet.json deleted file mode 100644 index b7969f8..0000000 --- a/packages/subgraph/manifest/data/mainnet.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", - "network": "mainnet", - "dataSources": { - "PluginSetupProcessors": [ - { - "name": "PluginSetupProcessor", - "address": "0xE978942c691e43f65c1B7c7F8f1dc8cDF061B13f", - "startBlock": 16721812 - } - ] - } -} diff --git a/packages/subgraph/manifest/data/mumbai.json b/packages/subgraph/manifest/data/mumbai.json deleted file mode 100644 index 9b1a784..0000000 --- a/packages/subgraph/manifest/data/mumbai.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", - "network": "mumbai", - "dataSources": { - "PluginSetupProcessors": [ - { - "name": "PluginSetupProcessor", - "address": "0x9227b311C5cecB416707F1C8B7Ca1b52649AabEc", - "startBlock": 33514164 - } - ] - } -} diff --git a/packages/subgraph/manifest/data/polygon.json b/packages/subgraph/manifest/data/polygon.json deleted file mode 100644 index 7675c9b..0000000 --- a/packages/subgraph/manifest/data/polygon.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", - "network": "matic", - "dataSources": { - "PluginSetupProcessors": [ - { - "name": "PluginSetupProcessor", - "address": "0x879D9dfe3F36d7684BeC1a2bB4Aa8E8871A7245B", - "startBlock": 40817440 - } - ] - } -} diff --git a/packages/subgraph/manifest/subgraph.placeholder.yaml b/packages/subgraph/manifest/subgraph.placeholder.yaml deleted file mode 100644 index f78df82..0000000 --- a/packages/subgraph/manifest/subgraph.placeholder.yaml +++ /dev/null @@ -1,66 +0,0 @@ -{{info}} -specVersion: 0.0.2 -description: A template for Plugin subgraphs -repository: https://github.com/aragon/osx-plugin-subgraph -schema: - file: ./schema.graphql -dataSources: - {{#dataSources.PluginSetupProcessors}} - # PluginSetupProcessor - - kind: ethereum/contract - name: {{name}} - network: {{network}} - source: - abi: PluginSetupProcessor - address: '{{address}}' - startBlock: {{startBlock}} - mapping: - kind: ethereum/events - apiVersion: 0.0.5 - language: wasm/assemblyscript - entities: - - PluginInstallation - - PluginPreparation - - PluginPermission - abis: - - name: PluginSetupProcessor - file: ./imported/PluginSetupProcessor.json - - name: ERC165 - file: ./abis/ERC165.json - eventHandlers: - - event: InstallationPrepared(indexed address,indexed address,bytes32,indexed address,(uint8,uint16),bytes,address,(address[],(uint8,address,address,address,bytes32)[])) - handler: handleInstallationPrepared - - event: InstallationApplied(indexed address,indexed address,bytes32,bytes32) - handler: handleInstallationApplied - - event: UpdatePrepared(indexed address,indexed address,bytes32,indexed address,(uint8,uint16),(address,address[],bytes),(address[],(uint8,address,address,address,bytes32)[]),bytes) - handler: handleUpdatePrepared - - event: UpdateApplied(indexed address,indexed address,bytes32,bytes32) - handler: handleUpdateApplied - - event: UninstallationPrepared(indexed address,indexed address,bytes32,indexed address,(uint8,uint16),(address,address[],bytes),(uint8,address,address,address,bytes32)[]) - handler: handleUninstallationPrepared - - event: UninstallationApplied(indexed address,indexed address,bytes32) - handler: handleUninstallationApplied - file: ./src/osx/pluginSetupProcessor.ts - {{/dataSources.PluginSetupProcessors}} -# templates -templates: - # Plugin (package) - - name: Plugin - kind: ethereum/contract - network: {{network}} - source: - abi: Plugin - mapping: - kind: ethereum/events - apiVersion: 0.0.5 - language: wasm/assemblyscript - entities: - - Dao - abis: - - name: Plugin - file: $PLUGIN_MODULE/artifacts/src/MyPlugin.sol/MyPlugin.json - eventHandlers: - - event: NumberStored(uint256) - handler: handleNumberStored - file: ./src/plugin/plugin.ts - diff --git a/packages/subgraph/package.json b/packages/subgraph/package.json deleted file mode 100644 index e1f0823..0000000 --- a/packages/subgraph/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@aragon/osx-plugin-subgraph", - "version": "1.0.0", - "license": "AGPL-3.0-or-later", - "scripts": { - "lint": "eslint . --ext .ts", - "build:contracts": "cd ../contracts && yarn build", - "build:manifest": "scripts/build-manifest.sh", - "build:subgraph": "scripts/build-subgraph.sh", - "build": "yarn build:contracts && yarn build:manifest && yarn build:subgraph", - "deploy": "scripts/deploy-subgraph.sh", - "create:local": "graph create aragon/aragon-core-rinkeby --node http://localhost:8020", - "deploy:local": "LOCAL=true scripts/deploy-subgraph.sh", - "start:dev": "docker-compose -f docker/docker-compose.yml up -d && sleep 15 && yarn create:local && yarn deploy:local", - "stop:dev": "docker-compose -f docker/docker-compose.yml down", - "test:fast": "graph test", - "test": "graph test -r", - "coverage": "graph test -c", - "postinstall": "ts-node scripts/postInstall.ts", - "clean": "rimraf deploy-output.txt subgraph.yaml ./build ./imported ./generated ./tests/.bin tests/.latest.json && yarn postinstall" - }, - "devDependencies": { - "osx-ethersV120": "npm:@aragon/osx-ethers@1.2.1", - "@graphprotocol/graph-cli": "^0.51.0", - "@graphprotocol/graph-ts": "^0.31.0", - "matchstick-as": "^0.5.2", - "mustache": "^4.2.0", - "ts-morph": "^17.0.1", - "ts-node": "^10.9.1", - "typescript": "^4.9.5" - } -} diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql deleted file mode 100644 index b19f567..0000000 --- a/packages/subgraph/schema.graphql +++ /dev/null @@ -1,108 +0,0 @@ -# Types - -# Executions - -type Action @entity { - id: ID! - to: Bytes! - value: BigInt! - data: Bytes! - dao: Dao! - proposal: IProposal! - execResult: Bytes -} - -# Dao - -type Dao @entity { - id: ID! # use address as id - actions: [Action!]! @derivedFrom(field: "dao") - proposals: [IProposal!]! @derivedFrom(field: "dao") - plugins: [Plugin!]! @derivedFrom(field: "dao") -} - -# Plugins - -type PluginPreparation @entity(immutable: true) { - # OSX related data - id: ID! # psp setupId + installationId - - # Set plugin specific related data below: -} - -interface PluginInstallation @entity { - # OSX related data - id: ID! # psp installationId - dao: Dao! - - # Set plugin specific related data below: -} - -# Plugin - -type Plugin implements PluginInstallation @entity { - "OSX related data" - id: ID! # psp installationId - dao: Dao! - - "Set plugin specific related data below:" - number: BigInt! - proposals: [PluginProposal!]! @derivedFrom(field: "plugin") - members: [PluginMember!]! @derivedFrom(field: "plugin") -} - -type PluginMember @entity { - id: ID! # plugin_address + member_address - address: String # address as string to facilitate filtering by address on the UI - proposals: [PluginProposalMember!]! @derivedFrom(field: "approver") - plugin: Plugin! -} - -type PluginProposalMember @entity(immutable: true) { - "MemberProposal for Many-to-Many" - id: ID! # approver + proposal - approver: PluginMember! - proposal: PluginProposal! - createdAt: BigInt! -} - -# Proposal -interface IProposal { - id: ID! # package + proposalId - dao: Dao! - creator: Bytes! - metadata: String - actions: [Action!]! @derivedFrom(field: "proposal") - allowFailureMap: BigInt! - failureMap: BigInt - executed: Boolean! - createdAt: BigInt! - startDate: BigInt! - endDate: BigInt! - executionTxHash: Bytes -} - -type PluginProposal implements IProposal @entity { - id: ID! # plugin + proposalId - dao: Dao! - actions: [Action!]! @derivedFrom(field: "proposal") - allowFailureMap: BigInt! - failureMap: BigInt - plugin: Plugin! - pluginProposalId: BigInt! - creator: Bytes! - metadata: String - createdAt: BigInt! - startDate: BigInt! - endDate: BigInt! - creationBlockNumber: BigInt! - snapshotBlock: BigInt! - minApprovals: Int! - approvals: Int - potentiallyExecutable: Boolean! - executed: Boolean! - executionDate: BigInt - executionBlockNumber: BigInt - executionTxHash: Bytes - approvers: [PluginProposalMember!]! @derivedFrom(field: "proposal") -} diff --git a/packages/subgraph/scripts/build-manifest.sh b/packages/subgraph/scripts/build-manifest.sh deleted file mode 100755 index 473223d..0000000 --- a/packages/subgraph/scripts/build-manifest.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - - -if [ -f ../../.env ] -then - export $(cat ../../.env | sed 's/#.*//g' | xargs) -fi - - -if [ -z "$SUBGRAPH_NETWORK_NAME" ] -then - echo "env is not set, exiting..." - exit -1 -else - echo "env Network is set to: $SUBGRAPH_NETWORK_NAME" -fi - -FILE=$SUBGRAPH_NETWORK_NAME'.json' -DATA=manifest/data/$FILE - -PLUGIN_MODULE=$(node -e 'console.log(require("path").dirname(require.resolve("@aragon/todo-osx-plugin-contracts/package.json")))') - -echo 'Generating manifest from data file: '$DATA -cat $DATA - -mustache \ - $DATA \ - manifest/subgraph.placeholder.yaml \ - | sed -e "s#\$PLUGIN_MODULE#$PLUGIN_MODULE#g" \ - > subgraph.yaml diff --git a/packages/subgraph/scripts/build-subgraph.sh b/packages/subgraph/scripts/build-subgraph.sh deleted file mode 100755 index 3f67c21..0000000 --- a/packages/subgraph/scripts/build-subgraph.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -eu - -if [ ! -f "./subgraph.yaml" ]; then - echo "The file subgraph.yaml doesn’t exist. Did you run: yarn manifest?" - exit 1 -fi - -rm -rf generated -rm -rf build - -graph codegen -graph build diff --git a/packages/subgraph/scripts/deploy-subgraph.sh b/packages/subgraph/scripts/deploy-subgraph.sh deleted file mode 100755 index 0c99609..0000000 --- a/packages/subgraph/scripts/deploy-subgraph.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -if [ -f .env ] -then - export $(cat .env | sed 's/#.*//g' | xargs) -fi - -if [ -z "$NETWORK_NAME" ] || [ -z "$SUBGRAPH_NAME" ] || [ -z "$GRAPH_KEY" ] || [ -z "$SUBGRAPH_VERSION" ] -then - echo "env variables are not set properly, exiting..." - exit -1 -fi - -# Exit script as soon as a command fails. -set -o errexit - -# Build manifest -echo '' -echo '> Building manifest file subgraph.yaml' -./scripts/build-manifest.sh - -# Build subgraph -echo '' -echo '> Building subgraph' -./scripts/build-subgraph.sh - -if [ "$NETWORK_NAME" == 'localhost' ] -then - NETWORK_NAME='goerli' -fi - -# Prepare subgraph name -FULLNAME=$SUBGRAPH_NAME-$NETWORK_NAME -if [ "$STAGING" ]; then - FULLNAME=$FULLNAME-staging -fi -echo '' -echo '> Deploying subgraph: '$FULLNAME -echo '> Subgraph version: '$SUBGRAPH_VERSION - -# Deploy subgraph -if [ "$LOCAL" ] -then - graph deploy $FULLNAME \ - --ipfs http://localhost:5001 \ - --node http://localhost:8020 -else - graph deploy $FULLNAME \ - --version-label $SUBGRAPH_VERSION \ - --node https://app.satsuma.xyz/api/subgraphs/deploy \ - --deploy-key $GRAPH_KEY > deploy-output.txt - - SUBGRAPH_ID=$(grep "Build completed:" deploy-output.txt | grep -oE "Qm[a-zA-Z0-9]{44}") - rm deploy-output.txt - echo "The Graph deployment complete: ${SUBGRAPH_ID}" - -fi \ No newline at end of file diff --git a/packages/subgraph/scripts/postInstall.ts b/packages/subgraph/scripts/postInstall.ts deleted file mode 100644 index 1c17ca9..0000000 --- a/packages/subgraph/scripts/postInstall.ts +++ /dev/null @@ -1,39 +0,0 @@ -import fs from 'fs'; -// Import the osx-ethers module to access OSX contracts and generate their ABIs for any needed version. -import * as osx120 from 'osx-ethersV120'; -import path from 'path'; - -// Add the contract factories to this array for the contracts you want to generate ABIs for. -const contractFactories = [osx120.PluginSetupProcessor__factory]; - -function generateABIFiles(contractFactories: any[]): void { - // Iterate through each contract factory passed. - contractFactories.forEach(contractFactory => { - // Extract the ABI object and name from the contract factory - const abiObject: any = contractFactory.abi; - const abiName: string = contractFactory.name.replace('__factory', ''); - - // Construct the file name for the ABI JSON file - const fileName = `${abiName}.json`; - - // Construct the ABI directory path relative to the project root - const abisDirectory = path.join(__dirname, '../imported'); - - // If the directory does not exist, create it - if (!fs.existsSync(abisDirectory)) { - fs.mkdirSync(abisDirectory, {recursive: true}); - } - - // Resolve the full file path - const filePath = path.resolve(abisDirectory, fileName); - - // Write the ABI object to a JSON file - fs.writeFileSync(filePath, JSON.stringify(abiObject)); - - // Log a message indicating that the ABI file has been generated - console.log(`ABI file generated for '${abiName}', file: ${filePath}`); - }); -} - -// Generate ABI files for the provided parameters in the specified directory -generateABIFiles(contractFactories); diff --git a/packages/subgraph/src/osx/pluginSetupProcessor.ts b/packages/subgraph/src/osx/pluginSetupProcessor.ts deleted file mode 100644 index 6edd4ee..0000000 --- a/packages/subgraph/src/osx/pluginSetupProcessor.ts +++ /dev/null @@ -1,248 +0,0 @@ -import { - getDaoId, - getPluginInstallationId, - getPluginPreparationId, -} from '../../commons/ids'; -import { - InstallationApplied, - InstallationPrepared, - UninstallationApplied, - UninstallationPrepared, - UpdateApplied, - UpdatePrepared, -} from '../../generated/PluginSetupProcessor/PluginSetupProcessor'; -import {Dao, Plugin, PluginPreparation} from '../../generated/schema'; -import {Plugin as PluginTemplate} from '../../generated/templates'; -import {PLUGIN_REPO_ADDRESS} from '../../utils/constants'; -import { - updatePluginDataForInstallationApplied, - updatePluginDataForInstallationPrepared, - updatePluginDataForUninstallationApplied, - updatePluginDataForUninstallationPrepared, - updatePluginDataForUpdateApplied, - updatePluginDataForUpdatePrepared, - updatePreparationDataForInstallationPrepared, - updatePreparationDataForUninstallationPrepared, - updatePreparationDataForUpdatePrepared, -} from '../plugin/pluginSetupProcessor'; -import {DataSourceContext, log} from '@graphprotocol/graph-ts'; - -export function handleInstallationPrepared(event: InstallationPrepared): void { - const pluginRepo = event.params.pluginSetupRepo.toHexString(); - - // Check if the prepared plugin is our plugin. - const isThisPlugin = pluginRepo === PLUGIN_REPO_ADDRESS; - - if (!isThisPlugin) { - return; - } - - ////////////////////////////////////////////////////////////// - // Index DAO - ////////////////////////////////////////////////////////////// - const dao = event.params.dao; - const daoId = getDaoId(dao); - let doaEntity = Dao.load(daoId); - if (!doaEntity) { - doaEntity = new Dao(daoId); - doaEntity.save(); - } - - const plugin = event.params.plugin; - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - log.error('Failed to get installationId', [daoId, plugin.toHexString()]); - return; - } - - ////////////////////////////////////////////////////////////// - // Index preparation - ////////////////////////////////////////////////////////////// - const setupId = event.params.preparedSetupId; - const preparationId = getPluginPreparationId(dao, plugin, setupId); - if (preparationId) { - const preparationEntity = new PluginPreparation(preparationId); - - // Add preparation specific data - updatePreparationDataForInstallationPrepared(preparationEntity, event); - - preparationEntity.save(); - - ////////////////////////////////////////////////////////////// - // Index plugin - ////////////////////////////////////////////////////////////// - let pluginEntity = Plugin.load(installationId.toHexString()); - if (!pluginEntity) { - pluginEntity = new Plugin(installationId.toHexString()); - } - pluginEntity.dao = daoId; - - // Add plugin preparation specific data - updatePluginDataForInstallationPrepared(pluginEntity, event); - - // Create template - const context = new DataSourceContext(); - context.setString('daoAddress', daoId); - PluginTemplate.createWithContext(plugin, context); - - pluginEntity.save(); - } else { - log.error('Failed to get preparationId for dao {}, plugin {}, setupId {}', [ - daoId, - plugin.toHexString(), - setupId.toHexString(), - ]); - return; - } -} - -export function handleInstallationApplied(event: InstallationApplied): void { - const dao = event.params.dao; - const plugin = event.params.plugin; - - // Check if the applied is our plugin. - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - return; - } - - let pluginEntity = Plugin.load(installationId.toHexString()); - if (!pluginEntity) { - pluginEntity = new Plugin(installationId.toHexString()); - pluginEntity.dao = getDaoId(dao); - } - - // Add plugin applied specific data - updatePluginDataForInstallationApplied(pluginEntity, event); - - pluginEntity.save(); -} - -export function handleUpdatePrepared(event: UpdatePrepared): void { - const dao = event.params.dao; - const plugin = event.params.setupPayload.plugin; - - // Check if the update preparation plugin is our plugin. - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - return; - } - - const setupId = event.params.preparedSetupId; - const preparationId = getPluginPreparationId(dao, plugin, setupId); - if (preparationId) { - const preparationEntity = new PluginPreparation(preparationId); - - // Add preparation specific data - updatePreparationDataForUpdatePrepared(preparationEntity, event); - - preparationEntity.save(); - - let pluginEntity = Plugin.load(installationId.toHexString()); - if (!pluginEntity) { - pluginEntity = new Plugin(installationId.toHexString()); - pluginEntity.dao = getDaoId(dao); - } - - // Add plugin preparation specific data - updatePluginDataForUpdatePrepared(pluginEntity, event); - - pluginEntity.save(); - } else { - log.error('Failed to get preparationId for dao {}, plugin {}, setupId {}', [ - dao.toHexString(), - plugin.toHexString(), - setupId.toHexString(), - ]); - return; - } -} - -export function handleUpdateApplied(event: UpdateApplied): void { - const dao = event.params.dao; - const plugin = event.params.plugin; - - // Check if the applied update for the plugin is our plugin. - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - return; - } - - let pluginEntity = Plugin.load(installationId.toHexString()); - if (!pluginEntity) { - pluginEntity = new Plugin(installationId.toHexString()); - pluginEntity.dao = getDaoId(dao); - } - - // Add plugin applied specific data - updatePluginDataForUpdateApplied(pluginEntity, event); - - pluginEntity.save(); -} - -export function handleUninstallationPrepared( - event: UninstallationPrepared -): void { - const dao = event.params.dao; - const plugin = event.params.setupPayload.plugin; - - // Check if the prepared uninstallation is for our plugin. - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - return; - } - - const setupId = event.params.preparedSetupId; - - const preparationId = getPluginPreparationId(dao, plugin, setupId); - if (preparationId) { - const preparationEntity = new PluginPreparation(preparationId); - - // Add preparation specific data - updatePreparationDataForUninstallationPrepared(preparationEntity, event); - - preparationEntity.save(); - - let pluginEntity = Plugin.load(installationId.toHexString()); - if (!pluginEntity) { - pluginEntity = new Plugin(installationId.toHexString()); - pluginEntity.dao = getDaoId(dao); - } - - // Add plugin preparation specific data - updatePluginDataForUninstallationPrepared(pluginEntity, event); - - pluginEntity.save(); - } else { - log.error('Failed to get preparationId for dao {}, plugin {}, setupId {}', [ - dao.toHexString(), - plugin.toHexString(), - setupId.toHexString(), - ]); - return; - } -} - -export function handleUninstallationApplied( - event: UninstallationApplied -): void { - const dao = event.params.dao; - const plugin = event.params.plugin; - - // Check if the applied uninstallation is for our plugin. - const installationId = getPluginInstallationId(dao, plugin); - if (!installationId) { - return; - } - - let pluginEntity = Plugin.load(installationId.toHexString()); - if (!pluginEntity) { - pluginEntity = new Plugin(installationId.toHexString()); - pluginEntity.dao = getDaoId(dao); - } - - // Add plugin applied specific data - updatePluginDataForUninstallationApplied(pluginEntity, event); - - pluginEntity.save(); -} diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts deleted file mode 100644 index 6611334..0000000 --- a/packages/subgraph/src/plugin/plugin.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {getPluginInstallationId} from '../../commons/ids'; -import {Plugin} from '../../generated/schema'; -import {NumberStored} from '../../generated/templates/Plugin/Plugin'; -import {Address, dataSource} from '@graphprotocol/graph-ts'; - -export function handleNumberStored(event: NumberStored): void { - const pluginAddress = event.address; - - const context = dataSource.context(); - const daoId = context.getString('daoAddress'); - - const installationId = getPluginInstallationId( - Address.fromString(daoId), - pluginAddress - ); - - if (installationId) { - const pluginEntity = Plugin.load(installationId.toHexString()); - if (pluginEntity) { - pluginEntity.number = event.params.number; - pluginEntity.save(); - } - } -} diff --git a/packages/subgraph/src/plugin/pluginSetupProcessor.ts b/packages/subgraph/src/plugin/pluginSetupProcessor.ts deleted file mode 100644 index e1a3a68..0000000 --- a/packages/subgraph/src/plugin/pluginSetupProcessor.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { - InstallationApplied, - InstallationPrepared, - UninstallationApplied, - UninstallationPrepared, - UpdateApplied, - UpdatePrepared, -} from '../../generated/PluginSetupProcessor/PluginSetupProcessor'; -import {Plugin, PluginPreparation} from '../../generated/schema'; - -///////////////// -// InstallationPrepared -///////////////// -export function updatePreparationDataForInstallationPrepared( - pluginPreparationEntity: PluginPreparation, - event: InstallationPrepared -): void { - // Add `PluginPreparation` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginPreparationEntity; - event; -} - -export function updatePluginDataForInstallationPrepared( - pluginEntity: Plugin, - event: InstallationPrepared -): void { - // Add `Plugin` specific data for this plugin - // pluginEntity.onlyListed = false; - // pluginEntity.proposalCount = BigInt.zero(); - - // Remove: the following code is used to silence the linter - pluginEntity; - event; -} - -///////////////// -// InstallationApplied -///////////////// -export function updatePluginDataForInstallationApplied( - pluginEntity: Plugin, - event: InstallationApplied -): void { - // Add `Plugin` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginEntity; - event; -} - -///////////////// -// UpdatePrepared -///////////////// -export function updatePreparationDataForUpdatePrepared( - pluginPreparationEntity: PluginPreparation, - event: UpdatePrepared -): void { - // Add `PluginPreparation` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginPreparationEntity; - event; -} - -export function updatePluginDataForUpdatePrepared( - pluginEntity: Plugin, - event: UpdatePrepared -): void { - // Add `Plugin` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginEntity; - event; -} - -///////////////// -// UpdateApplied -///////////////// -export function updatePluginDataForUpdateApplied( - pluginEntity: Plugin, - event: UpdateApplied -): void { - // Add `Plugin` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginEntity; - event; -} - -///////////////// -// UninstallationPrepared -///////////////// -export function updatePreparationDataForUninstallationPrepared( - pluginPreparationEntity: PluginPreparation, - event: UninstallationPrepared -): void { - // Add `PluginPreparation` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginPreparationEntity; - event; -} - -export function updatePluginDataForUninstallationPrepared( - pluginEntity: Plugin, - event: UninstallationPrepared -): void { - // Add `Plugin` specific data for this plugin - // pluginEntity.onlyListed = false; - // pluginEntity.proposalCount = BigInt.zero(); - - // Remove: the following code is used to silence the linter - pluginEntity; - event; -} - -///////////////// -// InstallationApplied -///////////////// -export function updatePluginDataForUninstallationApplied( - pluginEntity: Plugin, - event: UninstallationApplied -): void { - // Add `Plugin` specific data for this plugin - - // Remove: the following code is used to silence the linter - pluginEntity; - event; -} diff --git a/packages/subgraph/tests/plugin.test.ts b/packages/subgraph/tests/plugin.test.ts deleted file mode 100644 index e69de29..0000000 diff --git a/packages/subgraph/tsconfig.json b/packages/subgraph/tsconfig.json deleted file mode 100644 index 20dcb72..0000000 --- a/packages/subgraph/tsconfig.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "compilerOptions": { - "declaration": true, - "declarationMap": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "forceConsistentCasingInFileNames": true, - "lib": ["es6"], - "module": "commonjs", - "moduleResolution": "node", - "noImplicitAny": true, - "removeComments": true, - "resolveJsonModule": true, - "sourceMap": true, - "strict": true, - "target": "es6" - }, - "exclude": ["node_modules"], - "files": ["./hardhat.config.ts"], - "include": [ - "manifest/**/*", - "src/**/*", - "scripts/**/*", - "tests/**/*", - "utils/**/*", - "plugin-settings.ts", - "commons/**/*" - ] -} diff --git a/packages/subgraph/utils/constants.ts b/packages/subgraph/utils/constants.ts deleted file mode 100644 index aad52aa..0000000 --- a/packages/subgraph/utils/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'; - -export const PLUGIN_INTERFACE = '0x11223344'; -export const PLUGIN_REPO_ADDRESS = '0xEF30A43458d846bb754DBEE17958Dbc7a7b98618'; diff --git a/packages/subgraph/utils/schema-extender.ts b/packages/subgraph/utils/schema-extender.ts deleted file mode 100644 index 9bfea40..0000000 --- a/packages/subgraph/utils/schema-extender.ts +++ /dev/null @@ -1,169 +0,0 @@ -import {CodeBlockWriter, Project} from 'ts-morph'; - -function main() { - const project = new Project(); - const sourceFile = project.addSourceFileAtPath('./generated/schema.ts'); - const sourceMethodFile = project.addSourceFileAtPath( - './tests/helpers/method-classes.ts' - ); - - const outputFile = project.createSourceFile( - './tests/helpers/extended-schema.ts', - '', - { - overwrite: true, - } - ); - - // Get original Entity classes - const sourceClasses = sourceFile.getClasses(); - - // Get additional method classes - const sourceMethodClasses = sourceMethodFile.getClasses(); - - // Add all imports from sourcemethod-classes - const methodsImportDeclarations = sourceMethodFile.getImportDeclarations(); - methodsImportDeclarations.forEach(importDeclaration => { - if ( - importDeclaration.getModuleSpecifierValue() !== '../../generated/schema' - ) { - outputFile.addImportDeclaration(importDeclaration.getStructure()); - } - }); - - // Import assert into generated file - outputFile.addImportDeclaration({ - namedImports: ['assert', 'log'], - moduleSpecifier: `matchstick-as`, - }); - - // Add import statements for the original classes - const sourceFileNameWithoutExtension = - sourceFile.getBaseNameWithoutExtension(); - outputFile.addImportDeclaration({ - namedImports: sourceClasses.map( - classDeclaration => classDeclaration.getName() as string - ), - moduleSpecifier: `../../generated/${sourceFileNameWithoutExtension}`, - }); - - // Iterate through the classes in the source file - sourceClasses.forEach(classDeclaration => { - // Create a new class based on the original one - const originalClassName = classDeclaration.getName() as string; - const newClassName = `Extended${originalClassName}`; - const newClass = outputFile.addClass({ - name: newClassName, - isExported: true, - extends: originalClassName, - }); - - // Create a new constructor that calls super() with a default id. - newClass.addConstructor({ - parameters: [], - statements: (writer: CodeBlockWriter) => { - const defaultEntityId = '0x1'; - writer.writeLine(`super('${defaultEntityId}');`); - }, - }); - - // add methods to generated classes - sourceMethodClasses.forEach(classDeclaration => { - if (classDeclaration.getName() === `${originalClassName}Methods`) { - const methods = classDeclaration.getMethods(); - - methods.forEach(method => { - let returnType = method.getReturnTypeNode()?.getText() || ''; - if (returnType === `${originalClassName}Methods`) { - returnType = `Extended${originalClassName}`; - } - - const newMethod = newClass.addMethod({ - name: method.getName(), - returnType: returnType, - }); - - const parameters = method.getParameters().map(parameter => { - return { - name: parameter.getName(), - type: parameter.getTypeNode()?.getText() || '', - hasQuestionToken: parameter.hasQuestionToken(), - initializer: parameter.getInitializer()?.getText(), - decorators: parameter - .getDecorators() - .map(decorator => decorator.getStructure()), - }; - }); - - newMethod.addParameters(parameters); - - const statements = method - .getStatements() - .map(statement => statement.getText()); - newMethod.addStatements(statements); - }); - } - }); - - newClass.addMethod({ - name: 'buildOrUpdate', - returnType: 'void', - statements: (writer: CodeBlockWriter) => { - writer.writeLine('this.save();'); - }, - }); - - newClass.addMethod({ - name: 'assertEntity', - returnType: 'void', - parameters: [ - { - name: 'debug', - type: 'boolean', - initializer: 'false', - }, - ], - statements: (writer: CodeBlockWriter) => { - writer.writeLine(`let entity = ${originalClassName}.load(this.id);`); - writer.writeLine(`if (!entity) throw new Error("Entity not found");`); - writer.writeLine(`let entries = entity.entries;`); - writer.write('for (let i = 0; i < entries.length; i++)').block(() => { - writer.writeLine(`let key = entries[i].key;`); - - writer.write('if (debug)').block(() => { - writer.writeLine(`log.debug('asserting for key: {}', [key]);`); - }); - - writer.writeLine(`let value = this.get(key);`); - - writer - .write('if (!value)') - .block(() => { - writer.write('if (debug)').block(() => { - writer.writeLine( - `log.debug('value is null for key: {}', [key]);` - ); - }); - }) - .write('else') - .block(() => { - writer.write('if (debug)').block(() => { - writer.writeLine( - `log.debug('asserting with value: {}', [value.displayData()]);` - ); - }); - - writer.writeLine( - `assert.fieldEquals("${originalClassName}", this.id, key, value.displayData());` - ); - }); - }); - }, - }); - }); - - // Save the changes - outputFile.saveSync(); -} - -main();