-
Notifications
You must be signed in to change notification settings - Fork 7
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
Safe subgraph queries #2746
Safe subgraph queries #2746
Changes from 4 commits
7ad668c
67c8655
a23c6e9
2612a16
03d6d07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Address, Hex } from 'viem'; | ||
|
||
// Define the base DAO structure that can be nested | ||
interface Safe { | ||
id: Address; | ||
created: string; | ||
creator: Address; | ||
transactionHash: Hex; | ||
factoryAddress: Address; | ||
singleton: Address; | ||
setupData: Hex; | ||
} | ||
|
||
// Define the top-level DAO response structure | ||
export interface SafeQueryResponse { | ||
safes: Safe[]; | ||
} | ||
|
||
export const SafeQuery = `query SafeQuery($safeAddress: Bytes) { | ||
safes(where: { id: $safeAddress }) { | ||
id | ||
created | ||
creator | ||
transactionHash | ||
factoryAddress | ||
singleton | ||
setupData | ||
} | ||
}`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import { | |
} from 'viem'; | ||
import GnosisSafeL2Abi from '../../../assets/abi/GnosisSafeL2'; | ||
import { SENTINEL_ADDRESS } from '../../../constants/common'; | ||
import { createDecentSubgraphClient } from '../../../graphql'; | ||
import { SafeQuery } from '../../../graphql/SafeQueries'; | ||
import { SafeWithNextNonce } from '../../../types'; | ||
import { NetworkConfig } from '../../../types/network'; | ||
import { useNetworkConfigStore } from '../../NetworkConfig/useNetworkConfigStore'; | ||
|
@@ -141,31 +143,40 @@ class EnhancedSafeApiKit extends SafeApiKit { | |
console.error('Error fetching getSafeCreationInfo from safeAPI:', error); | ||
} | ||
|
||
// TODO: uncomment this out once subgraph testing is completed and working | ||
// try { | ||
// type SafeClientCreationInfoResponse = { | ||
// readonly created: string; | ||
// readonly creator: string; | ||
// readonly transactionHash: string; | ||
// readonly factoryAddress: string; | ||
|
||
// readonly masterCopy: string; | ||
// readonly setupData: string; | ||
// }; | ||
|
||
// const response: SafeClientCreationInfoResponse = await this._safeClientGet( | ||
// safeAddress, | ||
// '/transactions/creation', | ||
// ); | ||
|
||
// return { ...response, singleton: response.masterCopy }; | ||
// } catch (error) { | ||
// console.error('Error fetching getSafeCreationInfo from safe-client:', error); | ||
// } | ||
|
||
// TODO: this is what needs to be tested | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good place to start. Find out where in the codebase is calling this You can use the Playground to verify that data is actually there and available: Check out the query in When I left off, the subgraph calls were returning strange "Message: Not Found" errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not getting the error now. Seems to work for me, so I can search on mainnet on sepolia. This DAO: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were you able to figure out why, @DarksightKellar ? |
||
try { | ||
type SafeClientCreationInfoResponse = { | ||
readonly created: string; | ||
readonly creator: string; | ||
readonly transactionHash: string; | ||
readonly factoryAddress: string; | ||
|
||
readonly masterCopy: string; | ||
readonly setupData: string; | ||
}; | ||
|
||
const response: SafeClientCreationInfoResponse = await this._safeClientGet( | ||
safeAddress, | ||
'/transactions/creation', | ||
); | ||
const client = createDecentSubgraphClient(this.networkConfig); | ||
const queryResult = await client.query<any>(SafeQuery, { safeAddress }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use the actual type from SafeQueries, not "any" |
||
|
||
return { ...response, singleton: response.masterCopy }; | ||
} catch (error) { | ||
console.error('Error fetching getSafeCreationInfo from safe-client:', error); | ||
} | ||
console.log('queryResult', queryResult); | ||
|
||
try { | ||
// TODO ENG-291 | ||
// add another layer of onchain fallback here | ||
// use subgraph to get this data | ||
const safeCreationInfo = queryResult.data?.safes[0]; | ||
if (safeCreationInfo) { | ||
return safeCreationInfo; | ||
} | ||
console.log('Safe creation info not found'); | ||
} catch (error) { | ||
console.error('Error fetching getSafeCreationInfo from subgraph:', error); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here to make the DAO Searching do all network requests in parallel, not in sequence. Faster searching.