Skip to content

Commit

Permalink
replace dao ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 committed Jul 18, 2023
1 parent a708fb4 commit 06ccbca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
59 changes: 30 additions & 29 deletions packages/subgraph/src/plugin/pluginSetupProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Bytes, log} from '@graphprotocol/graph-ts';
import {getDaoId} from '@aragon/subgraph-commons';
import {
InstallationApplied,
InstallationPrepared,
Expand All @@ -20,7 +21,7 @@ import {
} from './utils';

export function handleInstallationPrepared(event: InstallationPrepared): void {
let dao = event.params.dao.toHexString();
let daoId = getDaoId(event.params.dao);
let plugin = event.params.plugin.toHexString();
let setupId = event.params.preparedSetupId.toHexString();
let pluginRepo = event.params.pluginSetupRepo.toHexString();
Expand All @@ -30,9 +31,9 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
event.params.versionTag.build
);

let installationId = getPluginInstallationId(dao, plugin);
let installationId = getPluginInstallationId(daoId, plugin);
if (!installationId) {
log.error('Failed to get installationId', [dao, plugin]);
log.error('Failed to get installationId', [daoId, plugin]);
return;
}

Expand All @@ -46,7 +47,7 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
let preparationEntity = new PluginPreparation(preparationId);
preparationEntity.installation = installationId.toHexString();
preparationEntity.creator = event.params.sender;
preparationEntity.dao = dao;
preparationEntity.dao = daoId;
preparationEntity.preparedSetupId = event.params.preparedSetupId;
preparationEntity.pluginRepo = event.params.pluginSetupRepo.toHexString();
preparationEntity.pluginVersion = pluginVersionId;
Expand Down Expand Up @@ -77,26 +78,26 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
pluginEntity = new PluginInstallation(installationId.toHexString());
}
pluginEntity.state = 'InstallationPrepared';
pluginEntity.dao = dao;
pluginEntity.dao = daoId;
pluginEntity.save();

addPlugin(dao, event.params.plugin);
addPlugin(daoId, event.params.plugin);
}

