Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Nov 18, 2024
1 parent 83606d0 commit 8d3d948
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
40 changes: 29 additions & 11 deletions src/app/utils/account-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
Transaction,
} from "../lib/fastnear";
import { runLLMInference } from "../lib/open-ai";
import { analyzeInteractionPatterns, analyzeSignificantContracts, ContractMetadata, InteractionPattern } from "./ecosystem-analysis";
import {
analyzeInteractionPatterns,
analyzeSignificantContracts,
ContractMetadata,
InteractionPattern,
} from "./ecosystem-analysis";

interface AccountSummaryData {
account_id: string;
Expand All @@ -34,8 +39,15 @@ interface AccountSummaryData {
uniqueInteractions: string[];
};
analysis: {
significantContracts: Array<{contract: string; metadata: ContractMetadata; frequency: number}>;
interactionPatterns: Array<{pattern: InteractionPattern; matchCount: number}>;
significantContracts: Array<{
contract: string;
metadata: ContractMetadata;
frequency: number;
}>;
interactionPatterns: Array<{
pattern: InteractionPattern;
matchCount: number;
}>;
};
staking: {
pools: string[];
Expand Down Expand Up @@ -101,11 +113,11 @@ function processAccountData(
activity: {
totalTransactions: allActivity.txs_count || 0,
recentTransactions,
uniqueInteractions
uniqueInteractions,
},
analysis: {
significantContracts,
interactionPatterns
interactionPatterns,
},
staking: {
pools: details.pools.map((pool) => pool.pool_id),
Expand All @@ -129,12 +141,18 @@ BEHAVIOR_PATTERNS:
- Unique contacts: ${data.activity.uniqueInteractions.length}
DEGEN_ANALYSIS:
- Key contracts: ${data.analysis.significantContracts.map(c =>
`${c.contract} (${c.metadata.name}): ${c.frequency} interactions - ${c.metadata.description}`
).join("\n")}
- Behavior patterns: ${data.analysis.interactionPatterns.map(p =>
`${p.pattern.name}: ${p.matchCount} matches - ${p.pattern.description}`
).join("\n")}
- Key contracts: ${data.analysis.significantContracts
.map(
(c) =>
`${c.contract} (${c.metadata.name}): ${c.frequency} interactions - ${c.metadata.description}`,
)
.join("\n")}
- Behavior patterns: ${data.analysis.interactionPatterns
.map(
(p) =>
`${p.pattern.name}: ${p.matchCount} matches - ${p.pattern.description}`,
)
.join("\n")}
ECOSYSTEM_ROLE:
- Active staking pools: ${data.staking.pools.join(", ")}
Expand Down
54 changes: 27 additions & 27 deletions src/app/utils/ecosystem-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Transaction } from "../lib/fastnear";

export interface ContractMetadata {
name: string;
category: 'defi' | 'nft' | 'gaming' | 'dao' | 'meme' | 'stablecoin' | 'scam';
risk: 'safe' | 'medium' | 'degen' | 'mega-degen';
category: "defi" | "nft" | "gaming" | "dao" | "meme" | "stablecoin" | "scam";
risk: "safe" | "medium" | "degen" | "mega-degen";
description: string;
}

export interface InteractionPattern {
pattern: string[];
pattern: string[];
name: string;
category: 'trader' | 'farmer' | 'gambler' | 'collector' | 'bot' | 'whale';
category: "trader" | "farmer" | "gambler" | "collector" | "bot" | "whale";
description: string;
}

Expand All @@ -19,19 +19,19 @@ const SIGNIFICANT_CONTRACTS: Record<string, ContractMetadata> = {
name: "Ref Finance",
category: "defi",
risk: "medium",
description: "Popular DEX, probably degen trading"
description: "Popular DEX, probably degen trading",
},
"nf-treasury.near": {
name: "NEAR Foundation Treasury",
category: "dao",
risk: "safe",
description: "Illuminati confirmed"
description: "Illuminati confirmed",
},
"wrap.near": {
name: "wNEAR",
category: "defi",
risk: "safe",
description: "Wrapped NEAR, basic DeFi user"
description: "Wrapped NEAR, basic DeFi user",
},
// what else???
};
Expand All @@ -41,56 +41,56 @@ const INTERACTION_PATTERNS: InteractionPattern[] = [
pattern: ["v2.ref-finance.near", "wrap.near"],
name: "DeFi Degen",
category: "trader",
description: "Loves losing money on DEXes"
description: "Loves losing money on DEXes",
},
{
pattern: ["aurora", "rainbow-bridge.near"],
name: "Bridge Explorer",
category: "gambler",
description: "Can't decide which chain to lose money on"
description: "Can't decide which chain to lose money on",
},
// what else...
];

export function analyzeSignificantContracts(
transactions: Transaction[],
contracts = SIGNIFICANT_CONTRACTS
): Array<{contract: string; metadata: ContractMetadata; frequency: number}> {
contracts = SIGNIFICANT_CONTRACTS,
): Array<{ contract: string; metadata: ContractMetadata; frequency: number }> {
const contractCounts = new Map<string, number>();

// Count interactions with significant contracts
transactions.forEach(tx => {
transactions.forEach((tx) => {
if (contracts[tx.signer_id]) {
contractCounts.set(
tx.signer_id,
(contractCounts.get(tx.signer_id) || 0) + 1
tx.signer_id,
(contractCounts.get(tx.signer_id) || 0) + 1,
);
}
});

// Convert to array and sort by frequency
return Array.from(contractCounts.entries())
.map(([contract, frequency]) => ({
contract,
metadata: contracts[contract],
frequency
frequency,
}))
.sort((a, b) => b.frequency - a.frequency);
}

export function analyzeInteractionPatterns(
transactions: Transaction[],
patterns = INTERACTION_PATTERNS
): Array<{pattern: InteractionPattern; matchCount: number}> {
patterns = INTERACTION_PATTERNS,
): Array<{ pattern: InteractionPattern; matchCount: number }> {
return patterns
.map(pattern => ({
.map((pattern) => ({
pattern,
matchCount: transactions.filter(tx =>
pattern.pattern.some(p =>
tx.signer_id.includes(p) || tx.signer_id.includes(p)
)
).length
matchCount: transactions.filter((tx) =>
pattern.pattern.some(
(p) => tx.signer_id.includes(p) || tx.signer_id.includes(p),
),
).length,
}))
.filter(result => result.matchCount > 0)
.filter((result) => result.matchCount > 0)
.sort((a, b) => b.matchCount - a.matchCount);
}
}

0 comments on commit 8d3d948

Please sign in to comment.