🔧technical documentation

This page provides developer documentation for the most important endpoints of the TenderSwap contract. TenderSwap facilitates trading of validator-specific tTokens using a shared liquidity pool, allowing users to deposit underlying tokens, receive LP tokens, and participate in the protocol's liquidity mechanisms.

Table of Contents

  • Swap

  • Quote

  • Deposit

  • Withdraw

  • Buy Unlock

  • Redeem Unlock

  • Claim Relayer Rewards

  • Events

  • Notes

  • Disclaimer

Swap

swap(address asset, uint256 amount, uint256 minOut) external returns (uint256 out, uint256 fee)

Parameters:

  • asset (address): The address of the tToken to swap

  • amount (uint256): The amount of tTokens to swap

  • minOut (uint256): The minimum amount of underlying tokens expected to receive

Returns:

  • out (uint256): The amount of underlying tokens received

  • fee (uint256): The fee charged for the swap

Description:

  • Transfers the specified tTokens from the user to the contract

  • Calculates the dynamic fee based on pool utilization

  • Creates an unlock position for the swapped tokens

  • Transfers the underlying tokens to the user

Events:

  • Swap(address indexed caller, address indexed asset, uint256 amountIn, uint256 fee, uint256 unlockId)

Errors:

  • ErrorInvalidAsset(address asset): Thrown if the tToken is not supported

  • ErrorSlippage(uint256 out, uint256 minOut): Thrown if the output amount is less than minOut

Quote

quote(address asset, uint256 amount) external view returns (uint256 out, uint256 fee)

Parameters:

  • asset (address): The address of the tToken to swap

  • amount (uint256): The amount of tTokens to swap

Returns:

  • out (uint256): The estimated amount of underlying tokens to receive

  • fee (uint256): The estimated fee for the swap

Description:

  • Simulates a swap to provide price information

  • Calculates fees based on current pool state

  • Does not modify state

Errors:

  • ErrorInvalidAsset(address asset): Thrown if the tToken is not supported

Deposit

deposit(uint256 amount, uint256 minLpShares) external returns (uint256 lpShares)

Parameters:

  • amount (uint256): The amount of underlying tokens to deposit

  • minLpShares (uint256): The minimum amount of LP tokens expected to receive

Returns:

  • lpShares (uint256): The number of LP tokens minted

Description:

  • Transfers underlying tokens from the user to the contract

  • Calculates LP tokens based on pool's current state

  • Mints LP tokens to the user

  • Updates pool liabilities

Events:

  • Deposit(address indexed from, uint256 amount, uint256 lpSharesMinted)

Errors:

  • ErrorSlippage(uint256 shares, uint256 minLpShares): Thrown if LP shares are less than minimum

  • ErrorCalculateLPShares(): Thrown if share calculation fails

Withdraw

withdraw(uint256 amount, uint256 maxLpSharesBurnt) external

Parameters:

  • amount (uint256): The amount of underlying tokens to withdraw

  • maxLpSharesBurnt (uint256): Maximum LP tokens willing to burn

Description:

  • Checks available liquidity

  • Burns LP tokens from user

  • Transfers underlying tokens to user

  • Updates pool liabilities

Events:

  • Withdraw(address indexed to, uint256 amount, uint256 lpSharesBurnt)

Errors:

  • ErrorInsufficientAssets(uint256 requested, uint256 available)

  • ErrorSlippage(uint256 shares, uint256 maxLpSharesBurnt)

[Continue with remaining sections in same format...]

Notes

  • Fee Structure: Implements dynamic fees based on pool utilization with BASE_FEE and variable component

  • Liquidity Management: Uses elastic LP tokens with automatic rebalancing

  • Safety Features: Includes slippage protection and recovery mode

  • Mathematical Precision: Uses UD60x18 for precise calculations

Disclaimer

This documentation provides a high-level overview of TenderSwap's core functionality. Developers should thoroughly review the contract code and conduct comprehensive testing before integration.

Last updated