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

Abstract Indexer Definitions #12

Merged
merged 32 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
11f5ff8
Initial abstract manager implementation
adairrr Jun 28, 2024
572d557
Updtae manager with moduleInfos
adairrr Jun 28, 2024
11a1c0d
Add basic proxy indexes
adairrr Jun 28, 2024
50a44e5
Merge remote-tracking branch 'origin/main' into adair/abstract
Buckram123 Nov 18, 2024
09729ab
update registry and account types
Buckram123 Nov 18, 2024
963704e
export abstract contract formulas
Buckram123 Nov 18, 2024
344ec58
progress
Buckram123 Nov 21, 2024
7ae4e3c
list accountsOwnedBy
Buckram123 Nov 22, 2024
500fd31
update module formula
Buckram123 Nov 22, 2024
2946b43
openapi update
Buckram123 Nov 22, 2024
1672739
dodged transformers
Buckram123 Nov 22, 2024
4925996
cleanup
Buckram123 Nov 22, 2024
7cf23b8
rename api path
Buckram123 Nov 22, 2024
208b0f1
optimized abstractAccount/accountsOwnedBy query
NoahSaso Dec 20, 2024
cbe05d0
Initial abstract manager implementation
adairrr Jun 28, 2024
8b0ced3
Updtae manager with moduleInfos
adairrr Jun 28, 2024
be07e08
Add basic proxy indexes
adairrr Jun 28, 2024
8dede98
update registry and account types
Buckram123 Nov 18, 2024
d2d5ae6
export abstract contract formulas
Buckram123 Nov 18, 2024
f9be91a
progress
Buckram123 Nov 21, 2024
bf21967
list accountsOwnedBy
Buckram123 Nov 22, 2024
09a3d0a
update module formula
Buckram123 Nov 22, 2024
540f238
openapi update
Buckram123 Nov 22, 2024
c5b9648
dodged transformers
Buckram123 Nov 22, 2024
a24de9c
cleanup
Buckram123 Nov 22, 2024
06fce90
rename api path
Buckram123 Nov 22, 2024
f74043d
optimized abstractAccount/accountsOwnedBy query
NoahSaso Dec 20, 2024
fb613fe
Merge branch 'adair/abstract' of github:AbstractSDK/dao-dao-indexer i…
NoahSaso Dec 20, 2024
c567d2b
cleaned up abstract stuff
NoahSaso Dec 20, 2024
62d3463
formatted
NoahSaso Dec 20, 2024
5331d3a
Update abstract types to 0.26
adairrr Dec 20, 2024
bf8be0f
Add Abstract Indexer definitions
adairrr Dec 21, 2024
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
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 @@ -60,6 +60,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 @@ -118,6 +119,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
Loading