Skip to content

Commit

Permalink
members gnosis fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ipatka committed Jan 20, 2023
1 parent 49e5417 commit 7610877
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 94 deletions.
81 changes: 38 additions & 43 deletions Implementations/API/backend/functions/gnosis/getMembers.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { APIGatewayProxyHandlerV2 } from 'aws-lambda'
import { gnosisGraphConfig } from 'functions/config'
import fetch from 'node-fetch'
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: string, data: any) {
return fetch(path, {
function apiRequest(path: string, method: 'GET' | 'POST', data?: any) {
const payload: RequestInit = {
headers: {
'Content-Type': 'application/json',
},
method,
redirect: 'follow',
body: JSON.stringify(data),
}).then((res) => res.json())
}
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' }

console.log({ graphConfig: gnosisGraphConfig })
const path = gnosisGraphConfig[network]
if (!path) return { statusCode: 400, message: 'Missing config for network' }
const path = gnosisApiConfig[network]
if (!path) return { statusCode: 400, message: 'Missing network' }

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

const checksummedId = utils.getAddress(eventId)

const template = {
'@context': {
Expand All @@ -32,41 +36,32 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
name: eventId,
}

const query = `query GetMembers($dao: String!) {
wallet(id: $dao) {
id
owners
}
}`
const queryPath = path + '/safes/' + checksummedId

const data = {
query,
variables: { dao: eventId.toLowerCase() },
}
console.log({ data })
const res = (await apiRequest(queryPath, 'GET')) as any

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

const res = (await apiRequest(path, 'POST', data)) as any
console.log({ res })
console.log({ owners });

if (!(res.data.wallet)) return { statusCode: 404, message: 'DAO not found' }
const members = res.data.wallet.owners
const membersFormatted = owners.map((a: any) => {
return {
id: a,
type: "EthereumAddress",
};
});

console.log({ members })
const transformed = { members: membersFormatted, ...template };

const membersFormatted = members.map((m: any) => {
return { id: m, type: 'EthereumAddress' }
})
return transformed
? {
statusCode: 200,
body: JSON.stringify(transformed),
}
: {
statusCode: 404,
body: JSON.stringify({ error: true }),
};
};

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

return transformed
? {
statusCode: 200,
body: JSON.stringify(transformed),
}
: {
statusCode: 404,
body: JSON.stringify({ error: true }),
}
}
4 changes: 4 additions & 0 deletions Implementations/API/cdk.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"hosted-zone:account=395914241380:domainName=sandbox.logos.xyz:region=us-east-1": {
"Id": "/hostedzone/Z042029711C667M0O6Y4A",
"Name": "sandbox.logos.xyz."
},
"hosted-zone:account=395914241380:domainName=services.daostar.org:region=us-east-1": {
"Id": "/hostedzone/Z02877671PLIIMUOU6SQ2",
"Name": "services.daostar.org."
}
}
10 changes: 5 additions & 5 deletions Implementations/API/stacks/MyStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export function MyStack({ stack }: StackContext) {
'GET /gnosis/proposals/{network}/{id}': 'functions/gnosis/getProposals.handler',
'GET /gnosis/activities/{network}/{id}': 'functions/gnosis/getActivityLogs.handler',
},
// customDomain: {
// domainName: 'sandbox.logos.xyz',
// hostedZone: 'sandbox.logos.xyz',
// path: 'api/v1',
// },
customDomain: {
domainName: 'services.daostar.org',
hostedZone: 'services.daostar.org',
path: 'api/v1',
},
})

// Show the API endpoint in the output
Expand Down
Binary file not shown.
12 changes: 6 additions & 6 deletions Implementations/Subgraph/daostar/build/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ schema:
templates:
- name: EIP4824Registration
kind: ethereum/contract
network: goerli
network: mainnet
source:
abi: EIP4824Registration
mapping:
Expand All @@ -19,15 +19,15 @@ templates:
file: EIP4824Registration/abis/EIP4824Registration.json
eventHandlers:
- event: NewURI(string,address)
handler: handleNewURIGoerli
handler: handleNewURIMainnet
dataSources:
- kind: ethereum
name: EIP4824RegistrationSummoner
network: goerli
network: mainnet
source:
address: "0x5ef59b7cde41b744f36b6e07fef230884f800529"
address: "0x37dF3fC47C1c3A2acaFd2Dad9c1C00090a8655Bc"
abi: EIP4824RegistrationSummoner
startBlock: 7958681
startBlock: 16084997
mapping:
kind: ethereum/events
apiVersion: 0.0.5
Expand All @@ -40,5 +40,5 @@ dataSources:
file: EIP4824RegistrationSummoner/abis/EIP4824RegistrationSummoner.json
eventHandlers:
- event: NewRegistration(indexed address,string,address)
handler: handleNewRegistrationGoerli
handler: handleNewRegistrationMainnet
file: EIP4824RegistrationSummoner/EIP4824RegistrationSummoner.wasm
80 changes: 40 additions & 40 deletions Implementations/Subgraph/daostar/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ specVersion: 0.0.2
schema:
file: ./schema.graphql
templates:
- name: EIP4824Registration
kind: ethereum/contract
network: goerli
source:
abi: EIP4824Registration
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mapping.ts
entities:
- Registration
abis:
- name: EIP4824Registration
file: ./abis/EIP4824Registration.json
eventHandlers:
- event: NewURI(string,address)
handler: handleNewURIGoerli
# - name: EIP4824Registration
# kind: ethereum/contract
# network: goerli
# source:
# abi: EIP4824Registration
# mapping:
# kind: ethereum/events
# apiVersion: 0.0.5
# language: wasm/assemblyscript
# file: ./src/mapping.ts
# entities:
# - Registration
# abis:
# - name: EIP4824Registration
# file: ./abis/EIP4824Registration.json
# eventHandlers:
# - event: NewURI(string,address)
# handler: handleNewURIGoerli
- name: EIP4824Registration
kind: ethereum/contract
network: mainnet
Expand All @@ -39,30 +39,30 @@ templates:
- event: NewURI(string,address)
handler: handleNewURIMainnet
dataSources:
# - kind: ethereum
# name: EIP4824RegistrationSummoner
# network: goerli
# source:
# address: "0x5ef59b7cde41b744f36b6e07fef230884f800529"
# abi: EIP4824RegistrationSummoner
# startBlock: 7958681
# mapping:
# kind: ethereum/events
# apiVersion: 0.0.5
# language: wasm/assemblyscript
# entities:
# - NewRegistration
# - RegistrationInstance
# abis:
# - name: EIP4824RegistrationSummoner
# file: ./abis/EIP4824RegistrationSummoner.json
# eventHandlers:
# - event: NewRegistration(indexed address,string,address)
# handler: handleNewRegistrationGoerli
# file: ./src/mapping.ts
- kind: ethereum
name: EIP4824RegistrationSummoner
network: goerli
source:
address: "0x5ef59b7cde41b744f36b6e07fef230884f800529"
abi: EIP4824RegistrationSummoner
startBlock: 7958681
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- NewRegistration
- RegistrationInstance
abis:
- name: EIP4824RegistrationSummoner
file: ./abis/EIP4824RegistrationSummoner.json
eventHandlers:
- event: NewRegistration(indexed address,string,address)
handler: handleNewRegistrationGoerli
file: ./src/mapping.ts
- kind: ethereum
name: EIP4824RegistrationSummoner
network: Mainnet
network: mainnet
source:
address: "0x37dF3fC47C1c3A2acaFd2Dad9c1C00090a8655Bc"
abi: EIP4824RegistrationSummoner
Expand Down

0 comments on commit 7610877

Please sign in to comment.