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: adds blocklist to remove subdomains from indexing #310

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UPCOMING]
## [1.0.1]

### Added

- Add `executable` attribute to `MultisigProposal`.
- Added `subdomain_blocklist` for DAO indexing.

### Changed

Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/osx-subgraph",
"version": "0.10.0-alpha",
"version": "1.0.1",
"description": "The Aragon OSx Subgraph",
"homepage": "https://github.com/aragon/osx",
"license": "AGPL-3.0-or-later",
Expand Down
22 changes: 21 additions & 1 deletion packages/subgraph/src/registries/daoRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import {DAORegistered} from '../../generated/DAORegistry/DAORegistry';
import {DaoTemplate} from '../../generated/templates';
import {Dao} from '../../generated/schema';
import {dataSource} from '@graphprotocol/graph-ts';

// blocklists of addresses for which we don't index the subdomain.
// Put the reason next to the address as a comment
const subdomain_blocklist_mainnet = [
'0x16070493aa513f91fc8957f14b7b7c6c0c41fbac' // domain squatting lido.dao.eth
];

export function handleDAORegistered(event: DAORegistered): void {
let id = event.params.dao.toHexString(); // use dao address as id, because it should not repeat
let entity = new Dao(id);

entity.subdomain = event.params.subdomain;
if (!isInSubdomainBlocklist(id)) {
entity.subdomain = event.params.subdomain;
}

entity.creator = event.params.creator;
entity.createdAt = event.block.timestamp;

Expand All @@ -15,3 +25,13 @@ export function handleDAORegistered(event: DAORegistered): void {

entity.save();
}

// checks if a certain address is in the blocklist. Returns false by default
function isInSubdomainBlocklist(address: string): bool {
// switch case doesn't work with assemblyscript
if (dataSource.network() == 'mainnet') {
return subdomain_blocklist_mainnet.includes(address);
}

return false;
}
94 changes: 67 additions & 27 deletions packages/subgraph/tests/registry/daoRegistry.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
import {assert, clearStore, test} from 'matchstick-as/assembly/index';
import {
assert,
clearStore,
test,
dataSourceMock,
describe,
afterEach
} from 'matchstick-as/assembly/index';
import {Address} from '@graphprotocol/graph-ts';

import {handleDAORegistered} from '../../src/registries/daoRegistry';
import {DAO_ADDRESS, ADDRESS_ONE} from '../constants';
import {createNewDaoEvent} from './utils';
import {Dao} from '../../generated/schema';

test('Run dao registry mappings with mock event', () => {
// create event
let newDaoEvent = createNewDaoEvent(DAO_ADDRESS, ADDRESS_ONE, 'mock-Dao');

// handle event
handleDAORegistered(newDaoEvent);

let entityID = Address.fromString(DAO_ADDRESS).toHexString();

// checks
assert.fieldEquals('Dao', entityID, 'id', entityID);
assert.fieldEquals(
'Dao',
entityID,
'creator',
Address.fromString(ADDRESS_ONE).toHexString()
);
assert.fieldEquals('Dao', entityID, 'subdomain', 'mock-Dao');
assert.fieldEquals(
'Dao',
entityID,
'createdAt',
newDaoEvent.block.timestamp.toString()
);

clearStore();
describe('DAORegistry', () => {
afterEach(() => {
clearStore();
});

test('Run dao registry mappings with mock event', () => {
// create event
let newDaoEvent = createNewDaoEvent(DAO_ADDRESS, ADDRESS_ONE, 'mock-Dao');

// handle event
handleDAORegistered(newDaoEvent);

let entityID = Address.fromString(DAO_ADDRESS).toHexString();

// checks
assert.fieldEquals('Dao', entityID, 'id', entityID);
assert.fieldEquals(
'Dao',
entityID,
'creator',
Address.fromString(ADDRESS_ONE).toHexString()
);
assert.fieldEquals('Dao', entityID, 'subdomain', 'mock-Dao');
assert.fieldEquals(
'Dao',
entityID,
'createdAt',
newDaoEvent.block.timestamp.toString()
);
});

test("Don't store subdomain for blocklisted DAO", () => {
// Using an already blocklisted address for mainnet. This is unlikely to change
let entityID = '0x16070493aa513f91fc8957f14b7b7c6c0c41fbac';
// create event.
let newDaoEvent = createNewDaoEvent(entityID, ADDRESS_ONE, 'mock-Dao');
dataSourceMock.setNetwork('mainnet');

handleDAORegistered(newDaoEvent);

// checks
assert.fieldEquals('Dao', entityID, 'id', entityID);
assert.fieldEquals(
'Dao',
entityID,
'creator',
Address.fromString(ADDRESS_ONE).toHexString()
);
assert.fieldEquals(
'Dao',
entityID,
'createdAt',
newDaoEvent.block.timestamp.toString()
);

const daoEntity = Dao.load(entityID);
assert.assertNull(daoEntity!.subdomain);
});
});