Karma Swap

Karma Swap: A Uniswap v4 hook that uses a cross-chain "credit score" to reward good traders.

Karma Swap

Created At

ETHGlobal New Delhi

Project Description

The Problem: An Anonymous and Unfair System

In today's DeFi landscape, there is a fundamental crisis of trust. Every wallet is treated as a blank slate, with no way to distinguish a long-term, positive-sum actor from a malicious one. Imagine a financial system where everyone had the same credit score—it would be chaos. That is the reality in DeFi today.

This creates two critical issues:

Risk for Liquidity Providers: During market turbulence, LPs are exposed to significant impermanent loss, and the static fees they earn often fail to compensate for this risk.

Unfairness for Users: A DeFi veteran with years of positive on-chain history is treated exactly the same as a brand-new wallet funded for a potential MEV exploit or rug pull. Good behavior is not rewarded.

The Solution: Karma Swap - A Trust Layer for DeFi

Karma Swap solves this by introducing DeFi's first cross-chain credit score, built directly into the heart of the ecosystem as a Uniswap v4 hook.

Our project fundamentally changes how trade fees are calculated. Instead of a one-size-fits-all model, Karma Swap implements a hybrid dynamic fee based on two key pillars:

The Karma Score: A comprehensive, cross-chain reputation score calculated by analyzing a wallet's entire history—their trading volume, governance participation, liquidation events, and known associations with illicit activities.

Market Volatility: A real-time data feed that adjusts the base fee to protect liquidity providers from impermanent loss during turbulent periods.

The result is a fee mechanism that is both market-aware and user-aware.

How It Works: The Hybrid Fee Engine

The final fee a user pays is a simple but powerful formula:

Final Fee = (Volatility-Adjusted Base Fee) - Karma Discount

This creates a fairer and safer trading environment where everyone gets a rate tailored to them and the current market.

User Profile Karma Swap Experience DeFi Veteran A high Karma Score grants them a significant fee discount, rewarding them for their positive contributions. New User Starts with a neutral score and fair, volatility-adjusted fees, with a clear incentive to build a positive reputation. Known Malicious Actor A negative Karma Score results in higher fees protecting the pool and its honest users.

How it's Made

Karma Swap is a full-stack dApp built around a hybrid on-chain/off-chain architecture, all orchestrated by a custom Uniswap v4 hook to create a two-factor dynamic fee.

On-Chain Architecture The core logic is a modular set of Solidity smart contracts developed with Foundry.

A central Hook Contract inherits from the official BaseHook and is deployed via CREATE2 to acquire the necessary beforeSwap permission flags. It acts as the on-chain orchestrator.

For security, it performs on-chain cryptographic signature verification (ecrecover on tx.origin) to validate a user's reputation score, which is passed in as hookData.

The hook coordinates with two satellite contracts: a Volatility Oracle for live market data and a separate Fee Calculator for the core fee algorithm, making the system modular and gas-efficient.

Off-Chain Services The hook is powered by two off-chain TypeScript services:

A live volatility pipeline sources data from a high-volume Ethereum Mainnet pool for accuracy and pushes it to our VolatilityOracle on the Sepolia testnet.

A reputation engine (simulated for the hackathon) calculates a user's "Karma Score" and provides a secure, signed attestation for the dApp to use.

User Interaction & Frontend The user-facing layer is designed for security and a professional user experience.

The React frontend uses RainbowKit and Wagmi for seamless multi-wallet support.

Crucially, all swaps are routed through the official Uniswap Universal Router, adhering to V4's core security pattern. The dApp constructs the router's execute command, packing our custom signed reputation data into the hookData field.

background image mobile

Join the mailing list

Get the latest news and updates