Permit2 sdk

From cyotee/indexedex · View interactive version

Permit2 sdk is an AI agent skill from the GitHub repository cyotee/indexedex. Uniswap Permit2 SDK for gasless token transfers in IndexedEx. Use when implementing swap/deposit/withdraw with signature-based or allowance-based authorization.

How to use this skill

Skill file

Permit2 SDK for IndexedEx

Comprehensive guide for using Permit2 in the frontend for vault operations.

Quick Start

import { PERMIT2_ADDRESS, SignatureTransfer } from '@uniswap/permit2-sdk'

Two Patterns

1. Signature Transfer (Recommended)

Gasless, no pre-approval needed beyond initial Permit2 allowance.

2. Allowance Transfer

Persistent approvals - user approves once, protocol spends repeatedly.

Exchange Types (Witness Context)

| Exchange | Selector | Witness Data |

|----------|----------|--------------|

| exchangeIn | 0x89d61912 | tokenIn, tokenOut, vault, amountIn |

| exchangeOut | 0x612d4427 | tokenIn, tokenOut, vault, amountOut, maxAmountIn |

| swapSingleTokenExactOut | (Balancer) | pool, tokenIn, tokenOut, amountOut |

Key Topics

Example: Swap with Witness

// Witness binds signature to this exact swap
const witness = {
  actionId: keccak256(encodePacked(
    ['address', 'address', 'address', 'uint256'],
    [tokenIn, tokenOut, vaultAddress, amountIn]
  ))
}

// Get permit data (EIP-712 ready)
const { domain, types, values } = SignatureTransfer.getPermitData(
  permit,           // amount, nonce, deadline
  PERMIT2_ADDRESS,
  chainId,
  { witness, witnessTypeName: 'Witness', witnessType: WITNESS_TYPE }
)

// User signs, then your contract calls Permit2
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.