Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use commons subgraph #29

Merged
merged 6 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/contracts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.8.1.tgz#363f7dd08f25f8f77e16d374350c3d6b43340a7a"
integrity sha512-1wTv+20lNiC0R07jyIAbHU7TNHKRwGiTGRfiNnA8jOWjKT98g5OgLpYWOi40Vgpk8SPLA9EvfJAbAeIyVn+7Bw==

"@openzeppelin/contracts-upgradeable@^4.9.4":
"@openzeppelin/contracts-upgradeable@^4.9.5":
version "4.9.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.5.tgz#572b5da102fc9be1d73f34968e0ca56765969812"
integrity sha512-f7L1//4sLlflAN7fVzJLoRedrf5Na3Oal5PZfIq55NFcVZ90EpV1q5xOvL4lFvg3MNICSDr2hH0JUBxwlxcoPg==
Expand All @@ -956,7 +956,7 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.1.tgz#709cfc4bbb3ca9f4460d60101f15dac6b7a2d5e4"
integrity sha512-xQ6eUZl+RDyb/FiZe1h+U7qr/f4p/SrTSQcTPH2bjur3C5DbuW/zFgCU/b1P/xcIaEqJep+9ju4xDRi3rmChdQ==

"@openzeppelin/contracts@^4.1.0", "@openzeppelin/contracts@^4.9.4":
"@openzeppelin/contracts@^4.1.0", "@openzeppelin/contracts@^4.9.5":
version "4.9.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.5.tgz#1eed23d4844c861a1835b5d33507c1017fa98de8"
integrity sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==
Expand Down
34 changes: 0 additions & 34 deletions packages/subgraph/commons/ids.ts

This file was deleted.

9 changes: 6 additions & 3 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
"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.3.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"
}
}
10 changes: 5 additions & 5 deletions packages/subgraph/src/osx/pluginSetupProcessor.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -20,7 +20,7 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
const plugin = event.params.plugin;

// Generate a unique ID for the plugin installation.
const installationId = generatePluginInstallationEntityId(dao, plugin);
let installationId = generatePluginInstallationEntityId(dao, plugin);
// Log an error and exit if unable to generate the installation ID.
if (!installationId) {
log.error('Failed to generate installationId', [
Expand All @@ -29,11 +29,11 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
]);
return;
}

installationId = installationId as string;
// 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.
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
Expand Down
18 changes: 6 additions & 12 deletions packages/subgraph/tests/osx/pluginSetupProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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';

Expand All @@ -27,13 +27,14 @@ describe('OSx', () => {
// Create event
const daoAddress = DAO_ADDRESS;
const pluginAddress = CONTRACT_ADDRESS;
const installationId = generatePluginInstallationEntityId(
let installationId = generatePluginInstallationEntityId(
Address.fromString(daoAddress),
Address.fromString(pluginAddress)
);
if (!installationId) {
throw new Error('Failed to get installationId');
}
installationId = installationId as string;
const setupId = PLUGIN_SETUP_ID;
const versionTuple = new ethereum.Tuple();
versionTuple.push(
Expand All @@ -60,8 +61,6 @@ describe('OSx', () => {
],
];

let installationIdString = installationId.toHexString();

const otherPluginSetupRepo = ADDRESS_TWO;

const event1 = createInstallationPreparedEvent(
Expand All @@ -78,7 +77,7 @@ describe('OSx', () => {

handleInstallationPrepared(event1);

assert.notInStore('DaoPlugin', installationIdString);
assert.notInStore('DaoPlugin', installationId);
assert.entityCount('DaoPlugin', 0);

const thisPluginRepoAddress = PLUGIN_REPO_ADDRESS;
Expand All @@ -97,12 +96,7 @@ describe('OSx', () => {

handleInstallationPrepared(event2);

assert.fieldEquals(
'DaoPlugin',
installationIdString,
'id',
installationIdString
);
assert.fieldEquals('DaoPlugin', installationId, 'id', installationId);
assert.entityCount('DaoPlugin', 1);
});
});
Expand Down
20 changes: 7 additions & 13 deletions packages/subgraph/tests/plugin/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -30,17 +30,16 @@ describe('Plugin', () => {
const daoAddress = Address.fromString(DAO_ADDRESS);
const pluginAddress = Address.fromString(CONTRACT_ADDRESS);

const installationId = generatePluginInstallationEntityId(
let installationId = generatePluginInstallationEntityId(
daoAddress,
pluginAddress
);
if (!installationId) {
throw new Error('Failed to get installationId');
}
const installationIdHex = installationId.toHexString();

installationId = installationId as string;
// Create state
let daoPlugin = new DaoPlugin(installationIdHex);
let daoPlugin = new DaoPlugin(installationId);
daoPlugin.dao = daoAddress;
daoPlugin.pluginAddress = pluginAddress;
daoPlugin.save();
Expand All @@ -54,13 +53,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);
});
});
Expand Down
22 changes: 0 additions & 22 deletions packages/subgraph/tests/plugin/utils.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
// 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';
import {Address, Bytes, ethereum} from '@graphprotocol/graph-ts';
} from '../../generated/PluginSetupProcessor/PluginSetupProcessor';
import {NumberStored} from '../../generated/templates/Plugin/Plugin';
import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts';
import {newMockEvent} from 'matchstick-as';

export function createNewNumberStoredEvent(
number: string,
contractAddress: string
): NumberStored {
let createNumberStoredEvent = changetype<NumberStored>(newMockEvent());

createNumberStoredEvent.address = Address.fromString(contractAddress);
createNumberStoredEvent.parameters = [];

let proposalIdParam = new ethereum.EventParam(
'number',
ethereum.Value.fromSignedBigInt(BigInt.fromString(number))
);

createNumberStoredEvent.parameters.push(proposalIdParam);

return createNumberStoredEvent;
}

export function createInstallationPreparedEvent(
sender: string,
dao: string,
Expand Down
9 changes: 8 additions & 1 deletion packages/subgraph/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# yarn lockfile v1


"@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/[email protected]":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@aragon/osx-ethers/-/osx-ethers-1.3.0.tgz#85ddd93f4448789e94154b313f9ddd8069dff568"
Expand Down Expand Up @@ -437,7 +444,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==
Expand Down
Loading