Skip to content

feat: onchain reputation check #21

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ Example query to Claude:

> "Buy $20 worth of OpenRouter credits."

### check_onchain_reputation

Checks the CDP onchain reputation of an Ethereum address.

Parameters:

- `address`: The Ethereum address to check reputation for

Example query to Claude:

> "Check the onchain reputation of 0x1234567890abcdef1234567890abcdef12345678."

## Security Considerations

- The configuration file contains sensitive information (API keys and seed phrases). Ensure it's properly secured and not shared.
Expand Down
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { erc20BalanceTool, erc20TransferTool } from './erc20/index.js';
import { getMorphoVaultsTool } from './morpho/index.js';
import { getOnrampAssetsTool, onrampTool } from './onramp/index.js';
import { buyOpenRouterCreditsTool } from './open-router/index.js';
import { checkReputationTool } from './reputation/index.js';
import type { ToolHandler, ToolWithHandler } from './types.js';

export const baseMcpTools: ToolWithHandler[] = [
Expand All @@ -13,6 +14,7 @@ export const baseMcpTools: ToolWithHandler[] = [
erc20BalanceTool,
erc20TransferTool,
buyOpenRouterCreditsTool,
checkReputationTool,
];

export const toolToHandler: Record<string, ToolHandler> = baseMcpTools.reduce<
Expand Down
22 changes: 22 additions & 0 deletions src/tools/reputation/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ExternalAddress } from '@coinbase/coinbase-sdk';
import { isAddress } from 'viem';
import type { PublicActions, WalletClient } from 'viem';
import type { z } from 'zod';
import { CheckReputationSchema } from './schemas.js';

export async function checkReputationHandler(
wallet: WalletClient & PublicActions,
args: z.infer<typeof CheckReputationSchema>,
): Promise<string> {
const { address } = args;

// Validate the address format
if (!isAddress(address, { strict: false })) {
throw new Error(`Invalid Ethereum address: ${address}`);
}

const externalAddress = new ExternalAddress('base-mainnet', address);
const reputation = await externalAddress.reputation();

return `Reputation score: ${reputation.score}, Metadata: ${JSON.stringify(reputation.metadata)}`;
}
10 changes: 10 additions & 0 deletions src/tools/reputation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { generateTool } from '../../utils.js';
import { checkReputationHandler } from './handlers.js';
import { CheckReputationSchema } from './schemas.js';

export const checkReputationTool = generateTool({
name: 'check_onchain_reputation',
description: 'Check the onchain reputation of an Ethereum address',
inputSchema: CheckReputationSchema,
toolHandler: checkReputationHandler,
});
7 changes: 7 additions & 0 deletions src/tools/reputation/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod';

export const CheckReputationSchema = z.object({
address: z
.string()
.describe('The Ethereum address to check CDP onchain reputation for'),
});