-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
969 additions
and
274 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
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
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 { Command } from '@commander-js/extra-typings'; | ||
import { isAddress } from '@ethersproject/address'; | ||
import { BigDecimal } from '@lens-protocol/shared-kernel'; | ||
import chalk from 'chalk'; | ||
import { createSpinner } from 'nanospinner'; | ||
|
||
import { ensureParentCommand, initLensClient } from '../lib/commandToEnvironment.js'; | ||
import { LENS_HANDLES_CONTRACT, LENS_PROFILES_CONTRACT } from '../lib/consts.js'; | ||
import { formatHandle, formatProfile } from '../lib/formatters.js'; | ||
import { output } from '../lib/output.js'; | ||
import { safeRequest } from '../lib/safeRequest.js'; | ||
|
||
const hexToDecimal = (hex: string) => BigDecimal.from(hex).toFixed(); | ||
|
||
export function investigate() { | ||
const cmd = new Command('investigate') | ||
.description('Investigate a Profile ID, Handle or Wallet Address') | ||
.option('-h, --handle <handle>', 'Handle with prefix (lens/handle)') | ||
.option('-a, --address <address>', 'Wallet address') | ||
.option('-p, --profile <address>', 'Profile ID') | ||
.action(async (options) => { | ||
if (!options.handle && !options.address && !options.profile) { | ||
output.error('At least one of the options is required. See --help for more information.'); | ||
process.exit(1); | ||
} | ||
|
||
const parentCommandName = ensureParentCommand(cmd); | ||
const client = initLensClient(parentCommandName); | ||
|
||
// investigate handle | ||
if (options.handle) { | ||
const fullHandle = options.handle; | ||
|
||
// fetch data | ||
const spinner = createSpinner( | ||
`Investigating handle: ${chalk.green(options.handle)}`, | ||
).start(); | ||
|
||
const address = await safeRequest( | ||
async () => client.handle.resolveAddress({ handle: fullHandle }), | ||
() => spinner.error(), | ||
); | ||
|
||
const profile = await safeRequest( | ||
async () => client.profile.fetch({ forHandle: fullHandle }), | ||
() => spinner.error(), | ||
); | ||
|
||
spinner.success(); | ||
|
||
// render results | ||
output.value(`Resolved address:`, address); | ||
output.info(`Handle details:`, profile && profile.handle && formatHandle(profile.handle)); | ||
output.info(`Linked profile:`, profile && formatProfile(profile)); | ||
|
||
if (parentCommandName === 'production') { | ||
output.value(`URL:`, `https://share.lens.xyz/u/${fullHandle}`); | ||
profile && | ||
profile.handle && | ||
output.value( | ||
`Lens Handles OpenSea:`, | ||
`https://opensea.io/assets/matic/${LENS_HANDLES_CONTRACT}/${hexToDecimal( | ||
profile.handle.id, | ||
)}`, | ||
); | ||
profile && | ||
output.value( | ||
`Lens Profiles OpenSea:`, | ||
`https://opensea.io/assets/matic/${LENS_PROFILES_CONTRACT}/${hexToDecimal( | ||
profile.id, | ||
)}`, | ||
); | ||
} | ||
} | ||
|
||
// investigate address | ||
if (options.address) { | ||
const address = options.address; | ||
|
||
// validate | ||
if (!isAddress(address)) { | ||
output.error(`Invalid address: ${address}`); | ||
process.exit(1); | ||
} | ||
|
||
// fetch data | ||
const spinner = createSpinner(`Investigating address: ${chalk.green(address)}`).start(); | ||
|
||
const managedProfiles = await safeRequest( | ||
async () => client.wallet.profilesManaged({ for: address }), | ||
() => spinner.error(), | ||
); | ||
|
||
const ownedProfiles = await safeRequest( | ||
async () => client.profile.fetchAll({ where: { ownedBy: [address] } }), | ||
() => spinner.error(), | ||
); | ||
|
||
const ownedHandles = await safeRequest( | ||
async () => client.wallet.ownedHandles({ for: address }), | ||
() => spinner.error(), | ||
); | ||
|
||
const rateLimits = await safeRequest( | ||
async () => client.wallet.rateLimits({ userAddress: address }), | ||
() => spinner.error(), | ||
); | ||
|
||
spinner.success(); | ||
|
||
// render results | ||
output.info(`Managed profiles:`, managedProfiles.items.map(formatProfile)); | ||
output.info(`Owned profiles:`, ownedProfiles.items.map(formatProfile)); | ||
output.info( | ||
`Owned handles:`, | ||
ownedHandles.items.map((handle) => formatHandle(handle)), | ||
); | ||
output.info(`Rate limits:`); | ||
console.table(rateLimits); | ||
} | ||
|
||
// investigate profile | ||
if (options.profile) { | ||
output.value(`Investigating profile:`, options.profile); | ||
|
||
// owner | ||
// managers | ||
// linked handle | ||
// lens share link | ||
} | ||
}); | ||
|
||
return cmd; | ||
} |
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
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 const LENS_HANDLES_CONTRACT = '0xe7e7ead361f3aacd73a61a9bd6c10ca17f38e945'; | ||
export const LENS_PROFILES_CONTRACT = '0xdb46d1dc155634fbc732f92e853b10b288ad5a1d'; |
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,27 @@ | ||
import { HandleInfoFragment, ProfileFragment } from '@lens-protocol/client'; | ||
|
||
export function formatProfile(profile: ProfileFragment) { | ||
return { | ||
id: profile.id, | ||
fullHandle: profile.handle && profile.handle.fullHandle, | ||
ownedBy: profile.ownedBy.address, | ||
createdAt: profile.createdAt, | ||
sponsor: profile.sponsor, | ||
signless: profile.signless, | ||
// guardian: profile.guardian, // can only be read by owner | ||
metadata: profile.metadata && { | ||
displayName: profile.metadata.displayName, | ||
bio: profile.metadata.bio, | ||
}, | ||
stats: profile.stats, | ||
}; | ||
} | ||
|
||
export function formatHandle(handle: HandleInfoFragment) { | ||
return { | ||
linkedTo: { | ||
profileId: handle.linkedTo?.nftTokenId, | ||
}, | ||
ownedBy: handle.ownedBy, | ||
}; | ||
} |
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,16 @@ | ||
import chalk from 'chalk'; | ||
|
||
export const output = { | ||
success: function (...args: Parameters<typeof console.log>) { | ||
console.log(chalk.green(...args)); | ||
}, | ||
error: function (...args: Parameters<typeof console.log>) { | ||
console.log(chalk.red(...args)); | ||
}, | ||
info: function (...args: Parameters<typeof console.log>) { | ||
console.log(...args); | ||
}, | ||
value: function (key: string, ...args: Parameters<typeof console.log>) { | ||
console.log(key, chalk.green(...args)); | ||
}, | ||
}; |
Oops, something went wrong.