export function handleInstallationApplied(event: InstallationApplied): void {
let dao = event.params.dao.toHexString();
let daoId = getDaoId(event.params.dao);
let plugin = event.params.plugin.toHexString();
let installationId = getPluginInstallationId(dao, plugin);
let installationId = getPluginInstallationId(daoId, plugin);
if (!installationId) {
log.error('Failed to get installationId', [dao, plugin]);
log.error('Failed to get installationId', [daoId, plugin]);
return;
}
let preparationId = `${installationId.toHexString()}_${event.params.preparedSetupId.toHexString()}`;

let pluginEntity = PluginInstallation.load(installationId.toHexString());
if (!pluginEntity) {
pluginEntity = new PluginInstallation(installationId.toHexString());
pluginEntity.dao = dao;
pluginEntity.dao = daoId;
}

let pluginPreparationEntity = PluginPreparation.load(preparationId);
Expand All @@ -112,7 +113,7 @@ export function handleInstallationApplied(event: InstallationApplied): void {
}

export function handleUpdatePrepared(event: UpdatePrepared): void {
let dao = event.params.dao.toHexString();
let daoId = getDaoId(event.params.dao);
let plugin = event.params.setupPayload.plugin.toHexString();
let setupId = event.params.preparedSetupId.toHexString();
let pluginRepo = event.params.pluginSetupRepo.toHexString();
Expand All @@ -123,9 +124,9 @@ export function handleUpdatePrepared(event: UpdatePrepared): void {
event.params.versionTag.build
);

let installationId = getPluginInstallationId(dao, plugin);
let installationId = getPluginInstallationId(daoId, plugin);
if (!installationId) {
log.error('Failed to get installationId', [dao, plugin]);
log.error('Failed to get installationId', [daoId, plugin]);
return;
}

Expand All @@ -139,7 +140,7 @@ export function handleUpdatePrepared(event: UpdatePrepared): void {
let preparationEntity = new PluginPreparation(preparationId);
preparationEntity.installation = installationId.toHexString();
preparationEntity.creator = event.params.sender;
preparationEntity.dao = dao;
preparationEntity.dao = daoId;
preparationEntity.preparedSetupId = event.params.preparedSetupId;
preparationEntity.pluginRepo = event.params.pluginSetupRepo.toHexString();
preparationEntity.pluginVersion = pluginVersionId;
Expand Down Expand Up @@ -168,27 +169,27 @@ export function handleUpdatePrepared(event: UpdatePrepared): void {
let pluginEntity = PluginInstallation.load(installationId.toHexString());
if (!pluginEntity) {
pluginEntity = new PluginInstallation(installationId.toHexString());
pluginEntity.dao = dao;
pluginEntity.dao = daoId;
}

pluginEntity.state = 'UpdatePrepared';
pluginEntity.save();
}

export function handleUpdateApplied(event: UpdateApplied): void {
let dao = event.params.dao.toHexString();
let daoId = getDaoId(event.params.dao);
let plugin = event.params.plugin.toHexString();
let installationId = getPluginInstallationId(dao, plugin);
let installationId = getPluginInstallationId(daoId, plugin);
if (!installationId) {
log.error('Failed to get installationId', [dao, plugin]);
log.error('Failed to get installationId', [daoId, plugin]);
return;
}
let preparationId = `${installationId.toHexString()}_${event.params.preparedSetupId.toHexString()}`;

let pluginEntity = PluginInstallation.load(installationId.toHexString());
if (!pluginEntity) {
pluginEntity = new PluginInstallation(installationId.toHexString());
pluginEntity.dao = dao;
pluginEntity.dao = daoId;
}

let pluginPreparationEntity = PluginPreparation.load(preparationId);
Expand All @@ -202,13 +203,13 @@ export function handleUpdateApplied(event: UpdateApplied): void {
pluginEntity.state = 'Installed';
pluginEntity.save();

addPlugin(dao, event.params.plugin);
addPlugin(daoId, event.params.plugin);
}

export function handleUninstallationPrepared(
event: UninstallationPrepared
): void {
let dao = event.params.dao.toHexString();
let daoId = getDaoId(event.params.dao);
let plugin = event.params.setupPayload.plugin.toHexString();
let setupId = event.params.preparedSetupId.toHexString();
let pluginRepo = event.params.pluginSetupRepo.toHexString();
Expand All @@ -219,9 +220,9 @@ export function handleUninstallationPrepared(
event.params.versionTag.build
);

let installationId = getPluginInstallationId(dao, plugin);
let installationId = getPluginInstallationId(daoId, plugin);
if (!installationId) {
log.error('Failed to get installationId', [dao, plugin]);
log.error('Failed to get installationId', [daoId, plugin]);
return;
}

Expand All @@ -230,7 +231,7 @@ export function handleUninstallationPrepared(
let preparationEntity = new PluginPreparation(preparationId);
preparationEntity.installation = installationId.toHexString();
preparationEntity.creator = event.params.sender;
preparationEntity.dao = dao;
preparationEntity.dao = daoId;
preparationEntity.preparedSetupId = event.params.preparedSetupId;
preparationEntity.pluginRepo = event.params.pluginSetupRepo.toHexString();
preparationEntity.pluginVersion = pluginVersionId;
Expand Down Expand Up @@ -258,7 +259,7 @@ export function handleUninstallationPrepared(
let pluginEntity = PluginInstallation.load(installationId.toHexString());
if (!pluginEntity) {
pluginEntity = new PluginInstallation(installationId.toHexString());
pluginEntity.dao = dao;
pluginEntity.dao = daoId;
}
pluginEntity.state = 'UninstallPrepared';
pluginEntity.save();
Expand All @@ -267,19 +268,19 @@ export function handleUninstallationPrepared(
export function handleUninstallationApplied(
event: UninstallationApplied
): void {
let dao = event.params.dao.toHexString();
let daoId = getDaoId(event.params.dao);
let plugin = event.params.plugin.toHexString();
let installationId = getPluginInstallationId(dao, plugin);
let installationId = getPluginInstallationId(daoId, plugin);
if (!installationId) {
log.error('Failed to get installationId', [dao, plugin]);
log.error('Failed to get installationId', [daoId, plugin]);
return;
}
let preparationId = `${installationId.toHexString()}_${event.params.preparedSetupId.toHexString()}`;

let pluginEntity = PluginInstallation.load(installationId.toHexString());
if (!pluginEntity) {
pluginEntity = new PluginInstallation(installationId.toHexString());
pluginEntity.dao = dao;
pluginEntity.dao = daoId;
}
pluginEntity.appliedPreparation = preparationId;
pluginEntity.state = 'Uninstalled';
Expand Down
7 changes: 4 additions & 3 deletions packages/subgraph/src/utils/tokens/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Address, BigInt, Bytes, Value, ethereum} from '@graphprotocol/graph-ts';
import {getDaoId} from '@aragon/subgraph-commons';
import {
ERC20Balance,
ERC20Contract,
Expand Down Expand Up @@ -108,7 +109,7 @@ export function updateERC20Balance(
return;
}

let daoId = dao.toHexString();
let daoId = getDaoId(dao);
let balanceId = daoId.concat('_').concat(token.toHexString());

let erc20Balance = ERC20Balance.load(balanceId);
Expand Down Expand Up @@ -175,7 +176,7 @@ export function handleERC20Action(
amount = tuple[2].toBigInt();
}

let daoId = dao.toHexString();
let daoId = getDaoId(dao);

let id = getTransferId(
event.transaction.hash,
Expand Down Expand Up @@ -231,7 +232,7 @@ export function handleERC20Deposit(
return;
}

let daoId = dao.toHexString();
let daoId = getDaoId(dao);

let id = getTransferId(event.transaction.hash, event.transactionLogIndex, 0);

Expand Down
5 changes: 3 additions & 2 deletions packages/subgraph/src/utils/tokens/erc721.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts';
import {getDaoId} from '@aragon/subgraph-commons';
import {
ERC721Balance,
ERC721Contract,
Expand Down Expand Up @@ -103,7 +104,7 @@ export function handleERC721Received(
let from = tuple[1].toAddress();
let tokenId = tuple[2].toBigInt();

let daoId = dao.toHexString();
let daoId = getDaoId(dao);

updateERC721Balance(
daoId,
Expand Down Expand Up @@ -173,7 +174,7 @@ export function handleERC721Action(
let to = tuple[1].toAddress();
let tokenId = tuple[2].toBigInt();

let daoId = dao.toHexString();
let daoId = getDaoId(dao);

let transferId = getTransferId(
event.transaction.hash,
Expand Down
5 changes: 3 additions & 2 deletions packages/subgraph/src/utils/tokens/eth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Address, BigInt, ethereum} from '@graphprotocol/graph-ts';
import {getDaoId} from '@aragon/subgraph-commons';
import {NativeBalance, NativeTransfer} from '../../../generated/schema';
import {ADDRESS_ZERO} from '../constants';
import {getTransferId, TransferType} from './common';
Expand Down Expand Up @@ -33,7 +34,7 @@ export function handleNativeDeposit(
reference: string,
event: ethereum.Event
): void {
let daoId = dao.toHexString();
let daoId = getDaoId(dao);

let id = getTransferId(event.transaction.hash, event.transactionLogIndex, 0);

Expand Down Expand Up @@ -69,7 +70,7 @@ export function handleNativeAction(
actionIndex: number,
event: ethereum.Event
): void {
let daoId = dao.toHexString();
let daoId = getDaoId(dao);

let id = getTransferId(
event.transaction.hash,
Expand Down

0 comments on commit 06ccbca

Please sign in to comment.