Skip to content

Commit

Permalink
Merge branch 'main' of github:DA0-DA0/dao-dao-indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Dec 21, 2024
2 parents 28bc88e + 0b99130 commit b987d06
Show file tree
Hide file tree
Showing 13 changed files with 1,772 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/protobuf/codegen/
src/formulas/contract/abstract/types
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@types/node": "^18.11.10",
"@types/prettier": "^2.7.1",
"@types/redis-info": "^3.0.1",
"@types/semver": "^7.5.8",
"@types/supertest": "^2.0.12",
"@types/validator": "^13.7.10",
"@types/ws": "^8.5.5",
Expand Down Expand Up @@ -119,6 +120,7 @@
"pg-hstore": "^2.3.4",
"pusher": "^5.1.2",
"reflect-metadata": "^0.1.13",
"semver": "^7.6.2",
"sequelize": "^6.26.0",
"sequelize-typescript": "^2.1.5",
"supertest": "^6.3.3",
Expand Down
71 changes: 71 additions & 0 deletions src/formulas/formulas/account/abstract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Op } from 'sequelize'

import { AccountFormula } from '@/types'

import { AccountTypes } from '../contract/abstract/types'

/**
* Get all contracts with the account governance owner set to this address.
*/
export const accountsOwnedBy: AccountFormula<
string[],
{
/**
* Optionally filter by code ID key.
*/
key?: string
}
> = {
docs: {
description:
'retrieves account (that use abstract governance to manage ownership) where the account is the owner',
args: [
{
name: 'key',
description: 'optional code ID key to filter by',
required: false,
schema: {
type: 'string',
},
},
],
},
compute: async (env) => {
const {
args: { key },
address,
getTransformationMatches,
getCodeIdsForKeys,
} = env

const owned =
(
await getTransformationMatches(
undefined,
'owner',
{
[Op.or]: [
{
monarchy: {
monarch: address,
},
} satisfies AccountTypes.GovernanceDetailsForString,
{
sub_account: {
account: address,
},
} satisfies AccountTypes.GovernanceDetailsForString,
{
abstract_account: {
address: address,
},
} satisfies AccountTypes.GovernanceDetailsForString,
],
},
key ? getCodeIdsForKeys(key) : undefined
)
)?.map(({ contractAddress }) => contractAddress) || []

return owned
},
}
1 change: 1 addition & 0 deletions src/formulas/formulas/account/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as abstract from './abstract'
export * as bank from './bank'
export * as contract from './contract'
export * as daos from './daos'
Expand Down
134 changes: 134 additions & 0 deletions src/formulas/formulas/contract/abstract/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { ContractFormula } from '@/types'

import { makeSimpleContractFormula } from '../../utils'
import * as Common from '../common'
import { AccountTypes } from './types'
import { Addr, GovernanceDetailsForString } from './types/account'

const AccountStorageKeys = {
SUSPENSION_STATUS: 'aa',
INFO: 'ab',
ACCOUNT_MODULES: 'ac',
DEPENDENTS: 'ad',
SUB_ACCOUNTS: 'ae',
WHITELISTED_MODULES: 'af',
ACCOUNT_ID: 'ag',
OWNER: 'ownership',
}

export const owner = makeSimpleContractFormula<
{ owner: GovernanceDetailsForString },
GovernanceDetailsForString | null
>({
docs: {
description: 'Get the owner of the account',
},
transformation: AccountStorageKeys.OWNER,
fallbackKeys: [AccountStorageKeys.OWNER],
transform: (data) => data.owner,
fallback: null,
})

export const accountId =
makeSimpleContractFormula<AccountTypes.AccountId | null>({
docs: {
description: 'Get accountId of the account',
},
key: AccountStorageKeys.ACCOUNT_ID,
fallback: null,
})

export const suspensionStatus = makeSimpleContractFormula<boolean | null>({
docs: {
description: 'Get suspension status of the account',
},
key: AccountStorageKeys.SUSPENSION_STATUS,
fallback: null,
})

export const info = makeSimpleContractFormula<AccountTypes.AccountInfo | null>({
docs: {
description: 'Get the account info',
},
key: AccountStorageKeys.INFO,
fallback: null,
})

export const whitelistedModules = makeSimpleContractFormula<Addr[] | null>({
docs: {
description: 'Get a list of whitelisted modules',
},
key: AccountStorageKeys.WHITELISTED_MODULES,
fallback: null,
})

export const subAccountIds: ContractFormula<AccountTypes.AccountId[]> = {
docs: {
description: 'Get sub-accounts owned by this account',
},
compute: async ({ contractAddress, getMap }) => {
const subAccountsMap =
(await getMap<number, {}>(
contractAddress,
AccountStorageKeys.SUB_ACCOUNTS,
{
keyType: 'number',
}
)) ?? {}

return Object.keys(subAccountsMap).map((seq) => ({
trace: 'local',
seq: Number(seq),
}))
},
}

export const moduleInfos: ContractFormula<
Array<
Omit<
AccountTypes.ModuleInfosResponse['module_infos'][number],
'version'
> & { version: string | undefined }
>
> = {
docs: {
description: 'Get module infos that are installed on this account',
},
compute: async (env) => {
const { contractAddress, getMap } = env

const moduleAddressesMap =
(await getMap<string, AccountTypes.Addr>(
contractAddress,
AccountStorageKeys.ACCOUNT_MODULES
)) ?? {}

// Query the info from the address of the module
return await Promise.all(
Object.entries(moduleAddressesMap).map(async ([moduleId, address]) => {
const contractInfo = await Common.info.compute({
...env,
contractAddress: address,
})

return {
id: contractInfo?.contract ?? moduleId,
address,
version: contractInfo?.version,
}
})
)
},
}

// TODO: account txs
// export const accountTxs: ContractFormula<any> = {
// docs: {
// description: '',
// },
// compute: async (env) => {
// const { contractAddress, getTxEvents } = env
// const events = await getTxEvents(contractAddress)
// return events || []
// },
// }
2 changes: 2 additions & 0 deletions src/formulas/formulas/contract/abstract/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as account from './account'
export * as registry from './registry'
Loading

0 comments on commit b987d06

Please sign in to comment.