-
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.
Added transformers and formulas to get vesting contracts with a speci…
…fic admin.
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 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
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,50 @@ | ||
import { Op } from 'sequelize' | ||
|
||
import { WalletFormula } from '@/core' | ||
|
||
export const ownerOf: WalletFormula<string[]> = { | ||
compute: async (env) => { | ||
const { walletAddress, getTransformationMatches, getCodeIdsForKeys } = env | ||
|
||
const cwVestingCodeIds = getCodeIdsForKeys('cw-vesting') | ||
if (!cwVestingCodeIds.length) { | ||
throw new Error('missing cw-vesting code IDs') | ||
} | ||
|
||
// Get all cw1-whitelist contracts with this wallet as an admin. | ||
const cw1WhitelistCodeIds = getCodeIdsForKeys('cw1-whitelist') | ||
const cw1WhitelistContracts = cw1WhitelistCodeIds.length | ||
? (await getTransformationMatches( | ||
undefined, | ||
'admins', | ||
{ | ||
[Op.contains]: walletAddress, | ||
}, | ||
cw1WhitelistCodeIds | ||
)) ?? [] | ||
: [] | ||
|
||
// Get all cw-vesting contracts with this wallet as the owner or a | ||
// cw1-whitelist contract where this wallet is an admin. | ||
const cwVestingContracts = ( | ||
await Promise.all([ | ||
getTransformationMatches( | ||
undefined, | ||
`owner:${walletAddress}`, | ||
undefined, | ||
cwVestingCodeIds | ||
), | ||
...cw1WhitelistContracts.map(({ contractAddress }) => | ||
getTransformationMatches( | ||
undefined, | ||
`owner:${contractAddress}`, | ||
undefined, | ||
cwVestingCodeIds | ||
) | ||
), | ||
]) | ||
).flatMap((m) => m ?? []) | ||
|
||
return cwVestingContracts.map(({ contractAddress }) => contractAddress) | ||
}, | ||
} |
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,8 +1,20 @@ | ||
import { Transformer } from '@/core' | ||
import { dbKeyForKeys } from '@/core/utils' | ||
|
||
import { makeTransformer } from './utils' | ||
|
||
// Transform for all contracts. | ||
const info: Transformer = makeTransformer([], 'info', 'contract_info') | ||
|
||
export default [info] | ||
// Transform for all contracts. cw-ownable ownership | ||
const KEY_OWNERSHIP = dbKeyForKeys('ownership') | ||
const owner: Transformer = { | ||
filter: { | ||
codeIdsKeys: [], | ||
matches: (event) => event.key === KEY_OWNERSHIP, | ||
}, | ||
name: 'owner', | ||
getValue: (event) => event.valueJson.owner, | ||
} | ||
|
||
export default [info, owner] |
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,17 @@ | ||
import { Transformer } from '@/core/types' | ||
import { dbKeyForKeys } from '@/core/utils' | ||
|
||
const CODE_IDS_KEYS: string[] = ['cw1-whitelist'] | ||
|
||
const KEY_ADMIN_LIST = dbKeyForKeys('admin_list') | ||
|
||
const admins: Transformer = { | ||
filter: { | ||
codeIdsKeys: CODE_IDS_KEYS, | ||
matches: (event) => event.key === KEY_ADMIN_LIST, | ||
}, | ||
name: 'admins', | ||
getValue: (event) => event.valueJson.admins, | ||
} | ||
|
||
export default [admins] |
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,5 +1,6 @@ | ||
import cw1Whitelist from './cw1Whitelist' | ||
import cw20 from './cw20' | ||
import cw4Group from './cw4Group' | ||
import cw721 from './cw721' | ||
|
||
export default [...cw20, ...cw4Group, ...cw721] | ||
export default [...cw1Whitelist, ...cw20, ...cw4Group, ...cw721] |