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

Add: use osx-commons-subgraph #520

Merged
merged 9 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
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: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"**/@graphprotocol/graph-cli",
"**/@graphprotocol/graph-cli/**",
"**/matchstick-as",
"**/matchstick-as/**"
"**/matchstick-as/**",
"**/@aragon/osx-commons-subgraph",
"**/@aragon/osx-commons-subgraph/**"
]
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"mustache": "^4.2.0",
"ts-morph": "^17.0.1",
"typescript": "^4.9.5"
},
"dependencies": {
"@aragon/osx-commons-subgraph": "^0.0.3"
}
}
79 changes: 44 additions & 35 deletions packages/subgraph/src/dao/dao_v1_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ import {
} from '../utils/tokens/erc1155';
import {handleNativeDeposit} from '../utils/tokens/eth';
import {handleAction, updateProposalWithFailureMap} from './utils';
import {
generateDaoEntityId,
generatePermissionEntityId,
generateProposalEntityId,
generateStandardCallbackEntityId,
generateTransactionActionsProposalEntityId,
} from '@aragon/osx-commons-subgraph';
import {BigInt, Bytes, store} from '@graphprotocol/graph-ts';

export function handleMetadataSet(event: MetadataSet): void {
let daoId = event.address.toHexString();
let daoId = generateDaoEntityId(event.address);
let metadata = event.params.metadata.toString();
_handleMetadataSet(daoId, metadata);
}
Expand Down Expand Up @@ -76,16 +83,16 @@ export function handleCallbackReceived(event: CallbackReceived): void {
}

