Documentation
¶
Overview ¶
Package permit2 packs Uniswap Permit2 EIP-712 typed data and contract calldata. Permit2 (https://github.com/Uniswap/permit2) is a canonical Permit2 singleton (0x000000000022D473030F116dDEE9F6B43aC78BA3 on every mainnet EVM chain) that lets a user approve a token ONCE for the Permit2 contract, then sign per-trade permit messages that let any downstream router transfer the exact amount without a fresh on-chain approval. Bungee's intent-mode swaps and every other aggregator that lists Permit2 as the approval target use these messages.
This package produces:
- The static ABI for the small subset of Permit2 functions wallets touch (approve, permit, permitTransferFrom).
- The EIP-712 domain + typed-data structs the FE feeds to `eth_signTypedData_v4`. Two flavours: PermitTransferFrom — single token, single transfer PermitBatchTransferFrom — many tokens per signature (permitWitnessTransferFrom variants live upstream but aren't used by the current aggregators we integrate; add here when someone needs one.)
Signing itself stays in signing/evm/eip712.go — this package only produces the typed-data payload; the caller feeds it to the signer.
Index ¶
Constants ¶
const ABI = `` /* 1270-byte string literal not displayed */
ABI is the minimal Permit2 interface — approve() for the initial unlimited allowance the user grants once per token, and the two permitTransferFrom variants for downstream routers to consume a signature. Extend as call-sites need more.
const Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3"
Address is Uniswap Permit2's canonical deployment. Same on every chain by design (deterministic CREATE2 with a fixed salt). If you're on a chain where Permit2 isn't deployed, the sig is useless — check first.
const DomainName = "Permit2"
DomainName is the EIP-712 domain name string Permit2 uses. Ties the signature to the intended verifier.
Variables ¶
This section is empty.
Functions ¶
func MarshalTypedData ¶
MarshalTypedData is a shortcut for callers that just want the JSON string the FE will feed to signTypedData.
Types ¶
type PermitBatchTransferFrom ¶
type PermitBatchTransferFrom struct {
Permitted []TokenPermissions `json:"permitted"`
Spender string `json:"spender"`
Nonce string `json:"nonce"`
Deadline string `json:"deadline"`
}
PermitBatchTransferFrom is the many-token variant. Same domain, different type name so the signature can't be replayed against the single-token verifier.
type PermitTransferFrom ¶
type PermitTransferFrom struct {
Permitted TokenPermissions `json:"permitted"`
// Spender is the router that will call permitTransferFrom on
// behalf of the signer. Not in the ISignatureTransfer struct
// but required in the EIP-712 typed data so the signature is
// bound to who can spend it.
Spender string `json:"spender"`
Nonce string `json:"nonce"`
Deadline string `json:"deadline"`
}
PermitTransferFrom is the single-token permit payload the user signs via eth_signTypedData_v4. Domain + Types + Message combine into the typed-data envelope MetaMask / walletconnect eat.
type TokenPermissions ¶
TokenPermissions is the (token, amount) pair inside a Permit2 signature. Amount is uint256 wire-side; keep as decimal string so the wire form is JSON-friendly.
type TypedData ¶
type TypedData struct {
Types map[string][]TypedField `json:"types"`
PrimaryType string `json:"primaryType"`
Domain Domain `json:"domain"`
Message map[string]interface{} `json:"message"`
}
TypedData is the eth_signTypedData_v4 envelope the wallet signs. Kept as generic map[string]interface{} shapes so the caller can json.Marshal + feed straight to signTypedData — no bespoke encoder to keep in sync with the wallet-side one.
func BuildPermitBatchTransferFrom ¶
func BuildPermitBatchTransferFrom(chainId int64, p PermitBatchTransferFrom) (*TypedData, error)
BuildPermitBatchTransferFrom is the many-token twin. Every TokenPermissions entry goes into a fresh sub-object.
func BuildPermitTransferFrom ¶
func BuildPermitTransferFrom(chainId int64, p PermitTransferFrom) (*TypedData, error)
BuildPermitTransferFrom produces the typed-data envelope for a single-token Permit2 permit on the given chain. Amount / nonce / deadline stay as decimal strings so callers don't have to preserve big.Int on the wire.
Returns the JSON-ready shape. Marshal it with encoding/json and hand it to the FE's eth_signTypedData_v4.