Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
IkigaiLabsETH committed Dec 21, 2024
1 parent 15e1ca0 commit f2c5dec
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1914,3 +1914,10 @@ export function getShareableCollectionLink(
const url = getCollectionViewUrl(address, options);
return `View this NFT collection on IkigaiLabs: ${url}`;
}

// Set of curated collection addresses (lowercase)
export const curatedCollections = new Set<string>([
// Add your curated collection addresses here
// Example:
// "0x1234...".toLowerCase(),
]);
21 changes: 13 additions & 8 deletions packages/plugin-nft-collections/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { ReservoirService } from "./services/reservoir";
import { MarketIntelligenceService } from "./services/market-intelligence";
import { SocialAnalyticsService } from "./services/social-analytics";
import { CacheManager } from "./services/cache-manager";
import { MemoryCacheManager } from "./services/cache-manager";
import { RateLimiter } from "./services/rate-limiter";
import { SecurityManager } from "./services/security-manager";
import { nftCollectionProvider } from "./providers/nft-collections";
Expand All @@ -27,6 +27,9 @@ interface NFTCollectionsPluginConfig {
windowMs?: number;
};
};
maxConcurrent?: number;
maxRetries?: number;
batchSize?: number;
}

interface ExtendedCharacter extends Character {
Expand All @@ -43,7 +46,7 @@ export class NFTCollectionsPlugin implements Plugin {
private reservoirService?: ReservoirService;
private marketIntelligenceService?: MarketIntelligenceService;
private socialAnalyticsService?: SocialAnalyticsService;
private cacheManager?: CacheManager;
private cacheManager?: MemoryCacheManager;
private rateLimiter?: RateLimiter;
private securityManager?: SecurityManager;

Expand All @@ -54,10 +57,9 @@ export class NFTCollectionsPlugin implements Plugin {
private initializeServices(): void {
// Initialize caching if enabled
if (this.config.caching?.enabled) {
this.cacheManager = new CacheManager({
ttl: this.config.caching.ttl || 3600000, // 1 hour default
maxSize: this.config.caching.maxSize || 1000,
});
this.cacheManager = new MemoryCacheManager(
this.config.caching.ttl || 3600000 // 1 hour default
);
}

// Initialize rate limiter if enabled
Expand All @@ -82,15 +84,18 @@ export class NFTCollectionsPlugin implements Plugin {
throw new Error("RESERVOIR_API_KEY is required");
}

// Initialize Reservoir service
// Initialize Reservoir service with enhanced configuration
this.reservoirService = new ReservoirService(reservoirApiKey, {
cacheManager: this.cacheManager,
rateLimiter: this.rateLimiter,
maxConcurrent: this.config.maxConcurrent,
maxRetries: this.config.maxRetries,
batchSize: this.config.batchSize,
});
await this.reservoirService.initialize(character.runtime);
await character.runtime.registerService(this.reservoirService);

// Initialize optional services
// Initialize optional services with enhanced configuration
const marketApiKeys = {
nansen: character.settings.secrets?.NANSEN_API_KEY,
dune: character.settings.secrets?.DUNE_API_KEY,
Expand Down
54 changes: 17 additions & 37 deletions packages/plugin-nft-collections/src/services/cache-manager.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
interface CacheConfig {
ttl: number;
maxSize: number;
export interface CacheManager {
get<T>(key: string): Promise<T | null>;
set<T>(key: string, value: T, ttl?: number): Promise<void>;
clear(): Promise<void>;
}

interface CacheEntry<T> {
data: T;
timestamp: number;
}

export class CacheManager {
private cache: Map<string, CacheEntry<any>>;
private config: CacheConfig;
export class MemoryCacheManager implements CacheManager {
private cache: Map<string, { value: any; expiry: number }>;
private defaultTtl: number;

constructor(config: CacheConfig) {
this.config = config;
constructor(defaultTtl: number = 3600000) {
// 1 hour default
this.cache = new Map();
this.defaultTtl = defaultTtl;
}

async get<T>(key: string): Promise<T | null> {
const entry = this.cache.get(key);
if (!entry) return null;
const item = this.cache.get(key);
if (!item) return null;

// Check if entry has expired
if (Date.now() - entry.timestamp > this.config.ttl) {
if (Date.now() > item.expiry) {
this.cache.delete(key);
return null;
}

return entry.data;
}

async set<T>(key: string, data: T): Promise<void> {
// Implement LRU eviction if cache is full
if (this.cache.size >= this.config.maxSize) {
const oldestKey = this.cache.keys().next().value;
this.cache.delete(oldestKey);
}

this.cache.set(key, {
data,
timestamp: Date.now(),
});
return item.value as T;
}

async delete(key: string): Promise<void> {
this.cache.delete(key);
async set<T>(key: string, value: T, ttl?: number): Promise<void> {
const expiry = Date.now() + (ttl || this.defaultTtl);
this.cache.set(key, { value, expiry });
}

async clear(): Promise<void> {
this.cache.clear();
}

async has(key: string): Promise<boolean> {
return this.cache.has(key);
}
}
Loading

0 comments on commit f2c5dec

Please sign in to comment.