Building Blocks
Discover and install building blocks to extend your WDK integration.
Discover and install building blocks to extend your WDK integration.
@tetherto/wdk-protocol-swap-velora-evm
DEX aggregator swap on EVM chains
Loading README…
USD₮0 bridging from EVM source chains to EVM and non-EVM destinations
Aave protocol integration for EVM
Ethereum and EVM-compatible chains wallet
Note: This package is currently in beta. Please test thoroughly in development environments before using in production.
A secure and straightforward package that lets EVM wallet accounts swap tokens using the Velora aggregator. This package provides a clean SDK for token swaps on EVM chains, supporting both standard wallets and ERC-4337 smart accounts.
This module can be managed by the @tetherto/wdk suite, which provides a unified interface for managing multiple WDK wallet and protocol modules across different blockchains.
This module is part of the WDK (Wallet Development Kit) project, which enables developers to build secure, non-custodial wallets with unified blockchain access and complete user control.
For documentation on the complete WDK ecosystem, see https://docs.wallet.tether.io.
swapMaxFee to cap gas costsnpm install @tetherto/wdk-protocol-swap-velora-evmimport ParaSwapProtocolEvm from '@tetherto/wdk-protocol-swap-velora-evm'
import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
const seed = 'test only example nut use this real life secret phrase must random'
// Create EVM account (m/44'/60'/0'/0/0)
const account = new WalletAccountEvm(seed, "0'/0/0", {
provider: 'https://ethereum-rpc.publicnode.com'
})
// Create swap protocol
const swap = new ParaSwapProtocolEvm(account, {
swapMaxFee: 200000000000000n // Optional: cap fee
})
// Buy: specify exact output amount
const buyResult = await swap.swap({
tokenIn: '0xTokenIn',
tokenOut: '0xTokenOut',
tokenOutAmount: 1000000n // exact out
})
// Sell: specify exact input amount
const sellResult = await swap.swap({
tokenIn: '0xTokenIn',
tokenOut: '0xTokenOut',
tokenInAmount: 1000000n // exact in
})
// Quote before swap
const quote = await swap.quoteSwap({
tokenIn: '0xTokenIn',
tokenOut: '0xTokenOut',
tokenInAmount: 1000000n
})import ParaSwapProtocolEvm from '@tetherto/wdk-protocol-swap-paraswap-evm'
import { WalletAccountEvmErc4337 } from '@tetherto/wdk-wallet-evm-erc-4337'
const smart = new WalletAccountEvmErc4337(seed, "0'/0/0", {
chainId: 1,
provider: 'https://arb1.arbitrum.io/rpc',
bundlerUrl: 'YOUR_BUNDLER_URL',
paymasterUrl: 'YOUR_PAYMASTER_URL'
})
const swap4337 = new ParaSwapProtocolEvm(smart, {
swapMaxFee: 200000000000000n
})
const result = await swap4337.swap({
tokenIn: '0xTokenIn',
tokenOut: '0xTokenOut',
tokenInAmount: 1000000n
}, {
paymasterToken: 'USDT', // pay gas with token
swapMaxFee: 200000000000000n // override cap
})Main class for ParaSwap token swaps on EVM.
new ParaSwapProtocolEvm(account, config?)Parameters:
account (WalletAccountEvm | WalletAccountEvmErc4337 | WalletAccountReadOnlyEvm | WalletAccountReadOnlyEvmErc4337)config (object, optional):
swapMaxFee (bigint, optional): maximum total gas fee allowedExample:
const swap = new ParaSwapProtocolEvm(account, { swapMaxFee: 200000000000000n })| Method | Description | Returns |
|---|---|---|
swap(options, config?) | Swaps a token pair | Promise<{hash: string, fee: bigint, tokenInAmount: bigint, tokenOutAmount: bigint, approveHash?, resetAllowanceHash?}> |
quoteSwap(options, config?) | Quotes swap fee and amounts | Promise<{fee: bigint, tokenInAmount: bigint, tokenOutAmount: bigint}> |
swap(options, config?)Execute a swap.
Options:
tokenIn (string): address of token to selltokenOut (string): address of token to buytokenInAmount (bigint, optional): exact input amounttokenOutAmount (bigint, optional): exact output amountminAmountOut (number or bigint, optional): minimum acceptable output amount in base unitsto (string, optional): recipient (default: your address)Config (ERC‑4337 only):
paymasterToken (string, optional): token to pay gasswapMaxFee (bigint, optional): override fee capReturns:
{ hash, fee, tokenInAmount, tokenOutAmount, approveHash, resetAllowanceHash? }{ hash, fee, tokenInAmount, tokenOutAmount } (approve bundled)Notes:
minAmountOut, fails before building or sending a transaction.minAmountOut is passed to Velora as the transaction's output floor; when omitted, the quoted output is used. Buys retain the exact requested output. Returned amounts describe the quote.Example:
const tx = await swap.swap({ tokenIn: '0xTokenIn', tokenOut: '0xTokenOut', tokenInAmount: 1000000n })quoteSwap(options, config?)Get swap fee and amounts without sending a transaction.
Options are the same as swap.
Returns: { fee, tokenInAmount, tokenOutAmount }
Config (ERC‑4337 only):
paymasterToken (string, optional): token to pay gasWorks with read-only accounts.
const quote = await swap.quoteSwap({ tokenIn: '0xTokenIn', tokenOut: '0xTokenOut', tokenOutAmount: 500000n })Works on EVM networks supported by ParaSwap. You will need a working RPC provider.
swapMaxFee to prevent high gas costs# Install dependencies
npm install
# Build TypeScript definitions
npm run build:types
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix# Run tests
npm test
# Run tests with coverage
npm run test:coverageThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For support, please open an issue on the GitHub repository.