@cowprotocol/sdk-common
Common utilities and types for CoW Protocol SDK
The @cowprotocol/sdk-common package provides shared utilities, types, and helper functions used across the CoW Protocol SDK.
Installation
Address Utilities
Type Definitions
isEvmAddress
Validates if a string is a valid EVM address.
Parameters:
address - The address string to validate
Returns: Type guard indicating if the address is a valid EVM address
Example:
isBtcAddress
Validates if a string is a valid Bitcoin address (supports legacy P2PKH/P2SH and Bech32 formats).
Parameters:
address - The address string to validate
Returns: Type guard indicating if the address is a valid Bitcoin address
isSolanaAddress
Validates if a string is a valid Solana address (Base58-encoded Ed25519 public keys).
Parameters:
address - The address string to validate
Returns: Type guard indicating if the address is a valid Solana address
getEvmAddressKey
Normalizes an EVM address to lowercase with 0x prefix.
Example:
getAddressKey
Gets an address key for any supported blockchain address type.
Parameters:
address - The address to convert to a key
Returns: Normalized address key based on the detected address type
Token Utilities
TokenIdentifier
getTokenId
Generates a unique token identifier from chain ID and address.
Example:
areTokensEqual
Compares two tokens for equality based on chain ID and address.
areAddressesEqual
Compares two addresses for equality, handling different blockchain formats.
isNativeToken
Checks if a token is the native currency for its chain.
isWrappedNativeToken
Checks if a token is the wrapped native currency (e.g., WETH on Ethereum).
Math Utilities
percentageToBps
Converts a percentage to basis points (bps).
Parameters:
percentage - The percentage to convert (e.g., 0.5 for 50%)
Returns: The basis points value (e.g., 5000 for 50%)
Example:
bpsToPercentage
Converts basis points to a percentage.
Parameters:
bps - The basis points value
Returns: The percentage value
applyPercentage
Applies a percentage to a bigint value.
Parameters:
value - The value to apply the percentage to
percentage - The percentage to apply (e.g., 1.1 for 110%)
Returns: The value after applying the percentage
Example:
Logging
enableLogging
Enables or disables SDK logging.
Example:
log
Logs a message if logging is enabled.
Type Utilities
Nullish
Utility type for nullable values.
ABIs
The package exports contract ABIs for CoW Protocol:
GPV2SettlementAbi
ABI for the GPv2 Settlement contract, including:
Trade event
setPreSignature() function
invalidateOrder() function
domainSeparator() function
EthFlowAbi
ABI for ETH flow contracts.
Erc20Abi
Standard ERC20 token ABI.
Common Types
These types provide compatibility across different Ethereum libraries (ethers.js, viem, etc.).Last modified on March 4, 2026