export function handleExecuted(event: Executed): void {
let proposalId = event.params.actor
.toHexString()
.concat('_')
.concat(event.params.callId.toHexString());
let proposalEntityId = generateProposalEntityId(
event.params.actor,
BigInt.fromByteArray(event.params.callId)
);

// Not an effective solution, until each plugin has
// its own subgraph separately.
// If proposal found, update its failureMap.
let wasUpdated = updateProposalWithFailureMap(
proposalId,
proposalEntityId,
event.params.failureMap
);

Expand All @@ -100,13 +107,14 @@ export function handleExecuted(event: Executed): void {
// might be a case when 2 different tx might end up having the same
// proposal ID which will cause overwrite. In case of plugins,
// It's plugin's responsibility to pass unique callId per execute.
proposalId = proposalId
.concat('_')
.concat(event.transaction.hash.toHexString())
.concat('_')
.concat(event.transactionLogIndex.toHexString());
let proposal = new TransactionActionsProposal(proposalId);
proposal.dao = event.address.toHexString();
proposalEntityId = generateTransactionActionsProposalEntityId(
proposalEntityId,
event.transaction.hash,
event.logIndex
);

let proposal = new TransactionActionsProposal(proposalEntityId);
proposal.dao = generateDaoEntityId(event.address);
proposal.createdAt = event.block.timestamp;
proposal.endDate = event.block.timestamp;
proposal.startDate = event.block.timestamp;
Expand All @@ -123,7 +131,7 @@ export function handleExecuted(event: Executed): void {
let actions = event.params.actions;

for (let index = 0; index < actions.length; index++) {
handleAction(actions[index], proposalId, index, event);
handleAction(actions[index], proposalEntityId, index, event);
}
}

Expand Down Expand Up @@ -159,19 +167,17 @@ export function handleNativeTokenDeposited(event: NativeTokenDeposited): void {
}

export function handleGranted(event: Granted): void {
const contractAddress = event.address.toHexString();
const contractAddress = event.address;
const where = event.params.where;
const permissionId = event.params.permissionId;
const who = event.params.who;

const permissionEntityId = [
const permissionEntityId = generatePermissionEntityId(
contractAddress,
permissionId.toHexString(),
where.toHexString(),
who.toHexString(),
].join('_');

const daoAddress = contractAddress;
permissionId,
where,
who
);

// Permission
let permissionEntity = Permission.load(permissionEntityId);
Expand All @@ -183,24 +189,24 @@ export function handleGranted(event: Granted): void {
permissionEntity.actor = event.params.here;
permissionEntity.condition = event.params.condition;

permissionEntity.dao = daoAddress;
permissionEntity.dao = generateDaoEntityId(contractAddress);
permissionEntity.save();
}
}

export function handleRevoked(event: Revoked): void {
// permission
const contractAddress = event.address.toHexString();
const contractAddress = event.address;
const where = event.params.where;
const permissionId = event.params.permissionId;
const who = event.params.who;

const permissionEntityId = [
const permissionEntityId = generatePermissionEntityId(
contractAddress,
permissionId.toHexString(),
where.toHexString(),
who.toHexString(),
].join('_');
permissionId,
where,
who
);

let permissionEntity = Permission.load(permissionEntityId);
if (permissionEntity) {
Expand All @@ -209,7 +215,7 @@ export function handleRevoked(event: Revoked): void {
}

export function handleTrustedForwarderSet(event: TrustedForwarderSet): void {
let daoId = event.address.toHexString();
let daoId = generateDaoEntityId(event.address);
let entity = Dao.load(daoId);
if (entity) {
entity.trustedForwarder = event.params.forwarder;
Expand All @@ -220,22 +226,25 @@ export function handleTrustedForwarderSet(event: TrustedForwarderSet): void {
export function handleStandardCallbackRegistered(
event: StandardCallbackRegistered
): void {
let daoId = event.address.toHexString();
let entityId = `${daoId}_${event.params.interfaceId.toHexString()}`;
let daoAddress = event.address;
let interfaceId = event.params.interfaceId;

let daoId = generateDaoEntityId(daoAddress);
let entityId = generateStandardCallbackEntityId(daoAddress, interfaceId);
let entity = StandardCallback.load(entityId);
if (!entity) {
entity = new StandardCallback(entityId);
entity.dao = daoId;
}
entity.interfaceId = event.params.interfaceId;
entity.interfaceId = interfaceId;
entity.callbackSelector = event.params.callbackSelector;
entity.magicNumber = event.params.magicNumber;
entity.save();
}

export function handleNewURI(event: NewURI): void {
let daoId = event.address.toHexString();
let entity = Dao.load(daoId);
let daoEntityId = generateDaoEntityId(event.address);
let entity = Dao.load(daoEntityId);
if (entity) {
entity.daoURI = event.params.daoURI;
entity.save();
Expand Down
33 changes: 21 additions & 12 deletions packages/subgraph/src/dao/dao_v1_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ import {
ExecutedActionsStruct,
} from '../../generated/templates/DaoTemplateV1_3_0/DAO';
import {handleAction} from './utils';
import {
generateDaoEntityId,
generateProposalEntityId,
generateTransactionActionsProposalEntityId,
} from '@aragon/osx-commons-subgraph';
import {BigInt} from '@graphprotocol/graph-ts';

export function handleExecuted(event: Executed): void {
let proposalId = event.params.actor
.toHexString()
.concat('_')
.concat(event.params.callId.toHexString());
let proposalEntityId = generateProposalEntityId(
event.params.actor,
BigInt.fromByteArray(event.params.callId)
);

proposalId = proposalId
.concat('_')
.concat(event.transaction.hash.toHexString())
.concat('_')
.concat(event.transactionLogIndex.toHexString());
let proposal = new TransactionActionsProposal(proposalId);
proposal.dao = event.address.toHexString();
let transactionActionsProposalEntityId =
generateTransactionActionsProposalEntityId(
proposalEntityId,
event.transaction.hash,
event.transactionLogIndex
);
let proposal = new TransactionActionsProposal(
transactionActionsProposalEntityId
);
proposal.dao = generateDaoEntityId(event.address);
proposal.createdAt = event.block.timestamp;
proposal.endDate = event.block.timestamp;
proposal.startDate = event.block.timestamp;
Expand All @@ -33,7 +42,7 @@ export function handleExecuted(event: Executed): void {
for (let index = 0; index < actions.length; index++) {
handleAction<ExecutedActionsStruct, Executed>(
actions[index],
proposalId,
transactionActionsProposalEntityId,
index,
event
);
Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/src/dao/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {handleERC20Action} from '../utils/tokens/erc20';
import {handleERC721Action} from '../utils/tokens/erc721';
import {handleERC1155Action} from '../utils/tokens/erc1155';
import {handleNativeAction} from '../utils/tokens/eth';
import {generateDaoEntityId} from '@aragon/osx-commons-subgraph';
import {BigInt} from '@graphprotocol/graph-ts';

// AssemblyScript struggles having multiple return types. Due to this,
Expand Down Expand Up @@ -104,7 +105,7 @@ function getOrCreateActionEntity<
entity.value = action.value;
entity.data = action.data;
entity.proposal = proposalId;
entity.dao = event.address.toHexString();
entity.dao = generateDaoEntityId(event.address);
}

return entity;
Expand Down
64 changes: 36 additions & 28 deletions packages/subgraph/src/packages/addresslist/addresslist-voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ import {
VotingSettingsUpdated,
} from '../../../generated/templates/AddresslistVoting/AddresslistVoting';
import {RATIO_BASE, VOTER_OPTIONS, VOTING_MODES} from '../../utils/constants';
import {getProposalId} from '../../utils/proposals';
import {generateMemberEntityId, generateVoteEntityId} from '../../utils/ids';
import {
generateActionEntityId,
generateEntityIdFromAddress,
generatePermissionEntityId,
generatePluginEntityId,
generateProposalEntityId,
} from '@aragon/osx-commons-subgraph';
import {BigInt, dataSource, store} from '@graphprotocol/graph-ts';

export function handleProposalCreated(event: ProposalCreated): void {
Expand All @@ -32,12 +39,13 @@ export function _handleProposalCreated(
metadata: string
): void {
let pluginAddress = event.address;
let pluginEntityId = generatePluginEntityId(pluginAddress);
let pluginProposalId = event.params.proposalId;
let proposalId = getProposalId(pluginAddress, pluginProposalId);
let proposalId = generateProposalEntityId(pluginAddress, pluginProposalId);

let proposalEntity = new AddresslistVotingProposal(proposalId);
proposalEntity.dao = daoId;
proposalEntity.plugin = pluginAddress.toHexString();
proposalEntity.plugin = pluginEntityId;
proposalEntity.pluginProposalId = pluginProposalId;
proposalEntity.creator = event.params.creator;
proposalEntity.metadata = metadata;
Expand Down Expand Up @@ -75,10 +83,7 @@ export function _handleProposalCreated(
let actions = proposal.value.value4;
for (let index = 0; index < actions.length; index++) {
const action = actions[index];

let actionId = getProposalId(pluginAddress, pluginProposalId)
.concat('_')
.concat(index.toString());
let actionId = generateActionEntityId(proposalId, index);

let actionEntity = new Action(actionId);
actionEntity.to = action.to;
Expand Down Expand Up @@ -110,12 +115,13 @@ export function _handleProposalCreated(

export function handleVoteCast(event: VoteCast): void {
const pluginProposalId = event.params.proposalId;
const member = event.params.voter.toHexString();
const memberAddress = event.params.voter;
const pluginAddress = event.address;
const pluginId = pluginAddress.toHexString();
const memberId = pluginId.concat('_').concat(member);
let proposalId = getProposalId(pluginAddress, pluginProposalId);
let voterVoteId = member.concat('_').concat(proposalId);
const pluginEntityId = generatePluginEntityId(pluginAddress);
const memberEntityId = generateMemberEntityId(pluginAddress, memberAddress);

let proposalId = generateProposalEntityId(pluginAddress, pluginProposalId);
let voterVoteId = generateVoteEntityId(memberAddress, proposalId);
let voteOption = VOTER_OPTIONS.get(event.params.voteOption);

if (voteOption === 'None') {
Expand All @@ -128,7 +134,7 @@ export function handleVoteCast(event: VoteCast): void {
voterProposalVoteEntity.updatedAt = event.block.timestamp;
} else {
voterProposalVoteEntity = new AddresslistVotingVote(voterVoteId);
voterProposalVoteEntity.voter = memberId;
voterProposalVoteEntity.voter = memberEntityId;
voterProposalVoteEntity.proposal = proposalId;
voterProposalVoteEntity.createdAt = event.block.timestamp;
voterProposalVoteEntity.voteReplaced = false;
Expand Down Expand Up @@ -201,7 +207,7 @@ export function handleVoteCast(event: VoteCast): void {

export function handleProposalExecuted(event: ProposalExecuted): void {
let pluginProposalId = event.params.proposalId;
let proposalId = getProposalId(event.address, pluginProposalId);
let proposalId = generateProposalEntityId(event.address, pluginProposalId);

let proposalEntity = AddresslistVotingProposal.load(proposalId);
if (proposalEntity) {
Expand All @@ -217,7 +223,9 @@ export function handleProposalExecuted(event: ProposalExecuted): void {
export function handleVotingSettingsUpdated(
event: VotingSettingsUpdated
): void {
let packageEntity = AddresslistVotingPlugin.load(event.address.toHexString());
let pluginAddress = event.address;
let pluginEntityId = generatePluginEntityId(pluginAddress);
let packageEntity = AddresslistVotingPlugin.load(pluginEntityId);
if (packageEntity) {
packageEntity.votingMode = VOTING_MODES.get(event.params.votingMode);
packageEntity.supportThreshold = event.params.supportThreshold;
Expand All @@ -231,15 +239,15 @@ export function handleVotingSettingsUpdated(
export function handleMembersAdded(event: MembersAdded): void {
let members = event.params.members;
for (let index = 0; index < members.length; index++) {
const member = members[index].toHexString();
const pluginId = event.address.toHexString();
const memberId = pluginId + '_' + member;

let voterEntity = AddresslistVotingVoter.load(memberId);
const memberAddress = members[index];
const pluginAddress = event.address;
const pluginEntityId = generatePluginEntityId(pluginAddress);
const memberEntityId = generateMemberEntityId(pluginAddress, memberAddress);
let voterEntity = AddresslistVotingVoter.load(memberEntityId);
if (!voterEntity) {
voterEntity = new AddresslistVotingVoter(memberId);
voterEntity.address = member;
voterEntity.plugin = pluginId;
voterEntity = new AddresslistVotingVoter(memberEntityId);
voterEntity.address = generateEntityIdFromAddress(memberAddress);
voterEntity.plugin = pluginEntityId;
voterEntity.save();
}
}
Expand All @@ -248,13 +256,13 @@ export function handleMembersAdded(event: MembersAdded): void {
export function handleMembersRemoved(event: MembersRemoved): void {
let members = event.params.members;
for (let index = 0; index < members.length; index++) {
const member = members[index].toHexString();
const pluginId = event.address.toHexString();
const memberId = pluginId + '_' + member;
const memberAddress = members[index];
let pluginAddress = event.address;
const memberEntityId = generateMemberEntityId(pluginAddress, memberAddress);

let voterEntity = AddresslistVotingVoter.load(memberId);
let voterEntity = AddresslistVotingVoter.load(memberEntityId);
if (voterEntity) {
store.remove('AddresslistVotingVoter', memberId);
store.remove('AddresslistVotingVoter', memberEntityId);
}
}
}
Loading
Loading