diff --git a/packages/subgraph/commons/ids.ts b/packages/subgraph/commons/ids.ts deleted file mode 100644 index d4234889..00000000 --- a/packages/subgraph/commons/ids.ts +++ /dev/null @@ -1,34 +0,0 @@ -// TODO: Remove this file and import from OSx-commons-subgraph, -// once the OSx-commons-subgraph npm package is published -import { - Address, - Bytes, - ethereum, - crypto, - ByteArray, -} from '@graphprotocol/graph-ts'; - -export function generatePluginInstallationEntityId( - 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; -} diff --git a/packages/subgraph/package.json b/packages/subgraph/package.json index 85e2936c..c82949ac 100644 --- a/packages/subgraph/package.json +++ b/packages/subgraph/package.json @@ -16,16 +16,20 @@ "clean": "rimraf deploy-output.txt subgraph.yaml ./build ./imported ./generated ./tests/.bin tests/.latest.json && yarn postinstall" }, "devDependencies": { + "@aragon/osx-ethers": "1.3.0", "@graphprotocol/graph-cli": "^0.51.0", "@graphprotocol/graph-ts": "^0.31.0", "cross-env": "^7.0.3", + "dotenv": "^16.3.1", "matchstick-as": "^0.5.2", "mustache": "^4.2.0", "@aragon/osx-ethers": "1.4.0-alpha.0", "@aragon/osx-commons-configs": "0.2.0", "ts-morph": "^17.0.1", "ts-node": "^10.9.1", - "typescript": "^5.2.2", - "dotenv": "^16.3.1" + "typescript": "^5.2.2" + }, + "dependencies": { + "@aragon/osx-commons-subgraph": "^0.0.4" } } diff --git a/packages/subgraph/src/osx/pluginSetupProcessor.ts b/packages/subgraph/src/osx/pluginSetupProcessor.ts index 5dd7281f..ac0aabdf 100644 --- a/packages/subgraph/src/osx/pluginSetupProcessor.ts +++ b/packages/subgraph/src/osx/pluginSetupProcessor.ts @@ -1,8 +1,8 @@ -import {generatePluginInstallationEntityId} from '../../commons/ids'; import {InstallationPrepared} from '../../generated/PluginSetupProcessor/PluginSetupProcessor'; import {DaoPlugin} from '../../generated/schema'; import {Plugin as PluginTemplate} from '../../generated/templates'; import {PLUGIN_REPO_ADDRESS} from '../../imported/repo-address'; +import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph'; import {Address, DataSourceContext, log} from '@graphprotocol/graph-ts'; export function handleInstallationPrepared(event: InstallationPrepared): void { @@ -29,11 +29,10 @@ export function handleInstallationPrepared(event: InstallationPrepared): void { ]); return; } - // Load or create a new entry for the this plugin using the generated installation ID. - let pluginEntity = DaoPlugin.load(installationId.toHexString()); + let pluginEntity = DaoPlugin.load(installationId!); if (!pluginEntity) { - pluginEntity = new DaoPlugin(installationId.toHexString()); + pluginEntity = new DaoPlugin(installationId!); } // Set the DAO and plugin address for the plugin entity. diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index 10cd9e37..aa004d71 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -1,6 +1,6 @@ -import {generatePluginInstallationEntityId} from '../../commons/ids'; import {DaoPlugin} from '../../generated/schema'; import {NumberStored} from '../../generated/templates/Plugin/Plugin'; +import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph'; import {Address, dataSource} from '@graphprotocol/graph-ts'; export function handleNumberStored(event: NumberStored): void { @@ -15,7 +15,7 @@ export function handleNumberStored(event: NumberStored): void { ); if (installationId) { - const pluginEntity = DaoPlugin.load(installationId.toHexString()); + const pluginEntity = DaoPlugin.load(installationId); if (pluginEntity) { pluginEntity.number = event.params.number; pluginEntity.save(); diff --git a/packages/subgraph/tests/osx/pluginSetupProcessor.test.ts b/packages/subgraph/tests/osx/pluginSetupProcessor.test.ts index 012173f1..920203aa 100644 --- a/packages/subgraph/tests/osx/pluginSetupProcessor.test.ts +++ b/packages/subgraph/tests/osx/pluginSetupProcessor.test.ts @@ -1,5 +1,3 @@ -import {generatePluginInstallationEntityId} from '../../commons/ids'; -import {createInstallationPreparedEvent} from '../../commons/test'; import {PLUGIN_REPO_ADDRESS} from '../../imported/repo-address'; import {handleInstallationPrepared} from '../../src/osx/pluginSetupProcessor'; import { @@ -13,6 +11,8 @@ import { DAO_ADDRESS, PLUGIN_SETUP_ID, } from '../utils/constants'; +import {createInstallationPreparedEvent} from '../utils/events'; +import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph'; import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts'; import {assert, afterEach, clearStore, test, describe} from 'matchstick-as'; @@ -60,8 +60,6 @@ describe('OSx', () => { ], ]; - let installationIdString = installationId.toHexString(); - const otherPluginSetupRepo = ADDRESS_TWO; const event1 = createInstallationPreparedEvent( @@ -78,7 +76,7 @@ describe('OSx', () => { handleInstallationPrepared(event1); - assert.notInStore('DaoPlugin', installationIdString); + assert.notInStore('DaoPlugin', installationId!); assert.entityCount('DaoPlugin', 0); const thisPluginRepoAddress = PLUGIN_REPO_ADDRESS; @@ -97,13 +95,8 @@ describe('OSx', () => { handleInstallationPrepared(event2); - assert.fieldEquals( - 'DaoPlugin', - installationIdString, - 'id', - installationIdString - ); assert.entityCount('DaoPlugin', 1); + assert.fieldEquals('DaoPlugin', installationId!, 'id', installationId!); }); }); }); diff --git a/packages/subgraph/tests/plugin/plugin.test.ts b/packages/subgraph/tests/plugin/plugin.test.ts index bb8b63d0..14db4cc4 100644 --- a/packages/subgraph/tests/plugin/plugin.test.ts +++ b/packages/subgraph/tests/plugin/plugin.test.ts @@ -1,8 +1,8 @@ -import {generatePluginInstallationEntityId} from '../../commons/ids'; import {DaoPlugin} from '../../generated/schema'; import {handleNumberStored} from '../../src/plugin/plugin'; import {CONTRACT_ADDRESS, DAO_ADDRESS} from '../utils/constants'; -import {createNewNumberStoredEvent} from './utils'; +import {createNewNumberStoredEvent} from '../utils/events'; +import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph'; import {Address, DataSourceContext} from '@graphprotocol/graph-ts'; import { assert, @@ -37,10 +37,8 @@ describe('Plugin', () => { if (!installationId) { throw new Error('Failed to get installationId'); } - const installationIdHex = installationId.toHexString(); - // Create state - let daoPlugin = new DaoPlugin(installationIdHex); + let daoPlugin = new DaoPlugin(installationId!); daoPlugin.dao = daoAddress; daoPlugin.pluginAddress = pluginAddress; daoPlugin.save(); @@ -54,13 +52,8 @@ describe('Plugin', () => { handleNumberStored(event); - assert.fieldEquals( - 'DaoPlugin', - installationIdHex, - 'id', - installationIdHex - ); - assert.fieldEquals('DaoPlugin', installationIdHex, 'number', number); + assert.fieldEquals('DaoPlugin', installationId!, 'id', installationId!); + assert.fieldEquals('DaoPlugin', installationId!, 'number', number); assert.entityCount('DaoPlugin', 1); }); }); diff --git a/packages/subgraph/tests/utils/events/index.ts b/packages/subgraph/tests/utils/events/index.ts new file mode 100644 index 00000000..ed8b40b6 --- /dev/null +++ b/packages/subgraph/tests/utils/events/index.ts @@ -0,0 +1,2 @@ +export * from './osx'; +export * from './plugin'; diff --git a/packages/subgraph/commons/test.ts b/packages/subgraph/tests/utils/events/osx.ts similarity index 93% rename from packages/subgraph/commons/test.ts rename to packages/subgraph/tests/utils/events/osx.ts index 2502b628..358f45bc 100644 --- a/packages/subgraph/commons/test.ts +++ b/packages/subgraph/tests/utils/events/osx.ts @@ -1,9 +1,7 @@ -// TODO: Remove this file and import from OSx-commons-subgraph, -// once the OSx-commons-subgraph npm package is published import { InstallationPrepared, InstallationPreparedPreparedSetupDataStruct, -} from '../generated/PluginSetupProcessor/PluginSetupProcessor'; +} from '../../../generated/PluginSetupProcessor/PluginSetupProcessor'; import {Address, Bytes, ethereum} from '@graphprotocol/graph-ts'; import {newMockEvent} from 'matchstick-as'; diff --git a/packages/subgraph/tests/plugin/utils.ts b/packages/subgraph/tests/utils/events/plugin.ts similarity index 89% rename from packages/subgraph/tests/plugin/utils.ts rename to packages/subgraph/tests/utils/events/plugin.ts index 7f08abd2..58df89f7 100644 --- a/packages/subgraph/tests/plugin/utils.ts +++ b/packages/subgraph/tests/utils/events/plugin.ts @@ -1,4 +1,4 @@ -import {NumberStored} from '../../generated/templates/Plugin/Plugin'; +import {NumberStored} from '../../../generated/templates/Plugin/Plugin'; import {Address, BigInt, ethereum} from '@graphprotocol/graph-ts'; import {newMockEvent} from 'matchstick-as'; diff --git a/packages/subgraph/yarn.lock b/packages/subgraph/yarn.lock index 2b2a9be4..e209c607 100644 --- a/packages/subgraph/yarn.lock +++ b/packages/subgraph/yarn.lock @@ -9,6 +9,13 @@ dependencies: tslib "^2.6.2" +"@aragon/osx-commons-subgraph@^0.0.4": + version "0.0.4" + resolved "https://registry.yarnpkg.com/@aragon/osx-commons-subgraph/-/osx-commons-subgraph-0.0.4.tgz#2aa52f3089d21189c9152d2f3d14c0d7c66d129f" + integrity sha512-cqhusJ3HNvMx+t9lXfN+Hy/5ipefNs1Tdxe+y0GvD4qgBMVU4tCbsxOpB9U2JEJNBCzFQj4E/872FFLpIErB4w== + dependencies: + "@graphprotocol/graph-ts" "0.31.0" + "@aragon/osx-ethers@1.4.0-alpha.0": version "1.4.0-alpha.0" resolved "https://registry.yarnpkg.com/@aragon/osx-ethers/-/osx-ethers-1.4.0-alpha.0.tgz#329f1ac27660b486fa0b296dddeb004ce352001c" @@ -444,7 +451,7 @@ which "2.0.2" yaml "1.10.2" -"@graphprotocol/graph-ts@^0.31.0": +"@graphprotocol/graph-ts@0.31.0", "@graphprotocol/graph-ts@^0.31.0": version "0.31.0" resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.31.0.tgz#730668c0369828b31bef81e8d9bc66b9b48e3480" integrity sha512-xreRVM6ho2BtolyOh2flDkNoGZximybnzUnF53zJVp0+Ed0KnAlO1/KOCUYw06euVI9tk0c9nA2Z/D5SIQV2Rg==