> For the complete documentation index, see [llms.txt](https://docs.taya.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.taya.fi/about-taya/swap.md).

# Swap

Taya is an automated market maker (AMM), a decentralized exchange (DEX) that allows users to trade assets directly without the need for a traditional order book to match buyers and sellers.

**SwapCraft Function**

At the heart of SwapCraft lies the "swapTokens" function, a powerful mechanism that facilitates token exchanges with ease. Let's delve into its core components:

```solidity
function swapTokens(
    TokenSwap tokenSwapRequest,
    AssetManagement assetRouting,
    uint256 tradeThreshold,
    uint256 swapExpiry
) returns (uint256 tradeResults[In/Out])
```

* `poolIdentifier`: Identifies the pool designated for the swap.
* `tradeType`: Precisely defines the type of trade, allowing for either "Out Given Exact In" or "In Given Exact Out" swaps.
* `inputAsset`: Refers to the asset intended to be swapped into the pool.
* `outputAsset`: Signals the asset to be acquired in exchange.
* `tradeAmount`: Its meaning seamlessly adjusts according to the selected "tradeType":
  1. `GIVEN_IN`: Signifies the amount of assets being dispatched.
  2. `GIVEN_OUT`: Designates the target amount of assets to be received.
* `userSpecificData`: This field serves as a conduit for any supplementary information necessary for the pool to execute the swap, thus facilitating future enhancements in the swapping protocol.

#### **TokenSwap Structure**

A vital cog in the SwapCraft machinery is the "TokenSwap" structure, meticulously outlined as follows:

```solidity
enum ExchangeType { GIVEN_IN, GIVEN_OUT }

struct TokenSwap {
   bytes32 poolIdentifier;
   ExchangeType tradeType;
   IAsset inputAsset;
   IAsset outputAsset;
   uint256 tradeAmount;
   bytes userSpecificData;
}
```

**AssetManagement Structure**

The "AssetManagement" structure plays a pivotal role in determining the flow of input and output assets. It takes the following form:

```solidity
struct AssetManagement {
    address senderAddress;
    bool sourceFromInternalStorage;
    address payable receiverAddress;
    bool sendToInternalStorage;
}
```

* `senderAddress`: Specifies the address from which assets will be sourced for the swap.
* `sourceFromInternalStorage`: Dictates whether the assets should be drawn from the sender's pre-existing holdings within the Vault.
* Taya's bespoke swap function tailored to our unique pool types, fortified with the robust technology inherited from the Balancer swap module.

{% hint style="info" %}
Tayaswap's bespoke swap function tailored to our unique pool types, fortified with the robust technology inherited from the [Balancer](https://docs.balancer.fi/concepts/vault/swaps.html) swap module.
{% endhint %}
