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/populate uris #62

Merged
merged 4 commits into from
Apr 27, 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
75 changes: 75 additions & 0 deletions Implementations/API/backend/functions/daodao/getActivityLogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
import { gnosisApiConfig } from "functions/config";
import fetch, { RequestInit } from 'node-fetch'
import "@ethersproject/shims"
import { utils } from 'ethers'

function apiRequest(path: string, method: 'GET' | 'POST', data?: any) {
const payload: RequestInit = {
headers: {
'Content-Type': 'application/json',
},
method,
redirect: 'follow',
}
if (method === 'POST') payload.body = JSON.stringify(data)
return fetch(path, payload).then((res) => res.json())
}

export const handler: APIGatewayProxyHandlerV2 = async (event) => {
const network = event?.pathParameters?.network
if (!network) return { statusCode: 400, message: 'Missing network' }

const path = gnosisApiConfig[network]
if (!path) return { statusCode: 400, message: 'Missing network' }

const eventId = event?.pathParameters?.id
if (!eventId) return { statusCode: 400 }

const checksummedId = utils.getAddress(eventId)

const template = {
'@context': {
'@vocab': 'http://daostar.org/',
},
type: 'DAO',
name: eventId,
}

const queryPath = path + '/safes/' + checksummedId + '/multisig-transactions/?executed=true'

const res = (await apiRequest(queryPath, 'GET')) as any

if (!res.results) return { statusCode: 404, message: 'DAO not found' }
const activites = res.results

console.log({ activites });

const activitesFormatted = activites.map((a: any) => {
return {
id: a.safe + a.nonce,
value: a.value,
type: "activity",
proposal: {
id: a.nonce,
type: "proposal",
},
member: {
id: a.executor, // TODO executor is not always a member
type: "EthereumAddress",
},
};
});

const transformed = { members: activitesFormatted, ...template };

return transformed
? {
statusCode: 200,
body: JSON.stringify(transformed),
}
: {
statusCode: 404,
body: JSON.stringify({ error: true }),
};
};
67 changes: 67 additions & 0 deletions Implementations/API/backend/functions/daodao/getMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
import { gnosisApiConfig } from "functions/config";
import fetch, { RequestInit } from 'node-fetch'
import "@ethersproject/shims"
import { utils } from 'ethers'

function apiRequest(path: string, method: 'GET' | 'POST', data?: any) {
const payload: RequestInit = {
headers: {
'Content-Type': 'application/json',
},
method,
redirect: 'follow',
}
if (method === 'POST') payload.body = JSON.stringify(data)
return fetch(path, payload).then((res) => res.json())
}

export const handler: APIGatewayProxyHandlerV2 = async (event) => {
const network = event?.pathParameters?.network
if (!network) return { statusCode: 400, message: 'Missing network' }

const path = gnosisApiConfig[network]
if (!path) return { statusCode: 400, message: 'Missing network' }

const eventId = event?.pathParameters?.id
if (!eventId) return { statusCode: 400 }

const checksummedId = utils.getAddress(eventId)

const template = {
'@context': {
'@vocab': 'http://daostar.org/',
},
type: 'DAO',
name: eventId,
}

const queryPath = path + '/safes/' + checksummedId

const res = (await apiRequest(queryPath, 'GET')) as any

if (!res.owners) return { statusCode: 404, message: 'DAO not found' }
const owners = res.owners

console.log({ owners });

const membersFormatted = owners.map((a: any) => {
return {
id: a,
type: "EthereumAddress",
};
});

const transformed = { members: membersFormatted, ...template };

return transformed
? {
statusCode: 200,
body: JSON.stringify(transformed),
}
: {
statusCode: 404,
body: JSON.stringify({ error: true }),
};
};

72 changes: 72 additions & 0 deletions Implementations/API/backend/functions/daodao/getProposals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { APIGatewayProxyHandlerV2 } from 'aws-lambda'
import { gnosisApiConfig } from 'functions/config'
import fetch, { RequestInit } from 'node-fetch'
import "@ethersproject/shims"
import { ethers } from 'ethers'

