Skip to main content
The @zkp2p/contracts-v2/constants module provides network-specific protocol parameters and configuration values.

Import Constants

Import constants for a specific network:
import { 
  USDC,
  INTENT_EXPIRATION_PERIOD,
  MAX_INTENTS_PER_DEPOSIT,
  PROTOCOL_TAKER_FEE,
  ESCROW_DUST_THRESHOLD
} from '@zkp2p/contracts-v2/constants/base';

console.log('USDC Address:', USDC);
console.log('Intent Expiration:', INTENT_EXPIRATION_PERIOD, 'seconds');

Network-Specific Constants

Constants vary by network:
import * as baseConstants from '@zkp2p/contracts-v2/constants/base';

console.log('USDC:', baseConstants.USDC);
console.log('Intent Expiration:', baseConstants.INTENT_EXPIRATION_PERIOD);
console.log('Taker Fee:', baseConstants.PROTOCOL_TAKER_FEE);

Available Constants

Token Addresses

USDC
string
Address of the USDC token contract on the network
import { USDC } from '@zkp2p/contracts-v2/constants/base';
// "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"

Protocol Parameters

INTENT_EXPIRATION_PERIOD
string
Time in seconds before an intent expires
import { INTENT_EXPIRATION_PERIOD } from '@zkp2p/contracts-v2/constants/base';
// "3600" (1 hour)
MAX_INTENTS_PER_DEPOSIT
number
Maximum number of intents allowed per deposit
import { MAX_INTENTS_PER_DEPOSIT } from '@zkp2p/contracts-v2/constants/base';
// 5
PROTOCOL_TAKER_FEE
string
Protocol fee charged to takers (in basis points)
import { PROTOCOL_TAKER_FEE } from '@zkp2p/constants/base';
// "50" (0.5%)
ESCROW_DUST_THRESHOLD
string
Minimum amount threshold for escrow dust collection
import { ESCROW_DUST_THRESHOLD } from '@zkp2p/contracts-v2/constants/base';
// "1000000" (1 USDC, 6 decimals)

Admin Addresses

MULTI_SIG
string
Address of the protocol multisig wallet
import { MULTI_SIG } from '@zkp2p/contracts-v2/constants/base';
PROTOCOL_TAKER_FEE_RECIPIENT
string
Address that receives protocol taker fees
import { PROTOCOL_TAKER_FEE_RECIPIENT } from '@zkp2p/contracts-v2/constants/base';
ESCROW_DUST_RECIPIENT
string
Address that receives dust from escrow contract
import { ESCROW_DUST_RECIPIENT } from '@zkp2p/contracts-v2/constants/base';

Verifier Addresses

WITNESS_ADDRESS
string
Address of the witness service for off-chain verification
import { WITNESS_ADDRESS } from '@zkp2p/contracts-v2/constants/base';
ZKTLS_ATTESTOR_ADDRESS
string
Address of the zkTLS attestor service
import { ZKTLS_ATTESTOR_ADDRESS } from '@zkp2p/contracts-v2/constants/base';

Using Constants in Your Code

Calculate Fees

import { ethers } from 'ethers';
import { PROTOCOL_TAKER_FEE } from '@zkp2p/contracts-v2/constants/base';

function calculateTakerFee(amount: bigint): bigint {
  const feeBps = BigInt(PROTOCOL_TAKER_FEE);
  return (amount * feeBps) / 10000n;
}

const orderAmount = ethers.utils.parseUnits('100', 6); // 100 USDC
const fee = calculateTakerFee(BigInt(orderAmount.toString()));

console.log('Fee:', ethers.utils.formatUnits(fee, 6), 'USDC');
// Fee: 0.5 USDC

Check Intent Expiration

import { INTENT_EXPIRATION_PERIOD } from '@zkp2p/contracts-v2/constants/base';

function isIntentExpired(intentTimestamp: number): boolean {
  const expirationPeriod = parseInt(INTENT_EXPIRATION_PERIOD);
  const now = Math.floor(Date.now() / 1000);
  return now > intentTimestamp + expirationPeriod;
}

const intentCreatedAt = 1709568000; // Unix timestamp
const expired = isIntentExpired(intentCreatedAt);

Validate Deposit Intent Count

import { MAX_INTENTS_PER_DEPOSIT } from '@zkp2p/contracts-v2/constants/base';

function canAddIntent(currentIntentCount: number): boolean {
  return currentIntentCount < MAX_INTENTS_PER_DEPOSIT;
}

const currentIntents = 3;
if (canAddIntent(currentIntents)) {
  console.log('Can signal another intent');
}

Import All Constants

Import all constants as a single object:
import * as constants from '@zkp2p/contracts-v2/constants/base';

console.log('All constants:', constants);

// Access individual constants
const usdcAddress = constants.USDC;
const intentExpiration = constants.INTENT_EXPIRATION_PERIOD;

Direct JSON Import

For bundle size optimization:
import baseConstants from '@zkp2p/contracts-v2/constants/base.json';

console.log(baseConstants.USDC);
console.log(baseConstants.INTENT_EXPIRATION_PERIOD);

Type Definitions

Constants are strongly typed:
interface Constants {
  USDC?: `0x${string}`;
  INTENT_EXPIRATION_PERIOD?: string;
  MAX_INTENTS_PER_DEPOSIT?: number;
  PROTOCOL_TAKER_FEE?: string;
  PROTOCOL_TAKER_FEE_RECIPIENT?: string;
  ESCROW_DUST_RECIPIENT?: string;
  ESCROW_DUST_THRESHOLD?: string;
  MULTI_SIG?: string;
  WITNESS_ADDRESS?: string;
  ZKTLS_ATTESTOR_ADDRESS?: string;
}

Next Steps

Payment Methods

Work with payment method configurations

Utilities

Use protocol utility functions

Build docs developers (and LLMs) love