-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github:DA0-DA0/dao-dao-indexer
- Loading branch information
Showing
13 changed files
with
1,772 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
src/protobuf/codegen/ | ||
src/formulas/contract/abstract/types |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 || [] | ||
// }, | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * as account from './account' | ||
export * as registry from './registry' |
Oops, something went wrong.