function apiRequest(path: string, method: 'GET' | 'POST', data?: any) {
const payload: RequestInit = {
headers: {
'Content-Type': 'application/json',
},
method,
redirect: 'follow',
}
if (method === 'POST') payload.body = JSON.stringify(data)
return fetch(path, payload).then((res) => res.json())
}

export const handler: APIGatewayProxyHandlerV2 = async (event) => {
const network = event?.pathParameters?.network
if (!network) return { statusCode: 400, message: 'Missing network' }

const path = gnosisApiConfig[network]
if (!path) return { statusCode: 400, message: 'Missing network' }

const eventId = event?.pathParameters?.id
if (!eventId) return { statusCode: 400 }

console.log({eventId})

const checksummedId = ethers.utils.getAddress(eventId)

console.log({checksummedId})

const template = {
'@context': {
'@vocab': 'http://daostar.org/',
},
type: 'DAO',
name: eventId,
}

const queryPath = path + '/safes/' + checksummedId + '/multisig-transactions/?executed=false'

console.log({queryPath})

const res = (await apiRequest(queryPath, 'GET')) as any

if (!res.results) return { statusCode: 404, message: 'DAO not found' }
const proposals = res.results

const proposalsFormatted = proposals.map((p: any) => {
return {
id: p.nonce,
type: 'proposal',
status: p.isExecuted ? 'Executed' : 'Proposed',
contentURI: p.url,
}
})

const transformed = { proposals: proposalsFormatted, ...template }

return transformed
? {
statusCode: 200,
body: JSON.stringify(transformed),
}
: {
statusCode: 404,
body: JSON.stringify({ error: true }),
}
}
2 changes: 2 additions & 0 deletions Implementations/API/stacks/MyStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function MyStack({ stack }: StackContext) {
'GET /gnosis/members/{network}/{id}': 'functions/gnosis/getMembers.handler',
'GET /gnosis/proposals/{network}/{id}': 'functions/gnosis/getProposals.handler',
'GET /gnosis/activities/{network}/{id}': 'functions/gnosis/getActivityLogs.handler',
'GET /daodao/members/{network}/{id}': 'functions/daodao/getMembers.handler',
'GET /daodao/proposals/{network}/{id}': 'functions/daodao/getProposals.handler',
},
customDomain: {
domainName: 'services.daostar.org',
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions Implementations/Subgraph/daostar/build/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ type RegistrationInstance @entity {
daoAddress: Bytes!
daoURI: String! # string
daoName: String
registrationNetwork: RegistrationNetwork!
daoDescription: String
membersURI: String
proposalsURI: String
governanceURI: String
activityLogURI: String
}

type RegistrationNetwork @entity {
id: ID!
registrations: [RegistrationInstance!] @derivedFrom(field: "registrationNetwork")
chainId: String!
}
72 changes: 72 additions & 0 deletions Implementations/Subgraph/daostar/generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class RegistrationInstance extends Entity {
this.set("registrationAddress", Value.fromBytes(Bytes.empty()));
this.set("daoAddress", Value.fromBytes(Bytes.empty()));
this.set("daoURI", Value.fromString(""));
this.set("registrationNetwork", Value.fromString(""));
}

save(): void {
Expand Down Expand Up @@ -92,6 +93,15 @@ export class RegistrationInstance extends Entity {
}
}

get registrationNetwork(): string {
let value = this.get("registrationNetwork");
return value!.toString();
}

set registrationNetwork(value: string) {
this.set("registrationNetwork", Value.fromString(value));
}

get daoDescription(): string | null {
let value = this.get("daoDescription");
if (!value || value.kind == ValueKind.NULL) {
Expand Down Expand Up @@ -177,3 +187,65 @@ export class RegistrationInstance extends Entity {
}
}
}

export class RegistrationNetwork extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));

this.set("chainId", Value.fromString(""));
}

