WDK logoWDK documentation

API Reference

API Reference for @tetherto/wdk-protocol-swap-velora-evm

Class: VeloraProtocolEvm

Main class for velora token swaps on EVM.

Constructor

new VeloraProtocolEvm(account, config?)

Parameters:

  • account: IWalletAccount | IWalletAccountReadOnly from @tetherto/wdk-wallet
  • config (optional):
    • swapMaxFee (bigint): maximum total gas fee allowed (wei)

The beta.7 declarations accept the generic wallet interfaces, but this package still requires an EVM-compatible account with a configured JSON-RPC URL or EIP-1193 provider. Use an EVM account from WDK's EVM wallet modules; the wider interfaces do not add support for arbitrary or non-EVM accounts.

Example:

const swap = new VeloraProtocolEvm(account, { swapMaxFee: 200000000000000n })

Methods

MethodDescriptionReturns
swap(options, config?)Perform a token swapPromise<{hash: string, fee: bigint, tokenInAmount: bigint, tokenOutAmount: bigint}>
quoteSwap(options, config?)Get estimated fee and amountsPromise<{fee: bigint, tokenInAmount: bigint, tokenOutAmount: bigint}>

swap(options, config?)

Execute a swap via velora.

Options:

  • tokenIn (string): Address of the ERC‑20 token to sell
  • tokenOut (string): Address of the ERC‑20 token to buy
  • tokenInAmount (bigint, optional): Exact input amount (base units)
  • tokenOutAmount (bigint, optional): Exact output amount (base units)
  • to (string, optional): Recipient address (defaults to account address)

Config (ERC‑4337 only):

  • paymasterToken ({ address: string }, optional): Paymaster token override for this swap
  • isSponsored (true, optional): Use sponsorship mode for this swap
  • sponsorshipPolicyId (string, optional): Sponsorship policy override
  • useNativeCoins (true, optional): Pay fees in the chain's native token
  • swapMaxFee (bigint, optional): Per‑swap fee cap (wei)

These per-swap overrides are applied only when the protocol uses a concrete WalletAccountEvmErc4337. With another writable EVM account, swap() sends one EVM transaction and does not apply the ERC‑4337 config object.

Returns:

  • Standard account: { hash, fee, tokenInAmount, tokenOutAmount }
  • ERC‑4337 account: { hash, fee, tokenInAmount, tokenOutAmount }

Notes:

  • Approve the input token with the account's approve() method before swapping if the spender does not already have enough allowance.
  • Requires a provider; requires a non read‑only account to send transactions.

Example:

const tx = await swap.swap({
  tokenIn: '0xdAC17F...ec7',      // USDt
  tokenOut: '0xC02a...6Cc2',      // WETH
  tokenInAmount: 1000000n
})

quoteSwap(options, config?)

Get estimated fee and token in/out amounts.

Options are the same as swap.

Returns: { fee, tokenInAmount, tokenOutAmount }

Config (ERC‑4337 only):

  • paymasterToken ({ address: string }, optional): Paymaster token override for fee estimation
  • isSponsored (true, optional): Use sponsorship mode for fee estimation
  • sponsorshipPolicyId (string, optional): Sponsorship policy override
  • useNativeCoins (true, optional): Estimate fees in the chain's native token

These per-call overrides are applied only when the protocol uses a concrete WalletAccountReadOnlyEvmErc4337. Other accounts use the ordinary single-transaction quote path and do not apply the ERC‑4337 config object.

Works with read‑only accounts.

Example:

const quote = await swap.quoteSwap({
  tokenIn: '0xdAC17F...ec7',      // USDt
  tokenOut: '0xC02a...6Cc2',      // WETH
  tokenOutAmount: 500000000000000000n // 0.5 WETH
})

Errors

Common errors include:

  • Insufficient liquidity / no route for pair
  • Fee exceeds swapMaxFee
  • Read‑only account cannot send swaps
  • Provider/RPC errors (invalid endpoint, network mismatch)

Types

  • swapMaxFee: bigint — Upper bound for gas fees (wei)
  • tokenInAmount/tokenOutAmount: bigint — ERC‑20 base units
  • paymasterToken: { address: string } — ERC‑4337 paymaster token override

Need Help?

On this page