Skip to content

wyc-dev/Uswap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Uswap - a swap cover layer

Uniswap V4 Periphery Contract — High-Performance Swap Mining + Gasless Swap (Final Stable Release – 2025-11-22)
SwapCoverLayer – Uniswap V4 周邊合約 — 高性能 Swap 交易挖礦 + 免 Gas 交易(2025-11-22 終極穩定版)

This contract is a minimal, optimised Uniswap V4 periphery implementation that provides swap-only rewards and a production-grade gasless swap experience on Base.
本合約為極致精簡化、高度優化的 Uniswap V4 周邊合約,專注於 Base 鏈的「純 Swap 獎勵」與「生產級 Gasless Swap」體驗。

Item Value
Type Uniswap V4 IUnlockCallback Periphery (no hooks)
Chain Base Mainnet (Chain ID: 8453)
PoolManager Address 0x7F4B8A79d8f8aC14E8A7B7d6A3E6715cE1d042F3
Version v2.1.0 (maxRewardPerAction removed, ultimate minimalism)

Overview(概覽)

SwapCoverLayer is a purpose-built periphery contract for Uniswap V4 that: 專為 Uniswap V4 打造的中繼合約,具備以下特性:

  • Rewards only swaps — liquidity addition/removal receives zero rewards (eliminates farming bots)
    僅對 Swap 發放獎勵 — 加/減流動性永遠 0 獎勵(徹底杜絕刷量機器人)

  • Rewards are calculated purely from stablecoin USD value 獎勵完全基於穩定幣美元價值計算

  • Gasless swaps with automatic fee burning based on USD volume (default 1%, owner-adjustable)
    手續費自動按 USD 交易量百分比燒毀(預設 1%,owner 可調整)

  • Gasless swaps require stablecoin involvement — transactions without stablecoins revert early, guaranteeing relayers never lose gas
    必須涉及穩定幣 — 無穩定幣交易直接 revert,確保 relayer 永不虧 gas

  • Anyone can call initializePool (fully permissionless pool creation)
    任何人都可呼叫 initializePool(完全無許可開池)

  • No hooks allowed (enforced at initialisation)
    強制禁止 Hook(開池時檢查)

  • All logic executes atomically in unlockCallback — maximum security & MEV resistance
    所有邏輯在 unlockCallback 原子執行 — 最高安全性與 MEV 抵抗性

Parameters(參數)

Parameter Default Description 說明
swapRewardRate 1000 Reward rate denominator (1000 = 0.1%, 100 USDT → 0.1 tokens) Swap 獎勵分母 (1000 = 0.1%)
gaslessFeeRate 100 Gasless swap fee rate (100 = 1%, burned) Gasless 手續費率 (100 = 1%,直接燒毀)
fixedReward 0 Optional fixed reward per swap (default pure percentage mode) 固定獎勵(預設純百分比模式)
rewardEnabled false Must be manually enabled after deployment 部署後需手動開啟

Stablecoins (Can add other stablecoin soon, up-to-date as of 2025-11-22):
穩定幣(可後期增加其他認可穩定幣,2025-11-22 最新確認):

USDC on Base (Circle native): 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
USDT on Base (bridged, highest liquidity): 0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2

Integration Guide(整合指南)

Standard Swap (with rewards)(普通 Swap,帶獎勵)

contract.swap(poolKey, swapParams, "0x");

Gasless Swap — Production-Ready TypeScript Signing Code (ethers v6)(Gasless Swap — 生產級 TypeScript 簽名程式碼)

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://mainnet.base.org");
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider); // 推薦使用 WalletConnect
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider);

async function signGaslessSwap(
  key: {
    currency0: string;
    currency1: string;
    fee: number;
    tickSpacing: number;
    hooks: string;
  },
  swapParams: {
    zeroForOne: boolean;
    amountSpecified: bigint;
    sqrtPriceLimitX96: bigint;
  },
  hookData: string = "0x",
  deadline: number = Math.floor(Date.now() / 1000) + 1200
) {
  const feeRate = await contract.gaslessFeeRate();           // 強制讀取最新值
  const chainId = (await provider.getNetwork()).chainId;

  const domain = {
    name: "SwapCoverLayer",
    version: "1",
    chainId: chainId,
    verifyingContract: contract.target as string            // 必須包含
  };

  const types = {
    PoolKey: [
      { name: "currency0", type: "address" },
      { name: "currency1", type: "address" },
      { name: "fee", type: "uint24" },
      { name: "tickSpacing", type: "int24" },
      { name: "hooks", type: "address" }
    ],
    SwapParams: [
      { name: "bool" },
      { name: "amountSpecified", type: "int256" },
      { name: "sqrtPriceLimitX96", type: "uint160" }
    ],
    Swap: [
      { name: "caller", type: "address" },
      { name: "key", type: "PoolKey" },
      { name: "params", type: "SwapParams" },
      { name: "hookData", type: "bytes" },
      { name: "feeRate", type: "uint256" },
      { name: "deadline", type: "uint256" }
    ]
  };

  const message = {
    caller: wallet.address,
    key,
    params: swapParams,
    hookData,
    feeRate,
    deadline
  };

  const signature = await wallet.signTypedData(domain, types, message);
  const { v, r, s } = ethers.Signature.from(signature);

  return { caller: wallet.address, key, swapParams, hookData, deadline, v, r, s };
}

Relayer Zero-Risk Execution(Relayer 零風險執行策略)

try {
  await contract.callStatic.executeGaslessSwap(params);  // 先模擬
  await contract.executeGaslessSwap(params);             // 成功才上鏈
} catch (e) {
  if (e.message.includes("NoStablecoinInvolved")) {
    // 直接丟棄,永不虧 gas
  }
}

Post-Deployment Steps(部署後必要操作)

1. updateRewardToken(YOUR_REWARD_TOKEN_ADDRESS)
2. setRewardEnabled(true)
3. (Optional) setRewardRates(newGaslessFeeRate, newSwapRewardRate, newFixedReward)

Gas Benchmarks (Base Mainnet, 2025-22)

Operation Gas Used Notes
Standard Swap ~185k +~45k vs native V4 swap
Gasless Swap ~230k Extremely low relayer cost

Security & Audit Status

  • All critical logic executes in unlockCallback with strict msg.sender == poolManager check
    所有關鍵邏輯在 unlockCallback 中原子執行,嚴格檢查 msg.sender

  • EIP-712 signatures include current gaslessFeeRate (replay protection)
    簽名包含當前 feeRate,完美防重放

  • No hooks permitted · ReentrancyGuard · immutable PoolManager
    禁止 Hook · 重入防護 · PoolManager immutable

This is currently the most refined, secure, and performant swap-mining periphery contract in the entire Uniswap V4 ecosystem.
這是目前整個 Uniswap V4 生態中最純粹、最安全、最高效的 Swap 交易挖礦周邊合約。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published