save(): void {
let id = this.get("id");
assert(id != null, "Cannot save RegistrationNetwork entity without an ID");
if (id) {
assert(
id.kind == ValueKind.STRING,
`Entities of type RegistrationNetwork must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`
);
store.set("RegistrationNetwork", id.toString(), this);
}
}

static load(id: string): RegistrationNetwork | null {
return changetype<RegistrationNetwork | null>(
store.get("RegistrationNetwork", id)
);
}

get id(): string {
let value = this.get("id");
return value!.toString();
}

set id(value: string) {
this.set("id", Value.fromString(value));
}

get registrations(): Array<string> | null {
let value = this.get("registrations");
if (!value || value.kind == ValueKind.NULL) {
return null;
} else {
return value.toStringArray();
}
}

set registrations(value: Array<string> | null) {
if (!value) {
this.unset("registrations");
} else {
this.set("registrations", Value.fromStringArray(<Array<string>>value));
}
}

get chainId(): string {
let value = this.get("chainId");
return value!.toString();
}

set chainId(value: string) {
this.set("chainId", Value.fromString(value));
}
}
7 changes: 7 additions & 0 deletions Implementations/Subgraph/daostar/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ type RegistrationInstance @entity {
daoAddress: Bytes!
daoURI: String! # string
daoName: String
registrationNetwork: RegistrationNetwork!
daoDescription: String
membersURI: String
proposalsURI: String
governanceURI: String
activityLogURI: String
}

type RegistrationNetwork @entity {
id: ID!
registrations: [RegistrationInstance!] @derivedFrom(field: "registrationNetwork")
chainId: String!
}
15 changes: 12 additions & 3 deletions Implementations/Subgraph/daostar/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { BigInt, ipfs, json, JSONValueKind, log } from '@graphprotocol/graph-ts'
import { BigInt, ipfs, json, JSONValueKind, log, dataSource } from '@graphprotocol/graph-ts'
import { NewRegistration } from '../generated/EIP4824RegistrationSummoner/EIP4824RegistrationSummoner'
import { NewURI } from '../generated/templates/EIP4824Registration/EIP4824Registration'
import { RegistrationInstance } from '../generated/schema'
import { RegistrationInstance, RegistrationNetwork } from '../generated/schema'
import { EIP4824Registration } from '../generated/templates'

export function handleNewRegistration(event: NewRegistration): void {
const chainName = dataSource.network() // returns network name

let registrationNetwork = RegistrationNetwork.load(chainName)
if (!registrationNetwork) {
registrationNetwork = new RegistrationNetwork(chainName)
registrationNetwork.save()
}

let daoAddress = event.params.daoAddress.toHex()
let daoId = daoAddress
let registrationInstance = RegistrationInstance.load(daoId)
Expand All @@ -15,6 +23,7 @@ export function handleNewRegistration(event: NewRegistration): void {
registrationInstance = new RegistrationInstance(newAddress)
}

registrationInstance.registrationNetwork = chainName
registrationInstance.registrationAddress = event.params.registration
registrationInstance.daoAddress = event.params.daoAddress
registrationInstance.daoURI = event.params.daoURI
Expand Down Expand Up @@ -80,7 +89,7 @@ export function handleNewURI(event: NewURI): void {
const governanceURI = daoMetadata.get('governanceURI')
const activityLogURI = daoMetadata.get('activityLogURI')

registrationInstance.daoName = daoName && daoName.kind == JSONValueKind.STRING ? daoName.toString() : ''
registrationInstance.daoName = daoName && daoName.kind == JSONValueKind.STRING ? daoName.toString() : ''
registrationInstance.daoDescription = daoDescription && daoDescription.kind == JSONValueKind.STRING ? daoDescription.toString() : ''
registrationInstance.membersURI = membersURI && membersURI.kind == JSONValueKind.STRING ? membersURI.toString() : ''
registrationInstance.proposalsURI = proposalsURI && proposalsURI.kind == JSONValueKind.STRING ? proposalsURI.toString() : ''
Expand Down
Loading