> For the complete documentation index, see [llms.txt](https://docs.covenant.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.covenant.finance/deprecated/user-app/guild-swaps.md).

# Guild Swaps

In addition to swapping debt tokens (zTokens) and money tokens in Uniswap v3 pools, users can also swap between these pairs using the Guild’s `swapMoneyForZTokens` and `swapZTokensForMoney` functions. The Guild has infinite zToken liquidity, meaning users can always `swapMoneyForZTokens` at the zToken *facePrice*. This is useful if there are not enough zTokens in the Uniswap v3 pool to pay off a user’s debt, if the user needs zTokens for liquidations, or if zToken *marketPrices* are too high (more details on this below). The Guild does not have infinite money tokens, however, so `swapZTokensForMoney` can only be used after users have already executed `swapMoneyForZTokens` and the Guild has a remaining money balance.

Guild money <> zToken swaps will always occur at the debt token *facePrice* (see details [here](https://docs.covenant.finance/getting-started/litepaper#interest-rates)). As a result, users can **potentially** take advantage of arbitrage opportunities if, for instance, the zToken *marketPrice* > *facePrice* or if zToken *facePrice* < *marketPrice* and there is Guild money to be claimed.

**Note: The following is meant for advanced defi users. Proceed with extreme caution and follow these steps at your own risk.**

***

## How to `swapMoneyForZTokens` :

1. Approve Money Token Transfers:
   1. Navigate to the top of the Market Details page in [https://alpha.covenant.finance/ ](https://alpha.covenant.finance/), and click on the link out from the money token in the right metrics panel

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FYF9O8TzY1Wk9HzjjvDqQ%2FScreenshot_2024-03-11_at_12.29.03_PM.png?alt=media&amp;token=68d9d7c2-8a71-42e2-af1e-e863f4118905" alt=""><figcaption></figcaption></figure>
   2. This will take you to the block explorer page for the money token. Navigate to the `Contracts` > `Write Contract` (or `Write as Proxy` if available) tab and click the `Connect to Web3` button to connect your wallet to the site.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2F91aGVVe6kmsOkhvQsvRQ%2FScreenshot_2024-03-11_at_12.30.44_PM.png?alt=media&amp;token=4c3cd08e-92c1-48ee-90ae-83d83d0c2aa3" alt=""><figcaption></figcaption></figure>
   3. After connecting your wallet, click the `approve` dropdown. Executing this function will enable the Guild to transfer an amount of money tokens on your behalf, which is required to execute `swapMoneyForZTokens`.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FgOSpU34flslOS1zDSRXa%2FScreenshot_2024-03-11_at_1.09.16_PM.png?alt=media&amp;token=8ecd45ee-2f25-4b09-b314-28f447642475" alt=""><figcaption></figcaption></figure>
   4. You can find Guild address by navigating back to the Market Details page and clicking on the address button next to the market name at the top of the page.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FygUx7QdUIN5ixoX2kVFi%2FScreenshot_2024-03-11_at_12.29.03_PM%201.png?alt=media&amp;token=9079266d-9a73-4106-acb5-465e094f280c" alt=""><figcaption></figcaption></figure>
   5. Input the guild address into the `spender` input field and add the money token amount you want to swap in the `value` field. **Note**: the money token value should be in money token units (i.e. 1 sUSD = 1000000000000000000) - **ALWAYS** confirm the decimal value of the money token you intend to swap.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FrpDJ8EwXFED1UjvQfLYq%2FScreenshot_2024-03-11_at_1.05.40_PM.png?alt=media&amp;token=372c9c28-50a7-4e20-b91d-f64b596e3554" alt=""><figcaption></figcaption></figure>
   6. Click on the `Write` button & sign the transactions in your wallet to execute the `approve` function.
2. Swap money for zTokens
   1. Navigate back to the Market Details page and click on the link out to the Guild address on the block explorer.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FrLMBbIlf3ABWs1d2LLh3%2FScreenshot_2024-03-11_at_12.29.03_PM%202.png?alt=media&amp;token=d161d599-5a1d-4042-8fb7-024128ff8b71" alt=""><figcaption></figcaption></figure>
   2. This will take you to the block explorer page for the money token. Navigate to the `Contracts` > `Write Contract` (or `Write as Proxy` if available) tab and click the `Connect to Web3` button to connect your wallet to the site.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2Ff1WdwmcT2v0h6UFBOqqk%2FScreenshot_2024-03-11_at_12.55.11_PM.png?alt=media&amp;token=bb505c7b-a282-47bf-89ed-9023c94b9948" alt=""><figcaption></figcaption></figure>
   3. Navigate to the bottom of the page, click on the `swapMoneyForZTokens` function, and enter the amount of money you want to swap with the Guild (note: this cannot exceed the amount of money you approved in the previous step).

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FEgOVa5kgxKkoctbqqYoV%2FScreenshot_2024-03-11_at_12.56.50_PM.png?alt=media&amp;token=c4897b0f-3d3c-471d-9c2d-a4df7915b333" alt=""><figcaption></figcaption></figure>
   4. Click the `Write` button & approve transactions in your wallet to execute the Guild swap.

## How to `swapZTokensForMoney` :

1. Navigate to the bottom of the Market Details page to check if the Guild has money to swap (i.e. the `Guild Balance` is greater than 0):

   <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FyfTsvBGfVzLUIQKIYRl3%2FScreenshot_2024-03-11_at_1.14.28_PM.png?alt=media&amp;token=18295ca7-539b-45c3-abfb-a1d168bdc627" alt=""><figcaption></figcaption></figure>
2. Approve zToken Transfers:
   1. Navigate to the top of the Market Details page in <https://alpha.covenant.finance/>, and click on the link out from the zToken in the right metrics panel

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FNAhNBi91gqH6DCdb6Q8B%2FScreenshot_2024-03-11_at_12.29.03_PM%203.png?alt=media&amp;token=c22acf8f-5339-42e9-b793-a0ddfbb97623" alt=""><figcaption></figcaption></figure>
   2. This will take you to the block explorer page for the Guild contract. Navigate to the `Contracts` > `Write Contract` (or `Write as Proxy` if available) tab and click the `Connect to Web3` button to connect your wallet to the site.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2Fvw7lw774DguqOdzTNjdd%2FScreenshot%202024-03-11%20at%201.03.00%20PM.png?alt=media&amp;token=a4670292-578e-4f25-a611-50bb8a5ad4fb" alt=""><figcaption></figcaption></figure>
   3. After connecting your wallet, click the `approve` dropdown. Executing this function will enable the Guild to transfer an amount of zTokens on your behalf, which is required to execute `swapZTokensForMoney`.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FKaXJVbur2O8voLXHin6P%2FScreenshot_2024-03-11_at_1.05.02_PM.png?alt=media&amp;token=e1a863df-a57a-435a-ab61-db0111c700df" alt=""><figcaption></figcaption></figure>
   4. You can find Guild address by navigating back to the Market Details page and clicking on the address button next to the market name at the top of the page.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FygUx7QdUIN5ixoX2kVFi%2FScreenshot_2024-03-11_at_12.29.03_PM%201.png?alt=media&amp;token=9079266d-9a73-4106-acb5-465e094f280c" alt=""><figcaption></figcaption></figure>
   5. Input the guild address into the `spender` input field and add the zToken amount you want to swap in the `value` field. **Note**: the money token value should be in zToken units (i.e. 1 zTazzDebtTest = 1000000000000000000) - **ALWAYS** confirm the decimal value of the zToken you intend to swap.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FX0hXEWOnxYMIVShu7YLJ%2FScreenshot_2024-03-11_at_1.07.32_PM.png?alt=media&amp;token=0c4f24b9-0774-4d51-a6fb-67cb92a9015b" alt=""><figcaption></figcaption></figure>
   6. Click on the `Write` button & sign the transactions in your wallet to execute the `approve` function.
3. Swap zTokens for money
   1. Navigate back to the Market Details page and click on the link out to the Guild address on the block explorer.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FMptrBSMyTpwsXiphTE9r%2Fimage.png?alt=media&amp;token=556406fe-3c0c-4389-9a0c-c04ad325606e" alt=""><figcaption></figcaption></figure>
   2. This will take you to the block explorer page for the Guild contract. Navigate to the `Contracts` > `Write Contract` (or `Write as Proxy` if available) tab and click the `Connect to Web3` button to connect your wallet to the site.

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2F9S3w52f3sfm3j7zrHW3t%2Fimage.png?alt=media&amp;token=ca07b506-2de4-4ce4-a7f5-db4017e59215" alt=""><figcaption></figcaption></figure>
   3. Navigate to the bottom of the page, click on the `swapZTokenForMoney` function, and enter the amount of zToken you want to swap with the Guild (note: this cannot exceed the amount of zToken you approved in the previous step).

      <figure><img src="https://3972845554-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCHCjmUrjuPhzffSUl2eD%2Fuploads%2FEnwHGwQZPhJLhhzxmBhD%2FScreenshot_2024-03-11_at_1.12.15_PM.png?alt=media&amp;token=5cccc443-1005-473d-ac1c-c523726e3439" alt=""><figcaption></figcaption></figure>
   4. Click the `Write` button & approve transactions in your wallet to execute the Guild swap.
