# Welcome to JediSwap

## What is JediSwap?

JediSwap is a 100% community-led, fully permissionless, and composable AMM on Starknet (a validity Rollup on Ethereum).&#x20;

With JediSwap, users can swap assets or earn passive yields by providing liquidity without losing custody of their funds. JediSwap is completely led and operated by the Mesh community.

## Who are we?

JediSwap is completely led and operated by the Mesh community. Mesh Community is a group of people united by shared beliefs in the core principles of transparency and equal accessibility. People in the Mesh community collaborate, learn, and earn together. Independent contributors help the Mesh community with development, community building, research, product development, growth, etc.

## What is the current status?

JediSwap has been live on the Starknet mainnet since November 30th, 2022. Within a short period of time, JediSwap became the #1 protocol on Starknet by TVL, trading volume, and many other onchain metrics.&#x20;

JediSwap is also the all-time #1 project on Gitcoin grants by unique donor count.

## Quick links

{% content-ref url="/pages/kWlenkSJ6BbITWqQhFx1" %}
[How to use JediSwap](/how-to-use-jediswap/how-to-set-up-a-starknet-wallet)
{% endcontent-ref %}

{% content-ref url="/pages/dV0NMJEftLQO8dmEM7Gm" %}
[Become a contributor](/become-a-contributor)
{% endcontent-ref %}

{% content-ref url="/pages/6N1R07EZrLFkmZQaYzXd" %}
[For Developers](/for-developers/jediswap-v2)
{% endcontent-ref %}


# Become a contributor

JediSwap is 100% led and operated by the Mesh community.

## What is the Mesh community?

The Mesh community is a group of people who believe in transparency and equal accessibility. Mesh Community is on a mission to create a fair and transparent organizational framework.&#x20;

We believe humanity can thrive if everyone has the freedom to

* work for what they believe in
* choose with whom they want to work with
* work from where they want to
* choose how much they want to work
* contribute with the skills they want to

## What is the Mesh contributor program?

People in the Mesh community collaborate, learn, and earn together. Independent contributors help the Mesh community with development, community building, research, product development, growth, etc.&#x20;

Products built by the Mesh community are community-driven, making everything bottom-up and non-hierarchical. From critical decisions to monetary rewards, all are processed with consensus, making everything transparent. There is no central team. The community and its set rules drive everything.

## Why become a Contributor?

You should become a contributor if you want to

* collaborate with like-minded people who believe in an equally accessible and transparent future
* work on creating the future of work with community-driven organizations
* be at the forefront of the financial revolution, bringing Open Finance to billions of people.&#x20;
* learn about Web 3.0 and the practices of community, consensus, and self-sovereignty
* earn ownership of the tools and products Mesh community launches

## **How are Mesh contributors rewarded?**

The Mesh community is building a unique incentive system to fairly and handsomely reward and recognize fellow contributors. This incentive system aims to remove all politics, reduce work pressure, and make collaboration fun. Contributors earn points for any contribution, like development, design, marketing, community management, etc. These contribution points will be converted to NFTs that show your efforts and impact on building JediSwap on-chain. These NFTs will be used for various benefits, like access to opportunities and token distribution for projects Mesh community launches.

## What are the ways to contribute?

There are multiple areas where we could use some help. Here are all the guilds we have:&#x20;

* **Force Wielders** (create content about JediSwap)
  * Independent Crypto Twitter users
  * Writers&#x20;
  * Youtubers&#x20;
  * KOLs
* **Community Managers**
  * &#x20;Actively help other people on Discord and create good vibes
* **Writers** (create content for JediSwap)
  * Documentation
  * Twitter Threads
  * Copy-writing (marketing material, website, etc.)
  * Blog posts
  * Translations
* **Developers**
  * Website Development
  * Smart contracts in Cairo
  * Building bots to make things easier
* **Design**
  * UI/UX (Website Design/App Design)
  * Illustrations/sketches/Stickers/Emojis
  * Marketing materials (Banners/Poster)
  * Animation Videos
  * Creative memes (not general memes)
* **Problem Solvers**
  * Discovering Problems and solving them
  * Sharing Growth Ideas
  * Projects/Ideas execution
  * Brainstorming/Feedback/Suggestions on existing projects/ideas
  * Project Management - leading a small/big project
  * DAO operations
  * Leaders - folks who take accountability and responsibility

**Check out the Mesh community notion page to learn more:** <https://jediswap.notion.site/3420d52b110a4ba0a039346119abc417?v=0e004cabdebe4792ac9bdaf39c59c030>

## How to join the Mesh Community?

Connect with us on Discord: <https://discord.gg/jediswap>


# DeFi spring STRK incentives for v2

Earn STRK Rewards by Adding Liquidity on Jediswap

## What is DeFi spring?

Users of the Jediswap protocol are eligible to receive STRK rewards as part of the [Starknet DeFi Spring](https://www.starknet.io/en/content/starknet-foundation-introduces-the-start-of-defi-spring), an initiative by the Starknet Foundation. The program aims to distribute 40 million STRK tokens as incentives for participation in DeFi platforms on Starknet, such as adding liquidity to Automated Market Makers (AMMs). Below, we describe our methodology for allocating these incentives to Jediswap liquidity providers.

## Incentive allocation methodology <a href="#incentive-allocation-methodology" id="incentive-allocation-methodology"></a>

Here are the steps for distributing STRK:

* The Starknet Foundation determines the amount of STRK for each eligible pair.
* Jediswap calculates the user-level allocation for each pair using the same methodology used for computing [LP points](/how-to-use-jediswap/points/lp-leaderboard#lp-points-formula):&#x20;
  * Each pair has four pools in Jediswap based on different fee tiers (0.01% fee, 0.05% fee, 0.3% fee, 1% fee).
  * We compute each user's points for each eligible pair by combining data from all four pools.
  * For each pair, we calculate the percentage points each LP accrued in the last 14 days relative to all LPs for that pair.
  * We multiply each user's percentage points by the total STRK allocated for that pair to determine the exact amount for each user.
  * We sum all the STRK amount of a liquidity provider across different pairs to determine the final STRK amount.

## Which pools are eligible for rewards <a href="#incentive-allocation-methodology" id="incentive-allocation-methodology"></a>

The Starknet Foundation periodically updates the list of eligible pairs. Currently, these pools are eligible for STRK rewards:

* [STRK/USDC](https://app.jediswap.xyz/#/add/0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)
* [STRK/ETH](https://app.jediswap.xyz/#/add/0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d/ETH)
* [ETH/USDC](https://app.jediswap.xyz/#/add/ETH/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)
* [USDC/USDT](https://app.jediswap.xyz/#/add/0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)
* [WBTC/ETH](https://app.jediswap.xyz/#/add/0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac/ETH)
* [DAIv0/USDC](https://app.jediswap.xyz/#/add/0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)
* [wstETH/ETH](https://app.jediswap.xyz/#/add/0x042b8f0484674ca266ac5d08e4ac6a3fe65bd3129795def2dca5c34ecc5f96d2/ETH)

## How do I earn the most STRK incentives? <a href="#how-do-i-earn-the-most-strk-incentives" id="how-do-i-earn-the-most-strk-incentives"></a>

Three factors influence the amount of STRK incentives you earn:

* **Pool type:** Different pools have distinct allocations of STRK incentives, as defined by the Starknet Foundation. Check the [Pool page](https://app.jediswap.xyz/#/pool) to see for the latest APR of different pools.
* **Fees earned by a position:** The more fees you earn, the larger your share of the incentives, all else being equal.
* **Duration of a position:** The longer you hold a position, the more rewards you accumulate during the event, compared to someone who earned the same fees but held the position for a shorter period.

## **How to participate in the program** <a href="#participation-in-the-program" id="participation-in-the-program"></a>

Since we calculate the suggested allocation of rewards off-chain and retroactively, no action is required to participate in this program. If you hold a position in one of the eligible pairs, it will automatically receive rewards.

## **Claiming your allocation** <a href="#claiming-your-allocation" id="claiming-your-allocation"></a>

Allocations will be available to claim on [Jediswap's Rewards Page](https://app.jediswap.xyz/#/rewards). To learn how allocations are determined for each individual address, checkout [#incentive-allocation-methodology](#incentive-allocation-methodology "mention").

Here is how you can claim your rewards.

1. Go to [Jediswap rewards page](https://app.jediswap.xyz/#/rewards)
2. Scroll down and check your unclaimed rewards since the last time you claimed rewards.
3. Click on the claim STRK button and confirm the transaction.&#x20;
4. Once you have claimed, you can come back to the rewards page on the next available claim date to check the next round's rewards.&#x20;

   <figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FLWvORvf7L7uql3wpZTmn%2Fimage.png?alt=media&amp;token=dda4d166-e780-4274-8340-e6a59aedb8a0" alt=""><figcaption></figcaption></figure>


# DeFi Spring STRK incentives for v1

STRK incentives for Jediswap liquidity providers

## Introduction <a href="#introduction" id="introduction"></a>

Jediswap protocol users are receiving STRK rewards as part of the [Starknet DeFi Spring](https://www.starknet.io/en/content/starknet-foundation-introduces-the-start-of-defi-spring) by the Starknet Foundation. Our methodology for generating the suggested allocation of these incentives to Jediswap liquidity providers is described below.

## Incentive allocation methodology <a href="#incentive-allocation-methodology" id="incentive-allocation-methodology"></a>

We will suggest user allocations based on the same measures used to determine protocol-level allocations so that the same users responsible for Jediswap's portion of the total incentive allocation also receive all the incentives.

The first split of allocation is by pair. The Starknet Foundation will determine this split.

The following pairs are eligible for rewards:

* [STRK/USDC](https://app.jediswap.xyz/#/add/0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)
* [STRK/ETH](https://app.jediswap.xyz/#/add/0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d/ETH)
* [ETH/USDC](https://app.jediswap.xyz/#/add/ETH/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)
* [USDC/USDT](https://app.jediswap.xyz/#/add/0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8)

The results of the query we use to determine allocation will be published for review days before the first allocation.

## How do I earn the most STRK incentives? <a href="#how-do-i-earn-the-most-strk-incentives" id="how-do-i-earn-the-most-strk-incentives"></a>

Please keep in mind the following guidelines for receiving the most STRK in order of importance. The exact algorithm may change from fortnight to fortnight.

* Larger positions earn a larger share of incentives, all else equal
* The longer you hold a position, the more rewards you get (during the event)

## **Participation in the program** <a href="#participation-in-the-program" id="participation-in-the-program"></a>

Because we compute the suggested allocation of rewards off-chain and retroactively, no action is required to participate in this program. If you have a position on one of the eligible pairs, it will receive rewards.

## **Claiming your allocation** <a href="#claiming-your-allocation" id="claiming-your-allocation"></a>

The allocation will be available to claim on the [Jediswap's Rewards Page](https://app.jediswap.xyz/#/rewards)

<br>


# Withdraw LP from Jediswap V1

Follow these step-by-step process to withdraw your liquidity from Jediswap V1.

{% stepper %}
{% step %}

### Get all Jediswap v1 LP tokens

* Open [https://starkscan.co](https://starkscan.co/)&#x20;
* Search your wallet address in the search bar&#x20;
* Go to Portfolio&#x20;
* Look for Tokens with symbol "JEDI-P"
* Click on Token contract address for each individual LP token

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2Fm2G7IUDravizqBIA6W3A%2F1.jpg?alt=media&amp;token=2715b50a-4268-4574-8236-7372ced4138e" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Get your LP balance

* Go to the LP token page on Starkscan as described above
* Go to Read/Write contract
* Click on function "balanceOf(account)"
* Input your wallet address and click query
* Copy the value of the balance on a note, it will be used in step 4 and 5

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FBH3OP4qbpGHZ1rC4LfPC%2F2.jpg?alt=media&amp;token=af05e38c-44bb-4e68-8925-c9b5585674e0" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Get address for token0 and token1

* Scroll down on the same page as above and click on function "token0()"
* Click query and copy the address on a note, it will be used to call withdraw function at end&#x20;
* Similarly scroll down again and click on function "token1()"
* Click query and copy the address on a note, it will be used to call withdraw function at end

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FCbRAy2rJLNwZb1r2qQQv%2F3.jpg?alt=media&amp;token=58976133-8780-493b-8b82-98276dc474f9" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Give "Jediswap Router contract" approval to spend your Jedi-P LP token

* Go to "Write" from top left options on the same Jedi-P LP contract
* Connect your Starknet wallet
* Click on "increaseAllowance" function&#x20;
* In the "spender" field, paste "0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023"
* In the "added\_value" field, paste the LP balance value you copied from step 2
* Click "write" and confirm tx on your Starknet wallet

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2F4GWfNrKGJu4TLoiSA33g%2Fimage.png?alt=media&amp;token=d0be2213-b4e5-4a38-bda7-398cc682b1f6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FyEmQghZWj7hTBD1V2WzS%2F5.jpg?alt=media&amp;token=a5d0bc05-845c-450b-aae0-12435d213d0a" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Remove your liquidity

* Go to "Write Contract" on [Jediswap Router Contract](https://starkscan.co/contract/0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023#read-write-contract-sub-write)
* Connect your Starknet wallet
* Click on "remove\_liquidity" function
* Input these values in the fields
  * tokenA = token0 value you received from step 3
  * tokenB = token1 value you received from step 3
  * liquidity = LP balance value from step 2
  * amountAMin = 0
  * amountBMin = 0
  * to = \[your wallet address in which you want your funds]
  * deadline = 10000000000
* Click write and confirm the tx on your wallet

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FiCkgt7NfnjnI7UGpPbUr%2F6.jpg?alt=media&amp;token=56fbfd98-0ecb-4f6e-b0c8-39f708e79c78" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Done! Your funds should be in your wallet. Repeat these steps for each of your Jediswap V1 LP position.

{% endstep %}
{% endstepper %}


# Withdraw LP from Jediswap V2

Follow these step-by-step process to withdraw your liquidity from Jediswap V1.

{% stepper %}
{% step %}

### Get all LP positions

* Go to [Jediswap V2 NFT router contract](https://voyager.online/contract/0x0469b656239972a2501f2f1cd71bf4e844d64b7cae6773aa84c702327c476e5b#readContract)
* Click on function "get\_all\_tokens\_for\_owner"
* In the "owner" field, paste your Starknet wallet address
* Select "Decimal" in the response format
* Click "Query"
* Note down all the "token ids" from the response, you can withdraw each LP position one by one.

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FVSLSspYEq7Hbe5bpXRfm%2F1.jpg?alt=media&amp;token=d7c49f60-4e36-4004-a2c1-0595ddbd4f75" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Get LP balance

* Scroll down on the above contract
* Click on function "get\_position"
* In the "token\_id" field paste one of the "token id" received from step 1
* Click query and copy the value for "liquidity" field from the response

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2Fir0iV9Bq3s9TquQFIBCJ%2F2.jpg?alt=media&amp;token=ed5b2e8d-e167-4d91-861b-ec328fd9d5fb" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Decrease liquidity

* Go to [write contract](https://voyager.online/contract/0x0469b656239972a2501f2f1cd71bf4e844d64b7cae6773aa84c702327c476e5b#writeContract) from top-right in the above contract
* Connect your Starknet wallet
* Click on function "decrease\_liquidity"
* In the fields input below values
  * token\_id = Same token id you used step 2
  * liquidity = liquidity value you received from step 2
  * amount0\_min = 0
  * amount1\_min = 0
  * deadline = 10000000000
* Click on "Transact" and approve tx on your wallet

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FhqB2RVb1J9cz3vFgz2zz%2F3.jpg?alt=media&amp;token=5d005399-8dfb-45e5-bde7-4d5fe0f3c011" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Withdraw funds

* In the same contract as above, click on function "collect"
* In the fields input below values
  * token\_id = Same token id you used step 2 and 3
  * recipient = your Starknet wallet address where you want to receive funds
  * amount0\_max = "0xffffffffffffffffffffffffffffffff"
  * amount1\_max = "0xffffffffffffffffffffffffffffffff"

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2F3zhVyxKfIMqxdsI1SIBU%2F4.jpg?alt=media&amp;token=d580f98c-7c2f-408a-9359-47f4424a3fb5" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Burn your LP NFT

* Your funds should already be in your wallet from step 4
* To keep your wallet positions clear, you can optionally burn the LP NFT
* In the same contract as step 3, go to function "burn"
* In the "token\_id" field paste the same token id you used in step 4
* Click transact and confirm tx on your Starknet wallet

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FcVmouSD2AU4AsChBUEFe%2F5.jpg?alt=media&amp;token=ebdf33f5-ae51-40f2-9410-25880ae58f0b" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Repeat these steps for each of your position from step 1

{% endstep %}
{% endstepper %}


# FAQ

TODO


# How to set up a Starknet wallet

### To access JediSwap, you'll need to first set up a Starknet wallet. Currently, Argent X, Argent Web Wallet and Braavos are the three wallets compatible with JediSwap.

1. [How to set up an Argent X wallet](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-set-up-a-starknet-wallet/how-to-set-up-an-argent-x-wallet)
2. [How to set up an Argent Web wallet](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-set-up-a-starknet-wallet/how-to-set-up-an-argent-web-wallet)
3. [How to set up a Braavos wallet](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-set-up-a-starknet-wallet/how-to-set-up-a-braavos-wallet)


# How to set up an Argent X wallet

In this guide, we will go over how to install and activate an Argent X Wallet.

## 1. Create the Argent X wallet

* Download the Argent X wallet extension from [here](https://chrome.google.com/webstore/detail/argent-x/dlcobpjiigpikoobohmabehhmhfoodbb).

<figure><img src="https://lh3.googleusercontent.com/gi7z7GpR1bGWbMfwGdKeByTagEqHZ6_1kMLgaDz6kP4nZeVH07Up5Oz8YKjpvkncsjp141RWP_W2JtXkzO0PzbsGCRqs8mXNHGjVN6t8WE9uT-uD2io40lYJ3Vtgv8Ve-c6sEohTw9-Oyxd9DYh8a1Y" alt=""><figcaption></figcaption></figure>

* Open the Argent X wallet extension on your browser and set up your initial account.\
  In case you need any help, here's a step by step [video](https://www.youtube.com/watch?v=_KgY2ag3JL4) by Argent.

<figure><img src="https://lh4.googleusercontent.com/WmKsdixGbwWFameaaMTK9VtadR735w2FNzWhgjsufWcE9wbqPeHaxNGOxGTiCvbkLEJc3vhz-c3IMwDtheaSW6AnnqM5vq5Hf7cgfbLWdsqYeLS4mMd9w0CBmCZmuqFQGZyI2n5XEwejw-EnYudqhDY" alt=""><figcaption></figcaption></figure>

* To top up (*deploy*) your Argent X wallet, you need to make sure that you are on Starknet mainnet.

<figure><img src="https://lh6.googleusercontent.com/xp-3srYdiqPXl5GuqdZ-q8IRW0M--Fjhv7Gt-GhbTKD1Bl3Yo7F3oFH5tiMIMVXISfaIzbBLLP8V_0ZOSfe8-9qme6DtD5Wgbbtx5Qijsktr_qegA_gM8JP0QW5Eyvc_hVgD6oZXgNiPHjclbmQZl2Y" alt="" width="375"><figcaption></figcaption></figure>

* Deposit funds to your wallet.

[*How to bridge to Starknet*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-bridge-assets-to-starknet)


# How to set up an Argent Web Wallet

In this guide, we will go over how to install and activate Argent Web Wallet.

## 1. Create the Argent Web Wallet

First, navigate to the [JediSwap app](https://app.jediswap.xyz/).

1. Click on the **“Connect Wallet”** button.
2. Click on the **“Continue with email”** button.&#x20;

<figure><img src="https://lh5.googleusercontent.com/6H36Y4wtHhESBjveY9UUusuoBE96XaNO5wNmvUx0rnFKnPCapBNolf6Uj5luUdvII9dPtmf5eZQCchRbyImSsiItv9CLDYKNQCXenMcIQG6SnizDt-azqrfsANLAE86t8s_LKN8DtZPvXQ0D-zv8ALg" alt=""><figcaption></figcaption></figure>

3. A new window with the Argent Web Wallet will be prompted. You will need to enter your **email** to start the account creation process and then, click on **“Continue”**.

<figure><img src="https://lh3.googleusercontent.com/a4yLAGCoFVfhIkW2tSr0K4dqHOa5vrX35OVFKjktgUxxuy3M7cQ9DaxM2vHvifbr0dZ7oqQXlI4GY6mhWDr0zFlVRGEOBHS0Ufdrjmz-2sFYyz-QhKnlIErz-7PP__GfiZvT6Y905lDPZzde4QNSkN8" alt=""><figcaption></figcaption></figure>

4. You are now required to verify your email. Upon entering your email, you will receive a **6-digit** code that must be provided in the field above.

<figure><img src="https://lh3.googleusercontent.com/puJ8x1_YVqITVAQKTiRpNkbhXtLltvrqF2_vRWlG8rUk4HcmlZhtTAKr0AWgaoun_Df6Sg7fB3m7HTpbc7l4tpoCBv9zB1IXk9Lx8GdCzNoyO3UCsG9y1jeuOOVmLWeAx_aHOUjIbyA8TMhBD44nvJ8" alt=""><figcaption></figcaption></figure>

5. The next step requires you to create a password for the Argent Web Wallet. Please ensure that your password includes a combination of both uppercase and lowercase letters, as well as numbers and special characters. Hit the **“Continue”** button to complete the process.

<figure><img src="https://lh3.googleusercontent.com/umvtd4m3GH55BeOEYYOUhP3Lzmdi9ihLCgwwryy7bvq7EF9zD1kRheAYZnlIIvewnM-UG2LZBUfGZx1J65xTsQUne3OQFZ7Y9xBMXDLqxnZVKqEseaX4L6GbKIrSq85sxuBrBnqnIrPdm4d3Oq2GBEo" alt=""><figcaption></figcaption></figure>

6. After setting a password, your account will be created. You will then be redirected to JediSwap and presented with the option to connect to JediSwap using the Argent Web Wallet.

<figure><img src="https://lh3.googleusercontent.com/zTQcnjIZBzRU-voCFbVZ4gyvigEuXWS1HE2RarEV0sjlFuvr84ezjxiFbv2vlMY8qyojqCyiLWsCOuZMKNRNdkMwGrFl7QJJsxlEIkwcUTIzTCtGbCSuY6s3J8o8ZRHbIKrB2unnLMAeikDsIUWlpIg" alt=""><figcaption></figcaption></figure>

Your **Argent** account is now up and running, which means you can start interacting with JediSwap using just your email and password.&#x20;

You can view your wallet at [web.argent.xyz](http://web.argent.xyz).

[*How to bridge to Starknet*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-bridge-assets-to-starknet)


# How to set up a Braavos wallet

In this guide, we will go over how to install and activate Braavos Wallet.

## 1. Create the Braavos wallet

* Download the Braavos wallet extension from [here](https://braavos.app/).

<figure><img src="https://lh3.googleusercontent.com/yC8_yRZ9W-SotVu7V2msQYi-lj_nUoDQc2t3fM9hfSyPyKRmv62AjUIagHkDPvP_1akFbdtMzSbE9N60quqqIRCXYW9MCc6WL7yz7YaOf2Ko_BVJZkrd87VjfZyyhX5QrrRfMfg2FyJM6fELpTs0Qno" alt=""><figcaption></figcaption></figure>

* Open the Braavos wallet extension on your browser and set up your initial account.

<figure><img src="https://lh3.googleusercontent.com/3OSWUc7HGuM-Jm4mcbROnrAEjtLwzbbmAHtYUQyYi9hZU32Gr89wdcsS02b_BaonN0TWZy_6gIpu5WGp_GW0q4wA03Ce669YAQoPe-TDQC5ax2IKafdVWsnX1gMhGvpfxqNcLaRHJWzv4hOZGuDG2BI" alt=""><figcaption></figcaption></figure>

* To top up (deploy) your Braavos wallet, you need to make sure that you are on Starknet mainnet.

<figure><img src="https://lh4.googleusercontent.com/TpW9lMWUtth2GqdzyvnsQZdcK6ClIXO8grESsbD73Fig9jZD836TbfGhg8JDd6972WtYhQ6dNCZk0s8Oc8xi7cihmJovpeGjwM0KkM-D26kKsm0ZWlD1PE-l682QuOPtiWakkTvLt24Bw75_3lgtBPs" alt="" width="375"><figcaption></figcaption></figure>

* Deposit funds to your wallet.

[*How to bridge to Starknet*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-bridge-assets-to-starknet)


# How to bridge assets to Starknet

## Bridge to your wallet

Currently, there are 3 different ways bridge funds to your account:

1. [Starkgate (native bridge)](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-bridge-assets-to-starknet/how-to-bridge-to-starknet-using-starkgate)
2. [Orbiter Finance (third party bridge)](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-bridge-assets-to-starknet/how-to-bridge-to-starknet-using-orbiter-finance)
3. [LayerSwap (third party bridge)](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-bridge-assets-to-starknet/how-to-bridge-to-starknet-using-layerswap)


# How to bridge to Starknet using Starkgate

In this section, we will show how to bridge your funds to Starknet using the Starkgate bridge.

## Starkgate

Open up the [Starkgate](https://starkgate.starknet.io/) bridge (native Starknet bridge).

<figure><img src="https://lh3.googleusercontent.com/vrCjCcaQzRahT9H_6A60oV5OKUsXYB3ge1fE1EhGwil5ZqPemMBIovGiCXAHuV58Kr7niwWhwoOTaeziFu18i_NKjTgeygOzlpCT1-bzG610rx3aods0SyYwRwU2Jh-qiZ0x6JnDzYyxgizsj4zs4sc" alt=""><figcaption></figcaption></figure>

* Connect your Metamask wallet
* Connect your Starknet wallet (Argent X / Braavos)
* Input the desired amount you want to send to Starknet
* Click on “Transfer”

<figure><img src="https://lh5.googleusercontent.com/1uLsjFHM4TGtKBVbm1nmPmhWLcFn_4k37fS3SQrgEqpMkwxW4_-xxDf5dq4JMZl5wdUeDEIAw93CmfTlTZDoMSJqrwKlPTx-7iv1nsCBu1QYrDs3HjKdBKHsuS5pbZhVvc24lrUPbjTC0UUBhjCxlZU" alt=""><figcaption></figcaption></figure>

* Confirm your transaction via Metamask wallet

<figure><img src="https://lh4.googleusercontent.com/TP9E40XJorqXqo-mShTroHC88YaW1rFv3HWpfz-PzkeHVVQGZ3I0iLa0ouhpyNfP27qyPBfQbFezG2otYpZolMVVVIgOJNoFnR8guzfDH6lERfrZiY3CRNMkN4aPMntSJPIHEFEL7WdO0u0zHN0gb7k" alt="" width="563"><figcaption></figcaption></figure>

* Simply wait for until the transaction is confirmed and your funds have arrived to Starknet

[*How to make a Swap on JediSwap*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-make-a-swap)


# How to bridge to Starknet using Orbiter Finance

In this section, we will show how to bridge your funds to Starknet using the Orbiter bridge.

## Orbiter Finance

Open up the [Orbiter Finance](https://www.orbiter.finance/) bridge (third party bridge).

<figure><img src="https://lh6.googleusercontent.com/_xvb-BIxvgIDyhTEygEMYHdbRRoSSg2G-0jpSUrcTvMFkh6ENfYWTCIh1kxn1kp4_RK-TPt2V0E4rXHz-fIYwnub44BvOU0fYbiq6N4QMlkMGV16iWALEB6jY7BDUdlVlmNTuUL27tylpciECwh1r2k" alt=""><figcaption></figcaption></figure>

* Connect your Starknet wallet (Argent X / Braavos)
* Connect your Metamask wallet
* Choose the source chain from which you are going to send funds
* Select Starknet as the destination chain
* Input the desired amount you want to send to Starknet
* Click to “Send”

<figure><img src="https://lh5.googleusercontent.com/2BTwV0wimL8WdEriVcH8rAgPjSQJ1ibjzDFdfMunphUGhT0CtjoGE0jmOkQYZoWr0p3KmiIlAhCswzUs0yN6F-Wvc6z6h16YxLxS37d1efk-C9QfA_zuKAws2qGP4LOtOu17svL-UO4TDuXv1nYd8sk" alt=""><figcaption></figcaption></figure>

* Confirm your transaction via Metamask wallet
* Simply wait until the transaction is confirmed and your funds have arrived to Starknet

[*How to make a Swap on JediSwap*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-make-a-swap)


# How to bridge to Starknet using LayerSwap

In this section, we will show how to bridge your funds to Starknet using the LayerSwap.

## LayerSwap

Open up the [LayerSwap](https://www.layerswap.io/) bridge (third party bridge).

<figure><img src="https://lh3.googleusercontent.com/jI4C4EVMwe6wzShC4Elnk-nY_RTUWKgTJHvSaKC3rZJvC1lt9rnV361khAmyNVJfaUqbKvc1x-JHi_7SdWNAO0GypuAVgdn4eorAFKvHwmVDeWFIgwBrG8i5SJXJtpwk8ytOJSmZ2T2gfK6tQzpe6qE" alt=""><figcaption></figcaption></figure>

1. Choose the source chain from which you are going to send the funds
2. Pick Starknet as the destination chain
3. Input the desired amount you want to send to Starknet
4. Input your Starknet Mainnet address
5. Click on “Swap Now”

<figure><img src="https://lh3.googleusercontent.com/9IYQLPIntRD0cyNi80jmpvW33Slp5BvB2kCmv5fa-NG4IgZ73QIumAaA3ptRl4fJ5HJJAxpP3OQMn_UjIDf0Q7OqBXC4Ko6tRL_PVGeZvxcjs4Cd8hKmyoTL9LfPjRK_yb3ljCDsIUJq8-545jOdvh8" alt=""><figcaption></figcaption></figure>

1. Select “Via wallet”
2. Confirm your transaction in the Metamask wallet

<figure><img src="https://lh6.googleusercontent.com/vs7tBMe1hFWmi9L7rWSiDMsVy-ZE-vsaRho-aRUv6GhJfjvpWIe3xKtjR9uEEiR4nWL-cOcjOF7vIHPTLtDRMdfTLmqKEwqPQCdm6sXiwra0gxlCnioNpC66svFvmFZYiejusi9-38ugZY_Xcs3o-eQ" alt=""><figcaption></figcaption></figure>

* Simply wait until the transaction is confirmed and your funds have arrived to Starknet

[*How to make a Swap on JediSwap*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-make-a-swap)


# How to make a swap

In JediSwap, users can swap tokens permissionlessly without losing custody of their funds.

## 1. Choose the tokens you wish to swap

* Go to <https://app.jediswap.xyz/>
* Choose the token you wish to swap and the token you wish to receive.

<figure><img src="https://lh4.googleusercontent.com/GD7IzOWzQBtDgMb-m5xuUWfYXg4cegOc4Jwom_7oc-PjYPyvevJlmvqgvKa4gfdqUpxWe-H5DJAMUjnncLRuiAHe85gp32wmoGe2ydZWoJ8uA7Sc5V6J1VtR0QTrMyK36-QI6AgbnKnNrtZ8ZEDLXcw" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh4.googleusercontent.com/42b_m1ruGsKxoSJ1g1mqD-3RwS7YxeFC3hIclV-Sa5y6Ysi8myngantdXvtSFhBkg0O9svLVimzI1se-59RoZLcnpoQNHswvKHchYtsLApDOE14bpc9YgIjeHHMzzTPPKogH1rb05Xq3k04noHyNwG4" alt=""><figcaption></figcaption></figure>

You can also search a token by its name or contract address.

<figure><img src="https://lh3.googleusercontent.com/Mc8RdPMVodGNph7WeeEKX5AtDBX755fqtdYn4LZVJeoY8kNlASvKcSkhpZtCU6zk0Qbsea2NkmCYXVHmTpKKKoq4v1kZ1cfvpzB7ibSM1Uzb8sl4lbHo4wrNqEPHX5Q6DVWVwb0M0P9QGoitRfwWzKU" alt=""><figcaption></figcaption></figure>

## 2. Enter the input or output amount

* Enter the amount that you wish to swap. Fill in either the input amount for the token you want to trade or the output amount for the token you want to receive.

<figure><img src="https://lh3.googleusercontent.com/y94enZ8rO4b7pdSyQ5_Lhur_KT_z1O_ctjnGw3GFxM6B01qnvGIaa4zagLqolzatbWYNTo_kRuolKZJulUd5gZgWCbLSbJrDpw89pHfU_5T3H9oifxvdIMjzqcR91pIp2ZNHpWvxGYaInnmSWF7Tm9o" alt=""><figcaption></figcaption></figure>

## 3. Review your swap

* Click on the 'Swap' button to see a preview of your swap.

<figure><img src="https://lh5.googleusercontent.com/LChwnaQheUB29nqNjj7JCXXzFYqPrcDPyMxtNaoYYPchRKVe7KH2BENHWWJCAf3BbiZ9pI-scm2JhNMUtvbtGziD_-wf97a6h4tsZpBs244zGMeYz1vX3bER5IPfuFCKU6D7EckIKQTUrBewuqT-sp0" alt=""><figcaption></figcaption></figure>

This screen will show you all the details of your swap, like the swap fee, price impact, allowed slippage, etc.

<figure><img src="https://lh6.googleusercontent.com/86wn1Dxf6UvVlafCVTsPYpgqJcEs9SQMtVQsDquoQBZ4B0Mw8yWipX_fR4diVeogDOHBaeYMik0lPpJwRpIt3BUcawBLqLbPJ6AVoiXsqzHAsoRrqezg4Od-mbQKYCcWyNWBa2s7fiXZB0ctdVUPUxU" alt=""><figcaption></figcaption></figure>

## 4. Confirm your swap

* Once you have reviewed your swap details, click on the “Confirm Swap” button, and it will open an Argent-X popup to authorize the transaction

<figure><img src="https://lh5.googleusercontent.com/LChwnaQheUB29nqNjj7JCXXzFYqPrcDPyMxtNaoYYPchRKVe7KH2BENHWWJCAf3BbiZ9pI-scm2JhNMUtvbtGziD_-wf97a6h4tsZpBs244zGMeYz1vX3bER5IPfuFCKU6D7EckIKQTUrBewuqT-sp0" alt=""><figcaption></figcaption></figure>

## 5. Sign the swap transaction

* Argent-X will prompt you to sign the swap transaction. Click on "Sign" to complete the transaction.

<figure><img src="https://lh6.googleusercontent.com/G63EuL-8wUyLmcZCkbkcHbGAFzwALYJGoxIx4iwSv1qHhD-I3RJRtgaDeYCc8ZIY-i9HJ0R44O3Ku2cWyW685IpThZJ12ubJEfYIofVcqXcYD6rWhS27Y2YtoVqknXL6nXY8CeikWa1-lwdFIJ3ckzg" alt=""><figcaption></figcaption></figure>

## 6. Wait for the transaction to be confirmed

This should take a couple of seconds.

[*How to add Liquidity on JediSwap*](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-add-liquidity)


# How to add liquidity

JedySwap is fully permissionless, and composable AMM on Starknet. Currently, JediSwap has two versions where users can earn passive yield on your assets by providing liquidity.

* [How to add liquidity V1](https://app.gitbook.com/o/0HDhWBRKw2xshTgFwB0n/s/TtqAy9sEg9xS0BQqt6LI/~/changes/63/how-to-use-jediswap/how-to-add-liquidity/how-to-add-liquidity-v1)
* [How to add liquidity V2](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-add-liquidity/how-to-add-liquidity-v2)


# How to add liquidity V1

Earn passive yield on your assets by providing liquidity

Providing liquidity to an AMM is one of the easiest ways to earn a good passive yield on your assets. The AMM pool uses this liquidity to enable swaps and, in return, charges a fee to users making a swap. This fee is distributed back to liquidity providers proportional to their share of liquidity in the liquidity pool. Currently, JediSwap charges a flat 0.3% on each swap.

## 1. Choose the tokens you wish to provide liquidity with

* Go to <https://app.jediswap.xyz/#/pool>
* Click on "ADD LIQUIDITY"

<figure><img src="https://lh4.googleusercontent.com/n_2zVLNfYmmhSZNWehzdhG-nNCnQg0B047VezlZMEeHQchP1KWt8f5JchOJe03-6Mgb5x5H21nWkP1TFYzye5PEL-LJj-5BZHzX5zShaPoTc89lpHMnJfwGGudYtrqu36fPkijJH7_Vi44o-uucwvmo" alt=""><figcaption></figcaption></figure>

* Choose the token using which you wish to provide liquidity.

<figure><img src="https://lh3.googleusercontent.com/zCl1FwUS78pEla-s15jIRoU_HMEZT4UAZmFpMH0U2Ijfk0Iewg0AGgBOUt4kNUaksU6VR5XBV0YdU5O40nsQRW4PJLimL9RrkMFrcTHe-YatdcwFxM79tckaXTffyyfzR6dLkxsPW_B1P2Ztz7_Uc0o" alt=""><figcaption></figcaption></figure>

## 2. Fill in the input amounts

* Input the number of tokens you want to add to the liquidity pool.

<figure><img src="https://lh3.googleusercontent.com/zUDC57K0X_oONHpsShFydUxUNJJLSH3ttUohh1l5CNNY4VTZ3a-8VVgM9Z5ZwTwyD6j_YH4s0Ik6RWHVfx7Ovgj45F2sQMCbAvKx_BM0XMni9QYXbg71OzP25_6NCBH1wtH2P5hVG_8nqllA8E47CV0" alt=""><figcaption></figcaption></figure>

## 3. Review your transaction details

* Click on the "Supply" button to preview your transaction for providing liquidity.

<figure><img src="https://lh3.googleusercontent.com/7cRpk3ekQLaHSDFV54ykaDkQEprp94aJBE4bo11aAes3GY7fDPChf_aytxP4b6FzNP3QlYZSFGMSPeO1rC1YQIDRjz0xcQ3flDp634Jg6ahl41qBOdFmechBddc21dJyWfyFlHpl5aNN2lntizJjVZ4" alt=""><figcaption></figcaption></figure>

* Review your transaction details, including the tokens' input amount and the slippage setting.

<figure><img src="https://lh5.googleusercontent.com/u4bxA1TVeif5WxC3WG0UOcw5xaFh0nTsHE5issOrIC0TmKtJR_QhWL8j0QjN0H3x8z2XEiR0xG3AEWDO5ETa6of6PsU_vS8VJjrek0nzBp3n2XFmwT0IbC2CjJOP6REEKTlGC-SQjRnGgeEkprejONo" alt=""><figcaption></figcaption></figure>

## 4. Confirm your transaction

* Once you have reviewed your transaction details, click the "Confirm Supply" button.&#x20;

<figure><img src="https://lh4.googleusercontent.com/KKEOFAfH73af7pIW-fCrYr3NSa0IAtds98-EL2IkGDwkz4i0oeF8GTS9g2MGA6282lZ2ikpCgjrxF1xHCiaDuDvlC3sLaJ_Mk7EaNx6uVZfnsVx5ykQQERfahxT47SjiNx7us3NJgioCT5Hinv2t4Ag" alt=""><figcaption></figcaption></figure>

## 5. Sign the add liquidity transaction

* Once you click the "Confirm Supply" button, Argent-X will open a prompt to sign the transaction. Click on "Sign" to complete the transaction.

<figure><img src="https://lh5.googleusercontent.com/Un-bcp3Drgt-jajIwoMtJewu9f3ohPv9dSEkxUx9irsBJoIFgi69dFTPD8w4NslHtUqoAyIbAwF_L0sukyLCmUbABIba4USX9kNwGf952RwLi2hFWmnMZHE2pH2DVCpn9zu-qd-joC1G28rur3k02a8" alt=""><figcaption></figcaption></figure>

## 6. Wait for the transaction to be confirmed

This should take a couple of seconds.\
\
All done! Congratulations, you are now a liquidity provider in JediSwap!


# How to add liquidity V2

Earn passive yield on your assets by providing liquidity

Providing liquidity to an AMM is one of the easiest ways to earn a good passive yield on your assets. The AMM pool uses this liquidity to enable swaps and, in return, charges a fee to users making a swap. This fee is distributed back to liquidity providers proportional to their share of liquidity in the liquidity pool. Currently, JediSwap charges a flat 0.3% on each swap.

## 1. Choose the tokens you wish to provide liquidity with

* Go to <https://app.v2.jediswap.xyz/#/pool>
* Click on "New position"

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FYJc7NdQpSQpI4iLGRY8t%2F%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202024-02-11%20%D0%B2%2017.58.16.png?alt=media&amp;token=0d736b47-5192-4c24-a017-00579f23e254" alt=""><figcaption></figcaption></figure>

* Choose the tokens you wish to provide liquidity with.
* Choose the fee tier.\
  *Fee Tier is the percentage of the liquidity provider fee that users pay for swapping*.
* Set the price range for optimising concentrated liquidity. Full price range can be used as well.

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FsBRsu7NLySp1pyTWeuY7%2F%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202024-02-11%20%D0%B2%2018.03.31.png?alt=media&amp;token=fab6a352-8f00-48bf-ac3f-e47335b47d02" alt=""><figcaption></figcaption></figure>

## 2. Fill in the input amounts

* Scroll down and input the amount of tokens you want to add to the liquidity pool.

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FHq9FiPcMhfWeYjvo96Z6%2F%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202024-02-11%20%D0%B2%2018.09.17.png?alt=media&amp;token=fce7ba76-e42d-48d7-bb7f-0bcd699114c6" alt=""><figcaption></figcaption></figure>

## 3. Review your transaction details

* Click on the "Preview" button to preview your transaction for providing liquidity.
* Review your transaction details, including the tokens, input amount, fee tier settings and price range.

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2FsK4EDjxauQHtzGzFYCE5%2F%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202024-02-11%20%D0%B2%2018.11.41.png?alt=media&amp;token=607bf6aa-0887-4cef-a9e2-77a6fa3a6962" alt=""><figcaption></figcaption></figure>

## 4. Confirm your transaction in your wallet

* Once you have reviewed your transaction details, click the "Add" button.&#x20;
* Your Starknet wallet will open a prompt to sign the transaction. Click on "Confirm" to complete the transaction.

<figure><img src="https://3647710270-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTtqAy9sEg9xS0BQqt6LI%2Fuploads%2Ft3IOCU87WYaPeC6kXpLI%2F%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202024-02-11%20%D0%B2%2018.31.08.png?alt=media&amp;token=e0cfe927-e635-4bb8-8d46-4fca85dc44f1" alt=""><figcaption></figcaption></figure>

## 5. Wait for the transaction to be confirmed

This should take a couple of seconds.\
\
All done! Congratulations, you are now a liquidity provider in JediSwap!


# How to ZAP

## What is Zap?

ZAP unveils an innovative capability that allows users to efficiently convert any token into an LP token with just a single swap. This innovation holds immense value, as it not only accelerates the process but also reduces both time and gas fees involved in converting a diverse range of tokens into LP tokens.

*It's important to note, however, that ZAP might occasionally lead to elevated slippage, especially when the token being zapped has low liquidity itself.*

### **There are two ways in which you can use the ZAP feature on JediSwap:**

1. [ZAP from Ethereum L1 to Starknet.](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-zap/how-to-zap-from-ethereum-l1-to-starknet)
2. [ZAP directly on Starknet.](https://docs.jediswap.xyz/how-to-use-jediswap/how-to-zap/how-to-zap-on-starknet)

<br>


# How to ZAP from Ethereum L1 to Starknet

### 1. Select the desired tokens and quantity.

* Head over to the JediSwap ZAP [page](https://app.jediswap.xyz/#/zap).

<figure><img src="https://lh4.googleusercontent.com/-KFdL8XILHqrW1tv0UvmpWW2Yec5Gsm8jM_AKBbGOyxEdcg4-tW_gQcgCkBPcn7w-XKuXLian4kVCKgGqXfZXiQGGM5D1ONWgxKQZdb8QaBYLIBVqrEORC5ZelvjTl_nvgvYwiATms9pFIB3fpBA2es" alt=""><figcaption></figcaption></figure>

* Click on "Select Token" within the "From" graph to select the first token.

<figure><img src="https://lh6.googleusercontent.com/9Ks4S54AGFAuy6tlFUfuSAXnKh0_xgDT30M6CYphNNsvu1ai8uA1kbGGBIxild8gGesfy7TzhHNBz1RyOZhjDB4t67JpyTcVvcatk0uFd6fnuG9-cS-pCpjAbnsncRumtcWF1e-YgkwCBTD2OljHzTU" alt=""><figcaption></figcaption></figure>

* Ensure that Ethereum is chosen as the source chain.
* Select the token that you wish to convert into a LP position.

<figure><img src="https://lh3.googleusercontent.com/qvWw0jQKLC5k1SGvhNZCtQDIhXxAAcM7QwR9-VLqQusEaFlDhooSn-kQ6tKSpSi1B_mGKlZ3ScsXVFWhKKnoHeK6fbtSdOFfHjllH2Eo9HQf-OocEwtUk-KRozIb1bCxRQ8xj7lxeqgavURgCfTSKNM" alt=""><figcaption></figcaption></figure>

* Click on "Select Token" to proceed with selecting the desired LP token.

<figure><img src="https://lh3.googleusercontent.com/-FZpABWKWbHKckEGE8I-QxL02alJKaA5LEx9zq6lYG8cvGrOr5rLCHDt7lfJhM5yQhJd7ccqH_SQlAw5LKXSr9U2F1cr4vEICtu2SF8CX3YaAqPF7gZUN5SXA2pMV3jmIRPTzxb8DOEq-ao7LFHdL4I" alt=""><figcaption></figcaption></figure>

* Select the LP token you would like to receive.

<figure><img src="https://lh4.googleusercontent.com/1KOiyYcLUvaYA8jLuq6KpeI15PpZ6upj1GPnrIQ39tv7T2x4EVm28vWwGpEWRanmxhtD6IuZhizHDHlJnneS6hbQo_49xWXyugGFF10cLvxyQMLbCRl-K3fJnETvlQqCgpBlq6iW2qbLLxq0WacuCt4" alt=""><figcaption></figcaption></figure>

* Connect your Metamask (or other Ethereum L1) wallet by clicking on the "Connect Ethereum Wallet" button.
* Make sure that you connecting to [app.jediswap.xyz](https://app.staging.jediswap.xyz).
* Click on "Connect" to link your Metamask wallet.

<figure><img src="https://lh6.googleusercontent.com/O0NWkGXZBjRN66JKmdTiOiOPj60kGoExJ5Fx1056K59myixQk_jaTCvq2Zg8OokJn4EEBa8k5pNq-BGNZMTH1rKzJ4zWC0Z3NeMtDuxiYOpXNVELT3Qp5Lv_qv9ayhmpe20kJHWI8vZ4ZqjJkt_8KeA" alt=""><figcaption></figcaption></figure>

* Input the quantity of the tokens you wish to provide liquidity with, and you will be shown the corresponding amount of LP tokens you'll obtain.

### 2. Review and confirm your transaction

* After inputting the desired amount, click on the "Review" button. Examine the specifics of your ZAP transaction, such as the anticipated LP token quantity, fee, slippage tolerance, etc. Once you've assessed the transaction details, proceed by clicking on "Confirm."

<figure><img src="https://lh5.googleusercontent.com/m6znh-AZBrNrpbMhjI4lCwPSV7M2k2R83MrMMNEu7d_DKHo3WO4y92ZlZ24ntfCRMEnVQ5mbyYsj967gJQNzAL3l-YWY3RJl_xyVpcXX9P4qBp6VDXya2bqLn5uA9l29R469tRqTIkax5tp_4RKQn24" alt=""><figcaption></figcaption></figure>

### 3. Sign the ZAP transaction

* After clicking on the "Confirm" button, your Metamask Wallet will prompt you to sign the ZAP transaction.

<figure><img src="https://lh4.googleusercontent.com/0ljUwufSB2Cpf1hhRhZrra-nbqadUZ7VAPrQmO1DSmWJekibjE3_ruamK8w9xztNo1DHDcB9Tq4uNtqINXP_BTVylcIQXF28G8kBp3ikw7RTmmiKl_PQxiGeIQ3IjgRKgp0vzO9Gq3F0FVTGxtTfs6U" alt=""><figcaption></figcaption></figure>

* To finalize the transaction, simply click on the "Confirm" button.

### 4. Wait for the transaction to be confirmed&#x20;

This should take a couple of seconds.

<figure><img src="https://lh3.googleusercontent.com/AIkHYskUKr8orJnPXPxOLCkBi954bFiQ4ntRqC5ptPwm9JXzjzYeaKXTXMsc41oiITdJDZU3OgH6p0QXZCD5GJGTwRaTLgiFIXtn-2xDc9pB7SxV73gpeoxcMbghJItunid_JqoF4YhRRJW6HYRbe6g" alt=""><figcaption></figcaption></figure>

<br>


# How to ZAP on Starknet

### 1. Select the desired tokens and quantity.

* Head over to the JediSwap ZAP [page](https://app.jediswap.xyz/#/zap).

<figure><img src="https://lh4.googleusercontent.com/SO6-SH-LMslTzP99-ACoF7pode3NlEgQrg2Pr9tcBhsyNT54KEY92b08LCSBba7zknJNCoJxSCccnL1PBsqzT9tppOFGa-mwgXUzczbCbN8Ly7Sk_MztU2ONmq4LpzCOZTvWasCJNOsPDCrOP-9-qik" alt=""><figcaption></figcaption></figure>

* Proceed by selecting the token you wish to add to liquidity with.

<figure><img src="https://lh4.googleusercontent.com/LCdZg0il5slBXRGLOIjbr4rRCUNBiEauTCSx5jcdFymRnR1vGpQtovvdI_nkl4WK7a07THB51zuogkPL-7-N26Yq7_ZqxVSWDWn0CWrBf-0z_HVFgEanS5U4SxgewfigfRPJ-QI5V1DSCXcApLCZD7c" alt=""><figcaption></figcaption></figure>

* Select the token you intend to add liquidity with.
* Select the LP token you want to receive.&#x20;
* Input the quantity of tokens with which you intend to provide liquidity with, and you will also be able to see the corresponding amount of LP tokens you'll obtain.&#x20;

### 2. Review and confirm your transaction

* After inputting the desired amount, click on the "Review" button.&#x20;

<figure><img src="https://lh4.googleusercontent.com/XK_L-lzmgPyiDVus6sVjfeDnp2qaFtP5L2_9fqcUIf4Nc6fQ95iw91AXDtbx0VvcHKyqAEnL1aIssCyNJMXFVZQRlifoBgqJHLFF8sHSU1Q1qy3Llkfkj5rp2wPnbHud6nzSPY3cGJKxck_0G8PmsVk" alt=""><figcaption></figcaption></figure>

* Examine the specifics of your ZAP transaction, such as the anticipated LP token quantity, fee, slippage tolerance, etc. Once you've assessed the transaction details, proceed by clicking on "Confirm".

### 3. Sign the ZAP transaction

* After clicking on the "Confirm" button, your Starknet Wallet *(Argent X, Braavos, Argent Web Wallet)* will display a prompt, asking you to sign the ZAP transaction.&#x20;

<figure><img src="https://lh5.googleusercontent.com/FreESBwjIRF-lgBIYp37nK8RZn_E78wWLoJz1L-Mcg9YBLVME86y7KC7aBmc37QT5my7gZxZMW4QrMXU7WkRpYHt6OHFeFBIcVho4A_8CPbpHG49D1UYvjcrDJ_zdCuug4qqsXsBfb-eO2ATRoMkPS0" alt=""><figcaption></figcaption></figure>

* To finalize the transaction, simply click on the "Sign" option.<br>

### 4. Wait for the transaction to be confirmed&#x20;

This should take a couple of seconds.

<figure><img src="https://lh6.googleusercontent.com/JRrZafqFEQZGgpGjS_J_qi_x1AoxJ-_WrIwyey9GAxuXpqco-tkYrn7K59tOujQ7oVo4PWVcBrs0YTWFqx9sGffjqK2zgr6TdivUgAL5UgVlf_mNEcwSrKFcKwH4cxiyxmATcO_MNGZHcDHBe5zIdJg" alt=""><figcaption></figcaption></figure>

<br>


# Points

This section is work in progres.


# LP Leaderboard

A reflection of how much value an LP added to Jediswap AMM relative to others LPs.

<mark style="color:red;">Note: this leaderboard is only for Jediswap v2 right now. We will soon publish a formula to calculate Jediswap v1 points and retroactively assign points for past LPs.</mark>

Users need to earn LP points to get into the Jediswap LP leaderboard.&#x20;

In short, Jediswap LP points are designed to reflect the value added by different users as a liquidity provider relative to other liquidity providers. The LP points formula is designed to give more points to authentic and loyal users in the most effective way possible. It takes into account the productivity and loyalty of a liquidity provider.&#x20;

## LP points formula

$$
P\_u =  \sum\_{i=1}^nP\_u^i
$$

$$P\_u$$ = LP points for a user address "u"

$$P\_u^i$$ = LP points for position "i" for the user address "u"

n = total number of LP positions of user address "u"

$$
P\_u^i  =  \sum\_{d=1}^nP\_u^i(d)
$$

$$P\_u^i(d)$$ = Points earned by a position on a day "d"

The points calculation for a day is broken into periods from " the previous day 00:00 UTC to any "increase/decrease liquidity event" until the current day's 00:00 UTC and then summed together.&#x20;

For example, if Alice had a $100 position at 00:00 UTC the previous day, she removed $50 at 01:00 UTC, added $50 again at 02:00 UTC, and kept it until 00:00 UTC the next day. We will calculate her points in 3 periods.

1. 00:00 UTC of the previous day till 01:00 UTC
2. 01:00 UTC till 02:00 UTC
3. 02:00 UTC till 00:00 UTC of the next day

For a period, here is how the Points calculation happens.

$$
P\_u^i(d) = \sum\_{p=1}^x F\_u^i(p) \* T\_u^i(p) \* pool boost(p) \* 1000
$$

$$x$$ = total number of periods for the day

As you see, three factors play a part in measuring LP points for a liquidity position.

$$F\_u^i(p)$$ = Fee earned by position "i" of user "u" in period "p"

$$T\_u^i(p)$$= Time vested multiplier for the position "i" of user "u" for period "p"

$$pool boost(p)$$ = a multiplier based on the liquidity Pool during the period "p"

We do this computation at 00:00 UTC every day.

## Fees earned by the position in USD:

Including fees earned as a factor helps Jediswap become more efficient for traders. Since only active positions earn fees, it incentivises liquidity providers to add liquidity within a range that can reduce traders' slippage. Fees accrued by all positions are computed for different periods every day.

## Time vested multiplier

Time vested in a position helps the Jediswap community align its focus on sticky liquidity. The more sticky liquidity, the more consistently Jediswap offers the best prices. The value of $$T\_u^i$$ starts with 0 and increases with every block as liquidity is in the pool. Here is how the time vested multiplier is calculated for a period.

$$
T\_u^i = min(1, (T\_u^i + s/FVP)
$$

FVP(Full vesting period) = 1296000 (15 days in seconds)

s = time in seconds for a period

When a user calls “decrease liquidity”, the value of $$T\_u^i$$ resets to 0.

When a user calls "increase liquidity", the value of $$T\_u^i$$ resets to $$T\_u^i \* 1/r$$

Where $$r = TVL\_(new)/TVL\_(old)$$

$$TVL\_(old)$$ is LP position's old TVL before the "increase liquidity"

$$TVL\_(new)$$ is LP position's new TVL after the "increase liquidity"

## Pool boost

The pool boost helps the Jediswap community align its focus towards the pools that add the most value during a given time period. For example, if, at some point in time, the Jediswap community wants to gain market share in a new token pool, the pool boost helps with that. The Jediswap problem-solving guild decides the pool boost for different pools for a time. Pool boost can range from 1 to 3. The default value of pool boost is 1 for eligible pools.&#x20;

Current pool boost for different pools

Eligible pools - Any pools with one of the tokens from ETH, WBTC, USDC, USDT, DAI

* ETH - USDC - 2
* USDC - USDT - 2
* STRK - ETH - 3
* STRK - USDC - 3
* All other pools - 1

## Example&#x20;

Lets say, Alice had a time-vested multiplier value from the previous day, 3/15

Pool boost = 1

The next day, she decreased liquidity by 50% at 01:00 UTC and then increased liquidity by 100% at 02:00 UTC.

We will calculate her points in 3 periods and then sum them together.

1. From 00:00 UTC the previous day until 01:00 UTC. Let's say during this period, she earned $1 in fees.
2. 01:00 UTC till 02:00 UTC. Let's say in this period, she earns $0.5 in fees.
3. 02:00 UTC until 00:00 UTC the next day. Let's say she earns $4 in fees during this period.

**1st-period calculation**&#x20;

Time vested multiplier = min(1, 3/15+10000/1296000) = 3/15+10000/1296000 =&#x20;

$$P\_1$$ = 1\*(3/15+10000/1296000)\*1\*1000 = 207

**2nd-period calculation**&#x20;

The time vested multiplier will first reset to 0 and then increase. &#x20;

Time vested multiplier = min (1, 0+40000/1296000) = 40000/1296000 = 0.20771604938

$$P\_2$$ = 0.5\*(40000/1296000)\*1\*1000 = 15

**3rd-period calculation**&#x20;

The time vested multiplier will first reset to $$T\_(perviousperiod)/r$$ and then increase.

r = 2 since liquidity was increased by 100%

$$T\_(pervious period)$$ = 0.20771604938

Time left 22 hours(from 02:00 UTC till 23:59 UTC) = 79200

Time vested multiplier =  min(1, 0.20771604938 + 79200/1296000) = 0.26882716049

$$P\_3$$ = 4\*0.26882716049\*1\*1000 = 1075

Her total points for the day = $$P\_1+P\_2+P\_3$$ = 207 + 15 + 1075 = 1297

Now, for the next day, the value of the Time vested multiplier will start from 0.26882716049.<br>

\ <br>


# Volume Leaderboard

A reflection of how much value a trader added to Jediswap AMM relative to others traders

Users need to earn Volume points to get into the Jediswap Volume leaderboard.&#x20;

Jediswap volume points reflect the value added by different users as traders relative to other traders. The volume points formula is designed to reward authentic traders in the most effective way possible.&#x20;

A user earns volume points for each swap based on certain conditions.

\
The formula to calculate the volume points is as below
------------------------------------------------------

{% code overflow="wrap" %}

```
Volume points for an address = sum of volume points for all swaps of that address

Volume points for a swap = swap fee(USD value) * Early adopter multiplier * Sybil multiplier * 1000
```

{% endcode %}

## Swap Fee paid&#x20;

Including swap fees as a factor helps Jediswap measure traders’ impact on the LPs of a pair. The more fees traders pay, the more fees liquidity providers earn, which attracts more users to add liquidity.

## Early adopter multiplier

The early adopter multiplier helps the Jediswap community align incentives for early users. Usually, the earlier the users come, the more expensive the DEX is for them and the more value they add in spinning up the network effects. Hence, the value of the early adopter multiplier will gradually decrease as Jediswap grows. The problem-solving guild decides the early adopter multiplier for a period of time. The current early adopter multiplier is 3.

## Sybil multiplier

The biggest challenge in measuring volume points is rewarding authentic users and not driving wash trading. Solving this will always have tradeoffs, but the tradeoffs should be transparent. To create a balance for each swap, we check if the swap fee paid was higher than the 25 percentile of the swaps. If the swap fee paid was higher than the bottom 25% of the swap fees paid, then it gets a multiplier of 1 otherwise it gets a multiplier of 0.

It means only the top 75% swaps by fee paid earns the daily volume points.

## Example&#x20;

Alice swapped $100 worth of ETH in USDC on March 3rd, ’24, and paid $0.3 in swap fees. If 100 swaps were made on March 3rd, we would order all 100 swaps in decreasing order based on the swap fee paid. Then, we will check how much fee the 76th swap paid. Let’s say the 76th swap paid $0.1 in fees. Here will be the volume points for Alice on March 3rd for that swap.

Early adopter multiplier = 3

Sybil multiplier = 1 (since $0.3 > $0.1)

Alice’s points = 0.3 \* 3 \* 1 \* 1000 = 900

\ <br>

<br>


# Jediswap v2

## Overview

JediSwap V2 is a Cairo fork of Uniswap V3. The smart contract system comprises of many libraries, which together make the Core and Periphery.

Core contracts provide fundamental safety guarantees for all parties interacting with JediSwap. They define the logic of pool generation, the pools themselves, and the interactions involving the respective assets therein.

Periphery contracts interact with one or more Core contracts but are not part of the core. They are designed to provide methods of interacting with the core that increase clarity and user safety.

External calls will primarily call the periphery interfaces. Externally available functions are all viewable in the reference documentation. Internal functions are viewable on the JediSwap V2 Github repo.

### Core <a href="#core" id="core"></a>

> [**Core Source Code**](https://github.com/jediswaplabs/JediSwap-v2-core)

The core consists of a factory and a pool deployer contract. The factory creates the pools.

#### Factory <a href="#factory" id="factory"></a>

> [**Factory Reference**](/for-developers/jediswap-v2/core/jediswap_v2_factory)

The factory defines the logic for generating pools. A pool is defined by two tokens, which make up the asset pair, and a fee. There can be multiple pools of the same asset pair, distinguished only by their swap fee.

#### Pools <a href="#pools" id="pools"></a>

> [**Pool Reference**](/for-developers/jediswap-v2/core/jediswap_v2_pool)

Pools primarily serve as automated market makers for the paired assets.

### Periphery <a href="#periphery" id="periphery"></a>

> [**Periphery Source Code**](https://github.com/jediswaplabs/JediSwap-v2-periphery)

The periphery is a constellation of smart contracts designed to support interactions with the core. As the protocol is a permissionless system, the contracts described below have no special privileges and are only a small subset of possible periphery-like contracts.

#### SwapRouter <a href="#swaprouter" id="swaprouter"></a>

> [**Swap Router Reference**](/for-developers/jediswap-v2/periphery/jediswap_v2_swap_router)

> [**Swap Router Interface**](/for-developers/jediswap-v2/periphery/jediswap_v2_swap_router#abi)

The swap router supports all the basic requirements of a front-end offering trading. It natively supports single trades (x to y) and multihop trades (e.g. x to y to z).

#### NFT Position Manager <a href="#nftpositionmanager" id="nftpositionmanager"></a>

> [**NFT Position Manager Reference**](/for-developers/jediswap-v2/periphery/jediswap_v2_nft_position_manager)

> [**NFT Position Manager Interface**](/for-developers/jediswap-v2/periphery/jediswap_v2_nft_position_manager#abi)

The position manager handles the logic transactions involving the creation, adjustment, or exiting of positions.


# Core


# jediswap\_v2\_factory

Deploys JediSwap V2 pools and manages ownership and control over protocol fees

### Functions <a href="#functions" id="functions"></a>

#### create\_pool <a href="#create_pool" id="create_pool"></a>

{% code overflow="wrap" %}

```rust
fn create_pool(ref self: ContractState, token_a: ContractAddress, token_b: ContractAddress, fee: u32) -> ContractAddress
```

{% endcode %}

Creates a pool for the given two tokens and fee

token\_a and token\_b may be passed in either order: token0/token1 or token1/token0. tick\_spacing is retrieved from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments are invalid.&#x20;

Emits [PoolCreated](#poolcreated).

**Parameters:**

| Name      | Type            | Description                                     |
| --------- | --------------- | ----------------------------------------------- |
| `token_a` | ContractAddress | One of the two tokens in the desired pool       |
| `token_b` | ContractAddress | The other of the two tokens in the desired pool |
| `fee`     | u32             | The desired fee for the pool                    |

**Return Values:**

| Type            | Description                           |
| --------------- | ------------------------------------- |
| ContractAddress | The address of the newly created pool |

#### enable\_fee\_amount <a href="#enable_fee_amount" id="enable_fee_amount"></a>

```rust
fn enable_fee_amount(ref self: ContractState, fee: u32, tick_spacing: u32)
```

Enables a fee amount with the given tick\_spacing

Fee amounts may never be removed once enabled

Caller is the owner

Emits [FeeAmountEnabled](#feeamountenabled).

**Parameters:**

| Name           | Type | Description                                                                              |
| -------------- | ---- | ---------------------------------------------------------------------------------------- |
| `fee`          | u32  | The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)                 |
| `tick_spacing` | u32  | The spacing between ticks to be enforced for all pools created with the given fee amount |

#### set\_fee\_protocol <a href="#set_fee_protocol" id="set_fee_protocol"></a>

```rust
fn set_fee_protocol(ref self: ContractState, fee_protocol: u8)
```

Sets the denominator of the protocol's share of the fees

Caller is the owner

Emits [SetFeeProtocol](#setfeeprotocol).

**Parameters:**

| Name           | Type | Description      |
| -------------- | ---- | ---------------- |
| `fee_protocol` | u8   | New protocol fee |

#### transfer\_ownership <a href="#transfer_ownership" id="transfer_ownership"></a>

{% code overflow="wrap" %}

```rust
fn transfer_ownership(ref self: ComponentState<TContractState>, new_owner: ContractAddress)
```

{% endcode %}

Transfers ownership of the contract to a new address

Caller it the owner

Emits [OwnershipTransferred](#ownershiptransferred).

**Parameters:**

| Name       | Type            | Description                   |
| ---------- | --------------- | ----------------------------- |
| new\_owner | ContractAddress | The new owner of the contract |

#### renounce\_ownership <a href="#renounce_ownership" id="renounce_ownership"></a>

```rust
fn renounce_ownership(ref self: ComponentState<TContractState>)
```

Leaves the contract without the owner. It will not be possible to call the owner only functions anymore. It can only be called by the current owner.

Emits [OwnershipTransferred](#ownershiptransferred).

**Parameters:**

| Name           | Type | Description      |
| -------------- | ---- | ---------------- |
| `fee_protocol` | u8   | New protocol fee |

### Events <a href="#events" id="events"></a>

#### PoolCreated <a href="#poolcreated" id="poolcreated"></a>

```rust
struct PoolCreated {
    token0: ContractAddress,
    token1: ContractAddress,
    fee: u32,
    tick_spacing: u32,
    pool: ContractAddress
}
```

**Parameters:**

| Name          | Type            | Description                                                                       |
| ------------- | --------------- | --------------------------------------------------------------------------------- |
| `token0`      | ContractAddress | The first token of the pool by address sort order                                 |
| `token1`      | ContractAddress | The second token of the pool by address sort order                                |
| `fee`         | u32             | The fee collected upon every swap in the pool, denominated in hundredths of a bip |
| tick\_spacing | u32             | The minimum number of ticks between initialized ticks                             |
| pool          | ContractAddress | The address of the created pool                                                   |

#### FeeAmountEnabled

```rust
struct FeeAmountEnabled {
    fee: u32,
    tick_spacing: u32
}
```

**Parameters:**

| Name           | Type | Description                                                                                |
| -------------- | ---- | ------------------------------------------------------------------------------------------ |
| `fee`          | u32  | The enabled fee, denominated in hundredths of a bip                                        |
| `tick_spacing` | u32  | The minimum number of ticks between initialized ticks for pools created with the given fee |

#### SetFeeProtocol <a href="#setfeeprotocol" id="setfeeprotocol"></a>

```rust
struct SetFeeProtocol {
    old_fee_protocol: u8,
    new_fee_protocol: u8
}
```

**Parameters:**

| Name               | Type | Description                            |
| ------------------ | ---- | -------------------------------------- |
| `old_fee_protocol` | u8   | The previous value of the protocol fee |
| new`_fee_protocol` | u8   | The updated value of the protocol fee  |

#### OwnershipTransferred

```rust
struct OwnershipTransferred {
    previous_owner: ContractAddress,
    new_owner: ContractAddress,
}
```

**Parameters:**

| Name             | Type            | Description                                               |
| ---------------- | --------------- | --------------------------------------------------------- |
| `previous_owner` | ContractAddress | The previous owner of the contract                        |
| `new_owner`      | ContractAddress | The new owner of the contract. Can be 0 while renouncing. |

### ABI <a href="#abi" id="abi"></a>

```rust
#[starknet::interface]
trait IJediSwapV2Factory<TContractState> {
    fn fee_amount_tick_spacing(self: @TContractState, fee: u32) -> u32;
    fn get_pool(self: @TContractState, token_a: ContractAddress, token_b: ContractAddress, fee: u32) -> ContractAddress;
    fn get_fee_protocol(self: @TContractState) -> u8;
    
    fn create_pool(ref self: TContractState, token_a: ContractAddress, token_b: ContractAddress, fee: u32) -> ContractAddress;
    fn enable_fee_amount(ref self: TContractState, fee: u32, tick_spacing: u32);
    fn set_fee_protocol(ref self: TContractState, fee_protocol: u8);
}

#[starknet::interface]
trait IOwnable<TState> {
    fn owner(self: @TState) -> ContractAddress;
    fn transfer_ownership(ref self: TState, new_owner: ContractAddress);
    fn renounce_ownership(ref self: TState);
}
```


# jediswap\_v2\_pool

### Functions <a href="#functions" id="functions"></a>

#### initialize <a href="#initialize" id="initialize"></a>

```rust
fn initialize(ref self: ContractState, sqrt_price_X96: u256)
```

Sets the initial price for the pool

Emits [Initialize](#event-initialize).

**Parameters:**

| Name             | Type | Description                                    |
| ---------------- | ---- | ---------------------------------------------- |
| sqrt\_price\_X96 | u256 | The initial sqrt price of the pool as a Q64.96 |

#### mint <a href="#mint" id="mint"></a>

{% code overflow="wrap" fullWidth="false" %}

```rust
fn mint(ref self: ContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount: u128, data: Array<felt252>) -> (u256, u256)
```

{% endcode %}

Adds liquidity for the given recipient/tick\_lower/tick\_upper position

The caller of this method receives a callback in the form of [jediswap\_v2\_mint\_callback](/for-developers/jediswap-v2/periphery/jediswap_v2_nft_position_manager#jediswap_v2_mint_callback) in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends on tick\_lower, tick\_upper, the amount of liquidity, and the current price.

Emits [Mint](#event-mint).

**Parameters:**

| Name        | Type            | Description                                              |
| ----------- | --------------- | -------------------------------------------------------- |
| recipient   | ContractAddress | The address for which the liquidity will be created      |
| tick\_lower | i32             | The lower tick of the position in which to add liquidity |
| tick\_upper | i32             | The upper tick of the position in which to add liquidity |
| amount      | u128            | The amount of liquidity to mint                          |
| data        | Array\<felt252> | Any data that should be passed through to the callback   |

**Return Values:**

| Type | Description                                                                                                 |
| ---- | ----------------------------------------------------------------------------------------------------------- |
| u256 | The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback |
| u256 | The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback |

#### collect <a href="#collect" id="collect"></a>

{% code overflow="wrap" %}

```rust
fn collect(ref self: ContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128)
```

{% endcode %}

Collects tokens owed to a position

It does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. Collect must be called by the position owner. To withdraw only token0 or only token1, amount0\_requested or amount1\_requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. BoundedInt::\<u128>::max(). Tokens owed may be from accumulated swap fees or burned liquidity.

Emits [Collect](#event-collect).

**Parameters:**

| Name               | Type            | Description                                              |
| ------------------ | --------------- | -------------------------------------------------------- |
| recipient          | ContractAddress | The address which should receive the fees collected      |
| tick\_lower        | i32             | The lower tick of the position for which to collect fees |
| tick\_upper        | i32             | The upper tick of the position for which to collect fees |
| amount0\_requested | u128            | How much token0 should be withdrawn from the fees owed   |
| amount1\_requested | u128            | How much token1 should be withdrawn from the fees owed   |

**Return Values:**

| Type | Description                            |
| ---- | -------------------------------------- |
| u128 | The amount of fees collected in token0 |
| u128 | The amount of fees collected in token1 |

#### burn <a href="#burn" id="burn"></a>

{% code overflow="wrap" %}

```rust
fn burn(ref self: ContractState, tick_lower: i32, tick_upper: i32, amount: u128) -> (u256, u256)
```

{% endcode %}

Burn liquidity from the sender and account tokens owed for the liquidity to the position

It can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0. Fees must be collected separately via a call to [collect](#collect).

Emits [Burn](#event-burn).

**Parameters:**

| Name        | Type | Description                                                |
| ----------- | ---- | ---------------------------------------------------------- |
| tick\_lower | i32  | The lower tick of the position for which to burn liquidity |
| tick\_upper | i32  | The upper tick of the position for which to burn liquidity |
| amount      | u128 | How much liquidity to burn                                 |

**Return Values:**

| Type | Description                                |
| ---- | ------------------------------------------ |
| u256 | The amount of token0 sent to the recipient |
| u256 | The amount of token1 sent to the recipient |

#### swap <a href="#swap" id="swap"></a>

{% code overflow="wrap" %}

```rust
fn swap(ref self: ContractState, recipient: ContractAddress, zero_for_one: bool, amount_specified: i256, sqrt_price_limit_X96: u256, data: Array<felt252>) -> (i256, i256)
```

{% endcode %}

Swap token0 for token1, or token1 for token0

The caller of this method receives a callback in the form of [jediswap\_v2\_swap\_callback](/for-developers/jediswap-v2/periphery/jediswap_v2_swap_router#jediswap_v2_swap_callback)

Emits [Swap](#event-swap).

**Parameters:**

| Name                    | Type            | Description                                                                                                                                                                        |
| ----------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| recipient               | ContractAddress | The address to receive the output of the swap                                                                                                                                      |
| zero\_for\_one          | bool            | The direction of the swap, true for token0 to token1, false for token1 to token0                                                                                                   |
| amount\_specified       | i256            | The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)                                                                 |
| sqrt\_price\_limit\_X96 | u256            | The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap |
| data                    | Array\<felt252> | Any data to be passed through to the callback                                                                                                                                      |

**Return Values:**

| Type | Description                                                                                |
| ---- | ------------------------------------------------------------------------------------------ |
| i256 | The delta of the balance of token0 of the pool, exact when negative, minimum when positive |
| i256 | The delta of the balance of token1 of the pool, exact when negative, minimum when positive |

#### collect\_protocol <a href="#collect_protocol" id="collect_protocol"></a>

{% code overflow="wrap" %}

```rust
fn collect_protocol(ref self: ContractState, recipient: ContractAddress, amount0_requested: u128, amount1_requested: u128) -> (u128, u128)
```

{% endcode %}

Collect the protocol fee accrued to the pool

Only the factory owner can call this function.

Emits [CollectProtocol](#event-collectprotocol).

**Parameters:**

| Name               | Type            | Description                                                                   |
| ------------------ | --------------- | ----------------------------------------------------------------------------- |
| recipient          | ContractAddress | The address to which collected protocol fees should be sent                   |
| amount0\_requested | u128            | The maximum amount of token0 to send, can be 0 to collect fees in only token1 |
| amount1\_requested | u128            | The maximum amount of token1 to send, can be 0 to collect fees in only token0 |

**Return Values:**

| Type | Description                          |
| ---- | ------------------------------------ |
| u128 | The protocol fee collected in token0 |
| u128 | The protocol fee collected in token1 |

### Events <a href="#events" id="events"></a>

#### Initialize <a href="#event-initialize" id="event-initialize"></a>

```rust
struct Initialize {
    sqrt_price_X96: u256,
    tick: i32
}
```

Emitted exactly once by a pool when [initialize](#initialize) is first called on the pool

Mint/Burn/Swap cannot be emitted by the pool before Initialize

**Parameters:**

| Name             | Type | Description                                                                          |
| ---------------- | ---- | ------------------------------------------------------------------------------------ |
| sqrt\_price\_X96 | u256 | The initial sqrt price of the pool, as a Q64.96                                      |
| tick             | i32  | The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool |

#### Mint <a href="#event-mint" id="event-mint"></a>

```rust
struct Mint {
    sender: ContractAddress,
    owner: ContractAddress,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name        | Type            | Description                                                     |
| ----------- | --------------- | --------------------------------------------------------------- |
| sender      | ContractAddress | The address that minted the liquidity                           |
| owner       | ContractAddress | The owner of the position and recipient of any minted liquidity |
| tick\_lower | i32             | The lower tick of the position                                  |
| tick\_upper | i32             | The upper tick of the position                                  |
| amount      | u128            | The amount of liquidity minted to the position range            |
| amount0     | u256            | How much token0 was required for the minted liquidity           |
| amount1     | u256            | How much token1 was required for the minted liquidity           |

#### Collect <a href="#event-collect" id="event-collect"></a>

Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees

```rust
struct Collect {
    owner: ContractAddress,
    recipient: ContractAddress,
    tick_lower: i32,
    tick_upper: i32,
    amount0: u128,
    amount1: u128
}
```

**Parameters:**

| Name        | Type            | Description                                            |
| ----------- | --------------- | ------------------------------------------------------ |
| owner       | ContractAddress | The owner of the position for which fees are collected |
| recipient   | ContractAddress | The address which should receive the fees collected    |
| tick\_lower | i32             | The lower tick of the position                         |
| tick\_upper | i32             | The upper tick of the position                         |
| amount0     | u128            | The amount of token0 fees collected                    |
| amount1     | u128            | The amount of token1 fees collected                    |

#### Burn <a href="#event-burn" id="event-burn"></a>

```rust
struct Burn {
    owner: ContractAddress,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name        | Type            | Description                                              |
| ----------- | --------------- | -------------------------------------------------------- |
| owner       | ContractAddress | The owner of the position for which liquidity is removed |
| tick\_lower | i32             | The lower tick of the position                           |
| tick\_upper | i32             | The upper tick of the position                           |
| amount      | u128            | The amount of liquidity to remove                        |
| amount0     | u256            | The amount of token0 withdrawn                           |
| amount1     | u256            | The amount of token1 withdrawn                           |

#### Swap <a href="#event-swap" id="event-swap"></a>

```rust
struct Swap {
    sender: ContractAddress,
    recipient: ContractAddress,
    amount0: i256,
    amount1: i256,
    sqrt_price_X96: u256,
    liquidity: u128,
    tick: i32
}
```

**Parameters:**

| Name             | Type            | Description                                                              |
| ---------------- | --------------- | ------------------------------------------------------------------------ |
| sender           | ContractAddress | The address that initiated the swap call, and that received the callback |
| recipient        | ContractAddress | The address that received the output of the swap                         |
| amount0          | i256            | The delta of the token0 balance of the pool                              |
| amount1          | i256            | The delta of the token1 balance of the pool                              |
| sqrt\_price\_X96 | u256            | The sqrt(price) of the pool after the swap, as a Q64.96                  |
| liquidity        | u128            | The liquidity of the pool after the swap                                 |
| tick             | i32             | The log base 1.0001 of price of the pool after the swap                  |

#### CollectProtocol <a href="#event-collectprotocol" id="event-collectprotocol"></a>

```rust
struct CollectProtocol {
    sender: ContractAddress,
    recipient: ContractAddress,
    amount0: u128,
    amount1: u128
}
```

**Parameters:**

| Name      | Type            | Description                                           |
| --------- | --------------- | ----------------------------------------------------- |
| sender    | ContractAddress | The address that collects the protocol fees           |
| recipient | ContractAddress | The address that receives the collected protocol fees |
| amount0   | u128            | The amount of token0 protocol fees that is withdrawn  |
| amount1   | u128            | The amount of token1 protocol fees that is withdrawn  |

### ABI <a href="#abi" id="abi"></a>

```rust
//sign true for negative numbers
struct i32 {
    mag: u32,
    sign: bool,
}

//sign true for negative numbers
struct i128 {
    mag: u128,
    sign: bool,
}

//sign true for negative numbers
struct i256 {
    mag: u256,
    sign: bool,
}

struct ProtocolFees {
    // @notice Accumulated protocol fees in token0
    token0: u128,
    // @notice Accumulated protocol fees in token1
    token1: u128
}

struct TickInfo {
    // @notice The total position liquidity that references this tick
    liquidity_gross: u128,
    // @notice Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left),
    liquidity_net: i128,
    // @notice Fee growth for token0 per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    fee_growth_outside_0_X128: u256,
    // @notice Fee growth for token1 per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    fee_growth_outside_1_X128: u256,
}

struct PositionInfo {
    // @notice The amount of liquidity owned by this position
    liquidity: u128,
    // @notice Fee growth of token0 per unit of liquidity as of the last update to liquidity or fees owned
    fee_growth_inside_0_last_X128: u256,
    // @notice Fee growth of token1 per unit of liquidity as of the last update to liquidity or fees owned
    fee_growth_inside_1_last_X128: u256,
    // @notice The fees owed to the position owner in token0
    tokens_owed_0: u128,
    // @notice The fees owed to the position owner in token1
    tokens_owed_1: u128,
}

struct PositionKey {
    // @notice The owner of the position
    owner: ContractAddress,
    // @notice The lower tick of the position's tick range
    tick_lower: i32,
    // @notice The upper tick of the position's tick range
    tick_upper: i32,
}

#[starknet::interface]
trait IJediSwapV2Pool<TContractState> {
    fn get_factory(self: @TContractState) -> ContractAddress;
    fn get_token0(self: @TContractState) -> ContractAddress;
    fn get_token1(self: @TContractState) -> ContractAddress;
    fn get_fee(self: @TContractState) -> u32;
    fn get_tick_spacing(self: @TContractState) -> u32;
    fn get_max_liquidity_per_tick(self: @TContractState) -> u128;
    fn get_sqrt_price_X96(self: @TContractState) -> u256;
    fn get_tick(self: @TContractState) -> i32;
    fn get_fee_protocol(self: @TContractState) -> u8;
    fn get_fee_growth_global_0_X128(self: @TContractState) -> u256;
    fn get_fee_growth_global_1_X128(self: @TContractState) -> u256;
    fn get_protocol_fees(self: @TContractState) -> ProtocolFees;
    fn get_liquidity(self: @TContractState) -> u128;
    fn get_tick_info(self: @TContractState, tick: i32) -> TickInfo;
    fn get_position_info(self: @TContractState, position_key: PositionKey) -> PositionInfo;
    fn static_collect(self: @TContractState, owner: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128);
    
    fn initialize(ref self: TContractState, sqrt_price_X96: u256);
    fn mint(ref self: TContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount: u128, data: Array<felt252>) -> (u256, u256);
    fn collect(ref self: TContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128);
    fn burn(ref self: TContractState, tick_lower: i32, tick_upper: i32, amount: u128) -> (u256, u256);
    fn swap(ref self: TContractState, recipient: ContractAddress, zero_for_one: bool, amount_specified: i256, sqrt_price_limit_X96: u256, data: Array<felt252>) -> (i256, i256);
    fn collect_protocol(ref self: TContractState, recipient: ContractAddress, amount0_requested: u128, amount1_requested: u128) -> (u128, u128);
}
```


# Periphery


# jediswap\_v2\_nft\_position\_manager

Wraps JediSwap V2 positions in the ERC721 non-fungible token interface

### Functions <a href="#functions" id="functions"></a>

#### mint <a href="#mint" id="mint"></a>

```rust
fn mint(ref self: ContractState, params: MintParams) -> (u256, u128, u256, u256)
```

Creates a new position wrapped in a NFT

Call this when the pool does exist and is initialized

Emits [IncreaseLiquidity](#event_increaseliquidity).

**Parameters:**

| Name   | Type       | Description                             |
| ------ | ---------- | --------------------------------------- |
| params | MintParams | The params necessary to mint a position |

**Return Values:**

| Type | Description                                             |
| ---- | ------------------------------------------------------- |
| u256 | The ID of the token that represents the minted position |
| u128 | The amount of liquidity for this position               |
| u256 | The amount of token0                                    |
| u256 | The amount of token1                                    |

#### increase\_liquidity <a href="#increase_liquidity" id="increase_liquidity"></a>

{% code overflow="wrap" %}

```rust
fn increase_liquidity(ref self: ContractState, params: IncreaseLiquidityParams) -> (u128, u256, u256)
```

{% endcode %}

Increases the amount of liquidity in a position, with tokens paid by the caller

Emits [IncreaseLiquidity](#event_increaseliquidity).

**Parameters:**

| Name   | Type                    | Description                                              |
| ------ | ----------------------- | -------------------------------------------------------- |
| params | IncreaseLiquidityParams | The params necessary to increase liquidity of a position |

**Return Values:**

| Type | Description                                          |
| ---- | ---------------------------------------------------- |
| u128 | The new liquidity amount as a result of the increase |
| u256 | The amount of token0 to achieve resulting liquidity  |
| u256 | The amount of token1 to achieve resulting liquidity  |

#### decrease\_liquidity <a href="#decrease_liquidity" id="decrease_liquidity"></a>

{% code overflow="wrap" %}

```rust
fn decrease_liquidity(ref self: ContractState, params: DecreaseLiquidityParams) -> (u256, u256)
```

{% endcode %}

Decreases the amount of liquidity in a position and accounts it to the position

Emits [DecreaseLiquidity](#event_decreaseliquidity).

**Parameters:**

| Name   | Type                    | Description                                              |
| ------ | ----------------------- | -------------------------------------------------------- |
| params | DecreaseLiquidityParams | The params necessary to decrease liquidity of a position |

**Return Values:**

| Type | Description                                                  |
| ---- | ------------------------------------------------------------ |
| u256 | The amount of token0 accounted to the position's tokens owed |
| u256 | The amount of token1 accounted to the position's tokens owed |

#### collect <a href="#collect" id="collect"></a>

```rust
fn collect(ref self: ContractState, params: CollectParams) -> (u128, u128)
```

Collects up to a maximum amount of fees owed to a specific position to the recipient

Emits [Collect](#event_collect).

**Parameters:**

| Name   | Type          | Description                                        |
| ------ | ------------- | -------------------------------------------------- |
| params | CollectParams | The params necessary to collect fees of a position |

**Return Values:**

| Type | Description                            |
| ---- | -------------------------------------- |
| u128 | The amount of fees collected in token0 |
| u128 | The amount of fees collected in token1 |

#### burn <a href="#burn" id="burn"></a>

```rust
fn burn(ref self: ContractState, token_id: u256)
```

Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens must be collected first.

**Parameters:**

| Name      | Type | Description                              |
| --------- | ---- | ---------------------------------------- |
| token\_id | u256 | The ID of the token that is being burned |

#### create\_and\_initialize\_pool <a href="#create_and_initialize_pool" id="create_and_initialize_pool"></a>

{% code overflow="wrap" %}

```rust
fn create_and_initialize_pool(ref self: ContractState, token0: ContractAddress, token1: ContractAddress, fee: u32, sqrt_price_X96: u256) -> ContractAddress
```

{% endcode %}

Creates a new pool if it does not exist, then initializes if not initialized

This method can be bundled with others via multicall for the first action (e.g. mint) performed against a pool

**Parameters:**

| Name             | Type            | Description                                                 |
| ---------------- | --------------- | ----------------------------------------------------------- |
| token0           | ContractAddress | The contract address of token0 of the pool                  |
| token1           | ContractAddress | The contract address of token1 of the pool                  |
| fee              | u32             | The fee amount of the v2 pool for the specified token pair  |
| sqrt\_price\_X96 | u256            | The initial square root price of the pool as a Q64.96 value |

**Return Values:**

| Type            | Description                                                                                                   |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| ContractAddress | The pool address based on the pair of tokens and fee, will return the newly created pool address if necessary |

#### jediswap\_v2\_mint\_callback <a href="#jediswap_v2_mint_callback" id="jediswap_v2_mint_callback"></a>

```rust
fn jediswap_v2_mint_callback(ref self: ContractState, amount0_owed: u256, amount1_owed: u256, callback_data_span: Span<felt252>)
```

**Parameters:**

| Name                 | Type           | Description |
| -------------------- | -------------- | ----------- |
| amount0\_owed        | u256           |             |
| amount1\_owed        | u256           |             |
| callback\_data\_span | Span\<felt252> |             |

### Events <a href="#events" id="events"></a>

#### IncreaseLiquidity <a href="#event_increaseliquidity" id="event_increaseliquidity"></a>

Emitted when liquidity is increased for a position NFT. Also emitted when a token is minted.

```rust
struct IncreaseLiquidity {
    token_id: u256,
    liquidity: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name      | Type | Description                                                      |
| --------- | ---- | ---------------------------------------------------------------- |
| token\_id | u256 | The ID of the token for which liquidity was increased            |
| liquidity | u128 | The amount by which liquidity for the NFT position was increased |
| amount0   | u256 | The amount of token0 that was paid for the increase in liquidity |
| amount1   | u256 | The amount of token1 that was paid for the increase in liquidity |

#### DecreaseLiquidity <a href="#event_decreaseliquidity" id="event_decreaseliquidity"></a>

```rust
struct DecreaseLiquidity {
    token_id: u256,
    liquidity: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name      | Type | Description                                                           |
| --------- | ---- | --------------------------------------------------------------------- |
| token\_id | u256 | The ID of the token for which liquidity was decreased                 |
| liquidity | u128 | The amount by which liquidity for the NFT position was decreased      |
| amount0   | u256 | The amount of token0 that was accounted for the decrease in liquidity |
| amount1   | u256 | The amount of token1 that was accounted for the decrease in liquidity |

#### Collect <a href="#event_collect" id="event_collect"></a>

```rust
struct Collect {
    token_id: u256,
    recipient: ContractAddress,
    amount0_collect: u128,
    amount1_collect: u128
}
```

The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior

**Parameters:**

| Name             | Type            | Description                                                    |
| ---------------- | --------------- | -------------------------------------------------------------- |
| token\_id        | u256            | The ID of the token for which underlying tokens were collected |
| recipient        | ContractAddress | The address of the account that received the collected tokens  |
| amount0\_collect | u128            | The amount of token0 owed to the position that was collected   |
| amount1\_collect | u128            | The amount of token1 owed to the position that was collected   |

### ABI <a href="#abi" id="abi"></a>

```rust
//sign true for negative numbers
struct i32 {
    mag: u32,
    sign: bool,
}

// @notice The identifying key of the pool
struct PoolKey {
    // @notice The first of the two tokens of the pool, sorted by address
    token0: ContractAddress,
    // @notice The second of the two tokens of the pool, sorted by address
    token1: ContractAddress,
    // @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    fee: u32
}

// @notice details about the JediSwap V2 position
struct PositionDetail {
    // @notice The address that is approved for spending this token
    operator: ContractAddress,
    // @notice The ID of the pool with which this token is connected
    pool_id: u64,
    // @notice The lower tick of the position
    tick_lower: i32,
    // @notice The upper tick of the position
    tick_upper: i32,
    // @notice The liquidity of the position
    liquidity: u128,
    // @notice The fee growth of the aggregate position as of the last action on the individual position, for token0
    fee_growth_inside_0_last_X128: u256,
    // @notice The fee growth of the aggregate position as of the last action on the individual position, for token1
    fee_growth_inside_1_last_X128: u256,
    // @notice Uncollected token0 owed to the position, as of the last computation
    tokens_owed_0: u128,
    // @notice Uncollected token1 owed to the position, as of the last computation
    tokens_owed_1: u128
}

struct MintParams {
    token0: ContractAddress,
    token1: ContractAddress,
    fee: u32,
    tick_lower: i32,
    tick_upper: i32,
    amount0_desired: u256,
    amount1_desired: u256,
    amount0_min: u256,
    amount1_min: u256,
    recipient: ContractAddress,
    deadline: u64
}

struct IncreaseLiquidityParams {
    token_id: u256,
    amount0_desired: u256,
    amount1_desired: u256,
    amount0_min: u256,
    amount1_min: u256,
    deadline: u64
}

struct DecreaseLiquidityParams {
    token_id: u256,
    liquidity: u128,
    amount0_min: u256,
    amount1_min: u256,
    deadline: u64
}

struct CollectParams {
    token_id: u256,
    recipient: ContractAddress,
    amount0_max: u128,
    amount1_max: u128
}

#[starknet::interface]
trait IJediSwapV2NFTPositionManager<TContractState> {
    fn get_factory(self: @TContractState) -> ContractAddress;
    fn get_position(self: @TContractState, token_id: u256) -> (PositionDetail, PoolKey);

    fn mint(ref self: TContractState, params: MintParams) -> (u256, u128, u256, u256);
    fn increase_liquidity(ref self: TContractState, params: IncreaseLiquidityParams) -> (u128, u256, u256);
    fn decrease_liquidity(ref self: TContractState, params: DecreaseLiquidityParams) -> (u256, u256);
    fn collect(ref self: TContractState, params: CollectParams) -> (u128, u128);
    fn burn(ref self: TContractState, token_id: u256);
    fn create_and_initialize_pool(ref self: TContractState, token0: ContractAddress, token1: ContractAddress, fee: u32, sqrt_price_X96: u256) -> ContractAddress;
    fn jediswap_v2_mint_callback(ref self: TContractState, amount0_owed: u256, amount1_owed: u256, callback_data_span: Span<felt252>);
}
```


# jediswap\_v2\_swap\_router

Router for stateless execution of swaps against JediSwap V2

### Functions <a href="#functions" id="functions"></a>

#### exact\_input\_single <a href="#exact_input_single" id="exact_input_single"></a>

{% code overflow="wrap" %}

```rust
fn exact_input_single(ref self: ContractState, params: ExactInputSingleParams) -> u256
```

{% endcode %}

Swaps `amount_in` of one token for as much as possible of another token

**Parameters:**

| Name   | Type                   | Description                           |
| ------ | ---------------------- | ------------------------------------- |
| params | ExactInputSingleParams | The parameters necessary for the swap |

**Return Values:**

| Type | Description                      |
| ---- | -------------------------------- |
| u256 | The amount of the received token |

#### exact\_input <a href="#exact_input" id="exact_input"></a>

```rust
fn exact_input(ref self: ContractState, params: ExactInputParams) -> u256
```

Swaps `amount_in` of one token for as much as possible of another along the specified path

**Parameters:**

| Name   | Type             | Description                                     |
| ------ | ---------------- | ----------------------------------------------- |
| params | ExactInputParams | The parameters necessary for the multi-hop swap |

**Return Values:**

| Type | Description                      |
| ---- | -------------------------------- |
| u256 | The amount of the received token |

#### exact\_output\_single <a href="#exact_output_single" id="exact_output_single"></a>

{% code overflow="wrap" %}

```rust
fn exact_output_single(ref self: ContractState, params: ExactOutputSingleParams) -> u256
```

{% endcode %}

Swaps as little as possible of one token for `amount_out` of another token

**Parameters:**

| Name   | Type                    | Description                           |
| ------ | ----------------------- | ------------------------------------- |
| params | ExactOutputSingleParams | The parameters necessary for the swap |

**Return Values:**

| Type | Description                   |
| ---- | ----------------------------- |
| u256 | The amount of the input token |

#### exact\_output <a href="#exact_output" id="exact_output"></a>

```rust
fn exact_output(ref self: ContractState, params: ExactOutputParams) -> u256
```

Swaps as little as possible of one token for `amount_out` of another along the specified path (reversed)\
path array will be in format \[token\_out, token\_in, fee] if used for single hop (recommend using exact\_output\_single)\
for multihop going from token\_in to token\_out via token\_mid, path will be \[token\_out, token\_mid, fee\_out\_mid, token\_mid, token\_in, fee\_mid\_in]

**Parameters:**

| Name   | Type              | Description                                     |
| ------ | ----------------- | ----------------------------------------------- |
| params | ExactOutputParams | The parameters necessary for the multi-hop swap |

**Return Values:**

| Type | Description                   |
| ---- | ----------------------------- |
| u256 | The amount of the input token |

#### jediswap\_v2\_swap\_callback <a href="#jediswap_v2_swap_callback" id="jediswap_v2_swap_callback"></a>

{% code overflow="wrap" %}

```rust
fn jediswap_v2_swap_callback(ref self: ContractState, amount0_delta: i256, amount1_delta: i256, callback_data_span: Span<felt252>)
```

{% endcode %}

**Parameters:**

| Name                 | Type           | Description |
| -------------------- | -------------- | ----------- |
| amount0\_delta       | i256           |             |
| amount1\_delta       | i256           |             |
| callback\_data\_span | Span\<felt252> |             |

### ABI <a href="#abi" id="abi"></a>

{% code overflow="wrap" %}

```rust
//sign true for negative numbers
struct i256 {
    mag: u256,
    sign: bool,
}

struct ExactInputSingleParams {
    token_in: ContractAddress,
    token_out: ContractAddress,
    fee: u32,
    recipient: ContractAddress,
    deadline: u64,
    amount_in: u256,
    amount_out_minimum: u256,
    sqrt_price_limit_X96: u256
}

struct ExactInputParams {
    path: Array<felt252>,
    recipient: ContractAddress,
    deadline: u64,
    amount_in: u256,
    amount_out_minimum: u256
}

struct ExactOutputSingleParams {
    token_in: ContractAddress,
    token_out: ContractAddress,
    fee: u32,
    recipient: ContractAddress,
    deadline: u64,
    amount_out: u256,
    amount_in_maximum: u256,
    sqrt_price_limit_X96: u256
}

struct ExactOutputParams {
    path: Array::<felt252>,
    recipient: ContractAddress,
    deadline: u64,
    amount_out: u256,
    amount_in_maximum: u256
}

#[starknet::interface]
trait IJediSwapV2SwapRouter<TContractState> {
    fn get_factory(self: @TContractState) -> ContractAddress;
    fn exact_input_single(ref self: TContractState, params: ExactInputSingleParams) -> u256;
    fn exact_input(ref self: TContractState, params: ExactInputParams) -> u256;
    fn exact_output_single(ref self: TContractState, params: ExactOutputSingleParams) -> u256;
    fn exact_output(ref self: TContractState, params: ExactOutputParams) -> u256;
    fn jediswap_v2_swap_callback(ref self: TContractState, amount0_delta: i256, amount1_delta: i256, callback_data_span: Span<felt252>);
}
```

{% endcode %}


# Contract Addresses

## Starknet Mainnet:

**Pool Class Hash:** 0x2cd3c16a0112b22ded4903707f268125fcf46fd7733761e62c13fc0157afd8d

**Factory Contract:** <https://starkscan.co/contract/0x01aa950c9b974294787de8df8880ecf668840a6ab8fa8290bf2952212b375148>

**NFT Router:** <https://starkscan.co/contract/0x0469b656239972a2501f2f1cd71bf4e844d64b7cae6773aa84c702327c476e5b>

**Swap Router:** <https://starkscan.co/contract/0x0359550b990167afd6635fa574f3bdadd83cb51850e1d00061fe693158c23f80>

## Sepolia Testnet:

**Pool Class Hash:** 0x2cd3c16a0112b22ded4903707f268125fcf46fd7733761e62c13fc0157afd8d

**Factory Contract:** <https://sepolia.starkscan.co/contract/0x050d3df81b920d3e608c4f7aeb67945a830413f618a1cf486bdcce66a395109c>

**NFT Router:** <https://sepolia.starkscan.co/contract/0x024fd9721eea36cf8cebc226fd9414057bbf895b47739822f849f622029f9399>

**Swap Router:** <https://sepolia.starkscan.co/contract/0x03c8e56d7f6afccb775160f1ae3b69e3db31b443e544e56bd845d8b3b3a87a21>


# Deprecated Contract Addresses

## <mark style="color:red;">**Warning: Deposits and swaps are paused. Don't interact with the mainnet contracts until this warning is removed.**</mark>

## Starknet Mainnet:

**Pool Class Hash:** 0x28f45f8cb529a51c5beead847c659802b978801e5303201859175f6d9a5939e

**Factory Contract:** <https://starkscan.co/contract/0x04ba0de31008f4e3edd42b3c31db8f49490505885d684b78f5aa1572850b3a5a>

**NFT Router:** <https://starkscan.co/contract/0x00287d2ff1c39a44cd18d9dc7ed5617c9cb16b65090db6a0f689aa14755e4e5e>

**Swap Router:** <https://starkscan.co/contract/0x031a0c1ec4b27d0d0ce75a56b0d35d7ca79138aed511857627b33295b1175ffa>


# Jediswap v1

Jediswap v1 is a Cairo fork of Uniswap V2, which follows the ambient liquidity formula xy=k. Check the docs in this section if you want to integrate Jediswap v1.


# Smart Contract integration

{% hint style="info" %}
**Below docs will demonstrate how to use JediSwap functionalities in your dapps.**&#x20;
{% endhint %}

{% content-ref url="/pages/PJ83nq8DmuKVSzIt2h48" %}
[Implement a swap](/for-developers/jediswap-v1/smart-contract-integration/implement-a-swap)
{% endcontent-ref %}

{% content-ref url="/pages/vLy1PTepYvEBvphzlGUX" %}
[Providing liquidity](/for-developers/jediswap-v1/smart-contract-integration/providing-liquidity)
{% endcontent-ref %}

{% content-ref url="/pages/ApvUYkfU09FjEyMVkihh" %}
[Pair Addresses](/for-developers/jediswap-v1/smart-contract-integration/pair-addresses)
{% endcontent-ref %}


# Implement a swap

When trading from a smart contract, an external price source is *required*. Without this, trades can be front-run to make a hefty loss.

*Read* [safety considerations](#safety-considerations) *for more.*

## Using the Router contract

The easiest way to safely swap tokens is to use the router, which provides a variety of methods to safely swap to and from different assets. There are two functions for swapping to/from an exact amount of tokens.

First, you must use an external price source to calculate the safety parameters for the function you'd like to call. This is either the minimum amount received when selling an exact input or the maximum amount you are willing to pay when buying an exact output amount

It is also important to ensure that your contract controls enough tokens to make the swap and has granted approval to the router to withdraw these many tokens.

## Example

Imagine you want to swap exactly 100 DAI for as much ETH as possible from your smart contract. These are the steps your smart contract needs to follow.

### 1. transferFrom

Before swapping, your smart contract needs to be in control of 100 DAI. The easiest way to accomplish this is by calling *transferFrom* on DAI with the owner set to *caller:*

```js
let (caller) = get_caller_address()
let (contract_address) = get_contract_address()
IERC20.transferFrom(contract_address=DAI_address, sender=caller, recipient=contract_address, amount=amount)
```

### 2. approve

Now that your contract owns 100 DAI, you need to approve the router contract to withdraw this DAI:

```js
 _IERC20.approve(contract_address= DAI_address, spender= router, amount= amount)_ 
```

### 3. swap\_exact\_tokens\_for\_tokens

Now we're ready to swap:

```js
 _let (deadline) = get_block_timestamp()
let (local path : felt*) = alloc()
assert [path] = DAI_address
assert [path+1] = ETH_address
let path_len = 2_ 
 _IRouter.swap_exact_tokens_for_tokens(contract_address = router, amountIn = amount, amountOutMin = amountOutMin, path_len = path_len, path = path, to = contract_address, deadline = deadline)_ 
```

## Safety Considerations

Because Starknet transactions occur in an adversarial environment, smart contracts that do not perform safety checks *can be exploited for profit*. If a smart contract assumes that the current price on JediSwap is a "fair" price without performing safety checks, *it is vulnerable to manipulation*. Exp: A bad actor could easily insert transactions before and after the swap (a "sandwich" attack), causing the smart contract to trade at a much worse price, profit from this at the trader's expense, and then return the contracts to their original state. (One important caveat is that these types of attacks are mitigated by trading in extremely liquid pools and/or at low values.)

The best way to protect against these attacks is to use an external price feed or "price oracle". The best "oracle" is simply *traders' off-chain observation of the current price*, which can be passed into the trade as a safety check. This strategy is best for situations *where users initiate trades on their own behalf*

However, when an off-chain price can't be used, an on-chain oracle should be used instead. Determining the best oracle for a given situation is not within the scope of this guide.


# Providing liquidity

When providing liquidity from a smart contract, the most important thing to keep in mind is that tokens deposited into a pool at any rate other than the current reserve ratio *are vulnerable to being arbitraged* . As an example, if the ratio of x:y in a pair is 10:2 (i.e. the price is 5), and someone naively adds liquidity at 5:2 (a price of 2.5), the contract will simply accept all tokens (changing the price to 3.75 and opening up the market to arbitrage), but only issue pool tokens entitling the sender to the amount of assets sent at the proper ratio, in this case, 5:1. To avoid donating to arbitrageurs, it is imperative to add liquidity at the current price. Luckily, it's easy to ensure that this condition is met!

## **Using the Router**

The easiest way to safely add liquidity to a pool is to use the router contract, which provides a simple method to safely add liquidity to a pool, *add\_liquidity.*

The *caller* needs to commit to a *belief about the current price* , which is encoded in the *amount\*\*Desired* parameters. Typically, it's fairly safe to assume that the current fair market price is around what the current reserve ratio is for a pair (because of arbitrage). So, if a user wants to add 1 ETH to a pool, and the current DAI/WETH ratio of the pool is 4000/1, it's reasonable to calculate that 4000 DAI must be sent along with 1 ETH, which is an implicit commitment to the price of 4000 DAI/1 WETH. However, it's important to note that this must be calculated *before the transaction is submitted* . It is *not safe* to look up the reserve ratio from within a transaction and rely on it as a price belief, as this ratio can be cheaply manipulated to your detriment.

However, it is still possible to submit a transaction that encodes a belief about the price which ends up being wrong because of a larger change in the true market price before the transaction is confirmed. For that reason, it's necessary to pass an additional set of parameters that encode the caller's tolerance to price changes. These *amount\*\*Min* parameters should typically be set to percentages of the calculated desired price. So, at a 1% tolerance level, if our user sends a transaction with 1 ETH and 4000 DAI, amountETHMin should be set to e.g. .99 ETH, and amountTokenMin should be set to 3960 DAI. This means that, at worst, liquidity will be added at a rate between 3960 DAI/1 ETH and 4040.40 DAI/1 ETH (4000 DAI/.99 ETH).

Once the price calculations have been made, it's important to ensure that your contract

1. controls at least as many tokens/ETH as were passed as amount\*Desired parameters, and
2. has granted approval to the router to withdraw this many tokens:

```js
IERC20.approve(contract_address = DAI_address, spender = router, amount = DAI_amount)
IERC20.approve(contract_address = WETH_address, spender = router, amount = WETH_amount)

let (contract_address) = get_contract_address()
let (deadline) = get_block_timestamp()
let(amountA:Uint256, amountB:Uint256, liquidity:Uint256) = IRouter.add_liquidity(contract_address = router, tokenA = DAI_address, tokenB = WETH_address, amountADesired = DAI_amount, amountBDesired = WETH_amount, amountAMin = DAI_amount_min, amountBMin = WETH_amount_min, to = contract_address, deadline = deadline )
```


# Pair Addresses

## **get\_pair**

The best way to get the address for a pair is to call [get\_pair](/for-developers/jediswap-v1/smart-contract-reference/factory#get_pair) on the [Factory](/for-developers/jediswap-v1/smart-contract-reference/factory). If the pair exists, this function will return its address else 0

* The "canonical" way to determine whether or not a pair exists.
* Requires an on-chain lookup.

## **Off-Chain**

Python Example:

```python
from starkware.starknet.core.os.contract_address.contract_address import calculate_contract_address_from_hash
from starkware.cairo.lang.vm.crypto import pedersen_hash


def get_create2_address(token0: int, token1: int, class_hash: int) -> int:

    salt = pedersen_hash(token0, token1)

    constructor_calldata = [token0,
                            token1]

    create2_pair_address = calculate_contract_address_from_hash(
        salt=salt, class_hash=class_hash, deployer_address=factory, constructor_calldata=constructor_calldata)

    return create2_pair_address
```

* token0 must be strictly less than token1 by sort order.
* Can be computed offline.
* Requires the ability to perform pedersen\_hash.


# Smart contract reference

{% hint style="info" %}
**You might need different contract addresses based on your needs. Below docs will demonstrate how to get different kinds of JediSwap contracts programmatically.**&#x20;
{% endhint %}

{% content-ref url="/pages/1h88z1NKhUSeQ8GsYe6I" %}
[Router](/for-developers/jediswap-v1/smart-contract-reference/router)
{% endcontent-ref %}

{% content-ref url="/pages/g85WapXdSMrUbSkYLN2S" %}
[Pair](/for-developers/jediswap-v1/smart-contract-reference/pair)
{% endcontent-ref %}

{% content-ref url="/pages/gJ9JCiBvds32S3XatC6M" %}
[Factory](/for-developers/jediswap-v1/smart-contract-reference/factory)
{% endcontent-ref %}

{% content-ref url="/pages/rs0xGdigTrebE9n8xiwb" %}
[Pair (ERC 20)](/for-developers/jediswap-v1/smart-contract-reference/pair-erc-20)
{% endcontent-ref %}


# Router

## Code

[Router.cairo](https://github.com/jediswaplabs/JediSwap/blob/main/contracts/Router.cairo)

## Address

Router is deployed at:

Starknet Alpha Testnet: [0x02bcc885342ebbcbcd170ae6cafa8a4bed22bb993479f49806e72d96af94c965](https://testnet.starkscan.co/contract/0x02bcc885342ebbcbcd170ae6cafa8a4bed22bb993479f49806e72d96af94c965)

Starknet Alpha Mainnet: [0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023](https://starkscan.co/contract/0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023)

## View Functions

### factory

```js
func factory() -> (address: felt):
```

Returns  [Factory](/for-developers/jediswap-v1/smart-contract-reference/factory) address.

### sort\_tokens​

```js
func sort_tokens(tokenA: felt, tokenB: felt) -> (token0: felt, token1: felt):
```

Sort tokens by address.

### quote​

```js
func quote(amountA: Uint256, reserveA: Uint256, reserveB: Uint256) -> (amountB: Uint256):
```

Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.

* Useful for calculating optimal token amounts before calling [mint](/for-developers/jediswap-v1/smart-contract-reference/pair#mint-1).

### get\_amount\_out​

```js
func get_amount_out(amountIn: Uint256, reserveIn: Uint256, reserveOut: Uint256) -> (amountOut: Uint256):
```

Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.

### get\_amount\_in​

```js
func get_amount_in(amountOut: Uint256, reserveIn: Uint256, reserveOut: Uint256) -> (amountIn: Uint256):
```

Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.

### get\_amounts\_out​

```js
func get_amounts_out(amountIn: Uint256, path_len: felt, path: felt*) -> (amounts_len: felt, amounts: Uint256*):
```

Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling [get\_reserves](/for-developers/jediswap-v1/smart-contract-reference/pair#get_reserves) for each pair of token addresses in the path in turn, and using these to call [ get\_amount\_out](#get_amount_out).

* Useful for calculating optimal token amounts before calling [swap](/for-developers/jediswap-v1/smart-contract-reference/pair#swap-1).

### get\_amounts\_in​

```js
func get_amounts_in(amountOut: Uint256, path_len: felt, path: felt*) -> (amounts_len: felt, amounts: Uint256*):
```

Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling [get\_reserves](/for-developers/jediswap-v1/smart-contract-reference/pair#get_reserves) for each pair of token addresses in the path in turn, and using these to call [get\_amount\_in](#get_amount_in).

* Useful for calculating optimal token amounts before calling [swap](/for-developers/jediswap-v1/smart-contract-reference/pair#swap-1).

## State-Changing Functions

### addLiquidity​

```js
func add_liquidity(tokenA: felt, tokenB: felt, amountADesired: Uint256,            amountBDesired: Uint256, amountAMin: Uint256, amountBMin: Uint256, to: felt, deadline: felt) -> (amountA: Uint256, amountB: Uint256, liquidity: Uint256):
```

Adds liquidity to an ERC-20⇄ERC-20 pool.

* To cover all possible scenarios,� *�calle* r should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.
* Always adds assets at the ideal ratio, according to the price when the transaction is executed.

### remove\_liquidity

```js
​func remove_liquidity(tokenA: felt, tokenB: felt, liquidity: Uint256, amountAMin: Uint256, amountBMin: Uint256, to: felt, deadline: felt) -> (amountA: Uint256, amountB: Uint256):
```

Removes liquidity from an ERC-20⇄ERC-20 pool.

* *caller*  should have already given the router an allowance of at least liquidity on the pool.

### swap\_exact\_tokens\_for\_tokens​

```js
​func swap_exact_tokens_for_tokens(amountIn: Uint256, amountOutMin: Uint256, path_len: felt, path: felt*, to: felt, deadline: felt) -> (amounts_len: felt, amounts: Uint256*):
```

Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

* *caller*  should have already given the router an allowance of at least amountIn on the input token.

### swap\_tokens\_for\_exact\_tokens​

```js
​func swap_tokens_for_exact_tokens(amountOut: Uint256, amountInMax: Uint256, path_len: felt, path: felt*, to: felt, deadline: felt) -> (amounts_len: felt, amounts: Uint256*):
```

Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate tokens to trade through (if, for example, a direct pair does not exist).

* *caller*  should have already given the router an allowance of at least amountInMax on the input token.

## Interface

```js
%lang starknet

from starkware.cairo.common.uint256 import Uint256

@contract_interface
namespace IRouter:
    func factory() -> (address: felt):
    end

    func sort_tokens(tokenA: felt, tokenB: felt) -> (token0: felt, token1: felt):
    end

    func quote(amountA: Uint256, reserveA: Uint256, reserveB: Uint256) -> (amountB: Uint256):
    end

    ​func get_amount_out(amountIn: Uint256, reserveIn: Uint256, reserveOut: Uint256) -> (amountOut: Uint256):
    end

    ​func get_amount_in(amountOut: Uint256, reserveIn: Uint256, reserveOut: Uint256) -> (amountIn: Uint256):
    end

    func get_amounts_out(amountIn: Uint256, path_len: felt, path: felt*) -> (amounts_len: felt, amounts: Uint256*):
    end

    func get_amounts_in(amountOut: Uint256, path_len: felt, path: felt*) -> (amounts_len: felt, amounts: Uint256*):
    end

    func add_liquidity(tokenA: felt, tokenB: felt, amountADesired: Uint256,            amountBDesired: Uint256, amountAMin: Uint256, amountBMin: Uint256, to: felt, deadline: felt) -> (amountA: Uint256, amountB: Uint256, liquidity: Uint256):
    end

    ​func remove_liquidity(tokenA: felt, tokenB: felt, liquidity: Uint256, amountAMin: Uint256, amountBMin: Uint256, to: felt, deadline: felt) -> (amountA: Uint256, amountB: Uint256):
    end

    ​func swap_exact_tokens_for_tokens(amountIn: Uint256, amountOutMin: Uint256, path_len: felt, path: felt*, to: felt, deadline: felt) -> (amounts_len: felt, amounts: Uint256*):
    end

    ​func swap_tokens_for_exact_tokens(amountOut: Uint256, amountInMax: Uint256, path_len: felt, path: felt*, to: felt, deadline: felt) -> (amounts_len: felt, amounts: Uint256*):
    end
end
```

## ABI

```js
[
    {
        "members": [
            {
                "name": "low",
                "offset": 0,
                "type": "felt"
            },
            {
                "name": "high",
                "offset": 1,
                "type": "felt"
            }
        ],
        "name": "Uint256",
        "size": 2,
        "type": "struct"
    },
    {
        "inputs": [
            {
                "name": "factory",
                "type": "felt"
            }
        ],
        "name": "constructor",
        "outputs": [],
        "type": "constructor"
    },
    {
        "inputs": [],
        "name": "factory",
        "outputs": [
            {
                "name": "address",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "tokenA",
                "type": "felt"
            },
            {
                "name": "tokenB",
                "type": "felt"
            }
        ],
        "name": "sort_tokens",
        "outputs": [
            {
                "name": "token0",
                "type": "felt"
            },
            {
                "name": "token1",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountA",
                "type": "Uint256"
            },
            {
                "name": "reserveA",
                "type": "Uint256"
            },
            {
                "name": "reserveB",
                "type": "Uint256"
            }
        ],
        "name": "quote",
        "outputs": [
            {
                "name": "amountB",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountIn",
                "type": "Uint256"
            },
            {
                "name": "reserveIn",
                "type": "Uint256"
            },
            {
                "name": "reserveOut",
                "type": "Uint256"
            }
        ],
        "name": "get_amount_out",
        "outputs": [
            {
                "name": "amountOut",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountOut",
                "type": "Uint256"
            },
            {
                "name": "reserveIn",
                "type": "Uint256"
            },
            {
                "name": "reserveOut",
                "type": "Uint256"
            }
        ],
        "name": "get_amount_in",
        "outputs": [
            {
                "name": "amountIn",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountIn",
                "type": "Uint256"
            },
            {
                "name": "path_len",
                "type": "felt"
            },
            {
                "name": "path",
                "type": "felt*"
            }
        ],
        "name": "get_amounts_out",
        "outputs": [
            {
                "name": "amounts_len",
                "type": "felt"
            },
            {
                "name": "amounts",
                "type": "Uint256*"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountOut",
                "type": "Uint256"
            },
            {
                "name": "path_len",
                "type": "felt"
            },
            {
                "name": "path",
                "type": "felt*"
            }
        ],
        "name": "get_amounts_in",
        "outputs": [
            {
                "name": "amounts_len",
                "type": "felt"
            },
            {
                "name": "amounts",
                "type": "Uint256*"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "tokenA",
                "type": "felt"
            },
            {
                "name": "tokenB",
                "type": "felt"
            },
            {
                "name": "amountADesired",
                "type": "Uint256"
            },
            {
                "name": "amountBDesired",
                "type": "Uint256"
            },
            {
                "name": "amountAMin",
                "type": "Uint256"
            },
            {
                "name": "amountBMin",
                "type": "Uint256"
            },
            {
                "name": "to",
                "type": "felt"
            },
            {
                "name": "deadline",
                "type": "felt"
            }
        ],
        "name": "add_liquidity",
        "outputs": [
            {
                "name": "amountA",
                "type": "Uint256"
            },
            {
                "name": "amountB",
                "type": "Uint256"
            },
            {
                "name": "liquidity",
                "type": "Uint256"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "tokenA",
                "type": "felt"
            },
            {
                "name": "tokenB",
                "type": "felt"
            },
            {
                "name": "liquidity",
                "type": "Uint256"
            },
            {
                "name": "amountAMin",
                "type": "Uint256"
            },
            {
                "name": "amountBMin",
                "type": "Uint256"
            },
            {
                "name": "to",
                "type": "felt"
            },
            {
                "name": "deadline",
                "type": "felt"
            }
        ],
        "name": "remove_liquidity",
        "outputs": [
            {
                "name": "amountA",
                "type": "Uint256"
            },
            {
                "name": "amountB",
                "type": "Uint256"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountIn",
                "type": "Uint256"
            },
            {
                "name": "amountOutMin",
                "type": "Uint256"
            },
            {
                "name": "path_len",
                "type": "felt"
            },
            {
                "name": "path",
                "type": "felt*"
            },
            {
                "name": "to",
                "type": "felt"
            },
            {
                "name": "deadline",
                "type": "felt"
            }
        ],
        "name": "swap_exact_tokens_for_tokens",
        "outputs": [
            {
                "name": "amounts_len",
                "type": "felt"
            },
            {
                "name": "amounts",
                "type": "Uint256*"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amountOut",
                "type": "Uint256"
            },
            {
                "name": "amountInMax",
                "type": "Uint256"
            },
            {
                "name": "path_len",
                "type": "felt"
            },
            {
                "name": "path",
                "type": "felt*"
            },
            {
                "name": "to",
                "type": "felt"
            },
            {
                "name": "deadline",
                "type": "felt"
            }
        ],
        "name": "swap_tokens_for_exact_tokens",
        "outputs": [
            {
                "name": "amounts_len",
                "type": "felt"
            },
            {
                "name": "amounts",
                "type": "Uint256*"
            }
        ],
        "type": "function"
    }
]

```


# Pair

This documentation covers Uniswap-specific functionality. For ERC-20 functionality, see [Pair (ERC-20)](/for-developers/jediswap-v1/smart-contract-reference/pair-erc-20).

## Code

[Pair.cairo](https://github.com/jediswaplabs/JediSwap/blob/main/contracts/Pair.cairo)

## Address

See [Pair Addresses](/for-developers/jediswap-v1/smart-contract-integration/pair-addresses)

## Events

### Mint​

```js
@event
func Mint(sender: felt, amount0: Uint256, amount1: Uint256):
end
```

Emitted each time liquidity tokens are created via [mint](#mint-1).

### Burn​

```js
@event
func Burn(sender: felt, amount0: Uint256, amount1: Uint256, to: felt):
end
```

Emitted each time liquidity tokens are destroyed via [burn](#burn-1).

### Swap​

```js
@event
func Swap(sender: felt, amount0In: Uint256, amount1In: Uint256, amount0Out: Uint256, amount1Out: Uint256, to: felt):
end
```

Emitted each time a swap occurs via [swap](#swap-1).

### Sync​

```js
@event
func Sync(reserve0: Uint256, reserve1: Uint256):
end
```

Emitted each time reserves are updated via [mint](#mint-1), [ burn](#burn-1), [swap](#swap-1) or [sync](#sync-1).

## View Functions

### token0​

```js
func token0() -> (address: felt):
```

Returns the address of the pair token with the lower sort order.

### token1​

```js
func token1() -> (address: felt):
```

Returns the address of the pair token with the higher sort order.

### get\_reserves

```js
func get_reserves() -> (reserve0: Uint256, reserve1: Uint256, block_timestamp_last: felt):
```

Returns the reserves of token0 and token1 used to price trades and distribute liquidity. Also returns the *get\_block\_timestamp()* (mod 2\*\*32) of the last block during which an interaction occurred for the pair.

### price\_0\_cumulative\_last

```js
​func price_0_cumulative_last() -> (res: Uint256):
```

Returns cumulative price for token0 on last update. See Oracles. TODO

### price\_1\_cumulative\_last

```js
​func price_1_cumulative_last() -> (res: Uint256):
```

Returns cumulative price for token1 on last update. See Oracles. TODO

### kLast​

```js
​func klast() -> (res: Uint256):
```

Returns the product of the reserves as of the most recent liquidity event. See Protocol Charge Calculation. TODO

## State-Changing Functions

### mint​

```js
func mint(to: felt) -> (liquidity: Uint256):
```

Creates pool tokens.

* Emits [Mint](#mint), [Sync](#sync), [Transfer](/for-developers/jediswap-v1/smart-contract-reference/pair-erc-20#transfer).

### burn​

```js
func burn(to: felt) -> (amount0: Uint256, amount1: Uint256):
```

Destroys pool tokens.

* Emits [Burn](#burn), [Sync](#sync), [Transfer](/for-developers/jediswap-v1/smart-contract-reference/pair-erc-20#transfer).

### swap​

```js
func swap(amount0Out: Uint256, amount1Out: Uint256, to: felt, data_len: felt, data: felt*):
```

Swaps tokens. For regular swaps, data.length must be 0. Also see Flash Swaps. TODO

* Emits [Swap](#swap), [Sync](#sync).

### skim​

```js
func skim(to: felt):
```

See the [uniswap whitepaper](https://docs.uniswap.org/whitepaper.pdf).

### sync​

```js
func sync():
```

See the [uniswap whitepaper](https://docs.uniswap.org/whitepaper.pdf).

* Emits [Sync](#sync).

## Interface

```js
%lang starknet

from starkware.cairo.common.uint256 import Uint256

@contract_interface
namespace IJediSwapPair:
    func token0() -> (address: felt):
    end

    func token1() -> (address: felt):
    end

    func get_reserves() -> (reserve0: Uint256, reserve1: Uint256, block_timestamp_last:     felt):
    end

    ​func price_0_cumulative_last() -> (res: Uint256):
    end

    ​func price_1_cumulative_last() -> (res: Uint256):
    end

    ​func klast() -> (res: Uint256):
    end

    func mint(to: felt) -> (liquidity: Uint256):
    end

    func burn(to: felt) -> (amount0: Uint256, amount1: Uint256):
    end

    func swap(amount0Out: Uint256, amount1Out: Uint256, to: felt, data_len: felt, data: felt*):
    end

    func skim(to: felt):
    end

    func sync():
    end
end
```

## ABI

```js
[
    {
        "members": [
            {
                "name": "low",
                "offset": 0,
                "type": "felt"
            },
            {
                "name": "high",
                "offset": 1,
                "type": "felt"
            }
        ],
        "name": "Uint256",
        "size": 2,
        "type": "struct"
    },
    {
        "data": [
            {
                "name": "from_",
                "type": "felt"
            },
            {
                "name": "to",
                "type": "felt"
            },
            {
                "name": "value",
                "type": "Uint256"
            }
        ],
        "keys": [],
        "name": "Transfer",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "owner",
                "type": "felt"
            },
            {
                "name": "spender",
                "type": "felt"
            },
            {
                "name": "value",
                "type": "Uint256"
            }
        ],
        "keys": [],
        "name": "Approval",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "from_address",
                "type": "felt"
            },
            {
                "name": "to_address",
                "type": "felt"
            },
            {
                "name": "amount",
                "type": "Uint256"
            }
        ],
        "keys": [],
        "name": "Transfer",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "owner",
                "type": "felt"
            },
            {
                "name": "spender",
                "type": "felt"
            },
            {
                "name": "amount",
                "type": "Uint256"
            }
        ],
        "keys": [],
        "name": "Approval",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "sender",
                "type": "felt"
            },
            {
                "name": "amount0",
                "type": "Uint256"
            },
            {
                "name": "amount1",
                "type": "Uint256"
            }
        ],
        "keys": [],
        "name": "Mint",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "sender",
                "type": "felt"
            },
            {
                "name": "amount0",
                "type": "Uint256"
            },
            {
                "name": "amount1",
                "type": "Uint256"
            },
            {
                "name": "to",
                "type": "felt"
            }
        ],
        "keys": [],
        "name": "Burn",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "sender",
                "type": "felt"
            },
            {
                "name": "amount0In",
                "type": "Uint256"
            },
            {
                "name": "amount1In",
                "type": "Uint256"
            },
            {
                "name": "amount0Out",
                "type": "Uint256"
            },
            {
                "name": "amount1Out",
                "type": "Uint256"
            },
            {
                "name": "to",
                "type": "felt"
            }
        ],
        "keys": [],
        "name": "Swap",
        "type": "event"
    },
    {
        "data": [
            {
                "name": "reserve0",
                "type": "Uint256"
            },
            {
                "name": "reserve1",
                "type": "Uint256"
            }
        ],
        "keys": [],
        "name": "Sync",
        "type": "event"
    },
    {
        "inputs": [
            {
                "name": "token0",
                "type": "felt"
            },
            {
                "name": "token1",
                "type": "felt"
            }
        ],
        "name": "constructor",
        "outputs": [],
        "type": "constructor"
    },
    {
        "inputs": [],
        "name": "name",
        "outputs": [
            {
                "name": "name",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "symbol",
        "outputs": [
            {
                "name": "symbol",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "totalSupply",
        "outputs": [
            {
                "name": "totalSupply",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "decimals",
        "outputs": [
            {
                "name": "decimals",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "account",
                "type": "felt"
            }
        ],
        "name": "balanceOf",
        "outputs": [
            {
                "name": "balance",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "owner",
                "type": "felt"
            },
            {
                "name": "spender",
                "type": "felt"
            }
        ],
        "name": "allowance",
        "outputs": [
            {
                "name": "remaining",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "token0",
        "outputs": [
            {
                "name": "address",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "token1",
        "outputs": [
            {
                "name": "address",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get_reserves",
        "outputs": [
            {
                "name": "reserve0",
                "type": "Uint256"
            },
            {
                "name": "reserve1",
                "type": "Uint256"
            },
            {
                "name": "block_timestamp_last",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "price_0_cumulative_last",
        "outputs": [
            {
                "name": "res",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "price_1_cumulative_last",
        "outputs": [
            {
                "name": "res",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "klast",
        "outputs": [
            {
                "name": "res",
                "type": "Uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "recipient",
                "type": "felt"
            },
            {
                "name": "amount",
                "type": "Uint256"
            }
        ],
        "name": "transfer",
        "outputs": [
            {
                "name": "success",
                "type": "felt"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "sender",
                "type": "felt"
            },
            {
                "name": "recipient",
                "type": "felt"
            },
            {
                "name": "amount",
                "type": "Uint256"
            }
        ],
        "name": "transferFrom",
        "outputs": [
            {
                "name": "success",
                "type": "felt"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "spender",
                "type": "felt"
            },
            {
                "name": "amount",
                "type": "Uint256"
            }
        ],
        "name": "approve",
        "outputs": [
            {
                "name": "success",
                "type": "felt"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "spender",
                "type": "felt"
            },
            {
                "name": "added_value",
                "type": "Uint256"
            }
        ],
        "name": "increaseAllowance",
        "outputs": [
            {
                "name": "success",
                "type": "felt"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "spender",
                "type": "felt"
            },
            {
                "name": "subtracted_value",
                "type": "Uint256"
            }
        ],
        "name": "decreaseAllowance",
        "outputs": [
            {
                "name": "success",
                "type": "felt"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "to",
                "type": "felt"
            }
        ],
        "name": "mint",
        "outputs": [
            {
                "name": "liquidity",
                "type": "Uint256"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "to",
                "type": "felt"
            }
        ],
        "name": "burn",
        "outputs": [
            {
                "name": "amount0",
                "type": "Uint256"
            },
            {
                "name": "amount1",
                "type": "Uint256"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "amount0Out",
                "type": "Uint256"
            },
            {
                "name": "amount1Out",
                "type": "Uint256"
            },
            {
                "name": "to",
                "type": "felt"
            },
            {
                "name": "data_len",
                "type": "felt"
            },
            {
                "name": "data",
                "type": "felt*"
            }
        ],
        "name": "swap",
        "outputs": [],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "to",
                "type": "felt"
            }
        ],
        "name": "skim",
        "outputs": [],
        "type": "function"
    },
    {
        "inputs": [],
        "name": "sync",
        "outputs": [],
        "type": "function"
    }
]

```


# Factory

## Code

[Factory.cairo](https://github.com/jediswaplabs/JediSwap/blob/main/contracts/Factory.cairo)

## Address

Factory is deployed at:

Starknet Alpha Testnet: [0x0262744f8cea943dadc8823c318eaf24d0110dee2ee8026298f49a3bc58ed74a](https://testnet.starkscan.co/contract/0x0262744f8cea943dadc8823c318eaf24d0110dee2ee8026298f49a3bc58ed74a)

Starknet Alpha Mainnet: [0x00dad44c139a476c7a17fc8141e6db680e9abc9f56fe249a105094c44382c2fd](https://starkscan.co/contract/0x00dad44c139a476c7a17fc8141e6db680e9abc9f56fe249a105094c44382c2fd)

## Events

### PairCreated​

```js
@event
func PairCreated(token0: felt, token1: felt, pair: felt, total_pairs: felt):
end
```

Emitted each time a pair is created via [create\_pair](#create_pair).

* The final uint log value will be 1 for the first pair created, 2 for the second, etc.

## View Functions

### get\_pair

```js
func get_pair(token0: felt, token1: felt) -> (pair: felt):
```

Returns the address of the pair for token0 and token1, if it has been created, else address(0).

* token0 and token1 are interchangeable.

### get\_all\_pairs​

```js
func get_all_pairs() -> (all_pairs_len: felt, all_pairs: felt*):
```

Returns the number of pairs and addresses of all pairs created.

### get\_num\_of\_pairs​

```js
func get_num_of_pairs() -> (num_of_pairs: felt):
```

Returns the number of pairs created.

### get\_fee\_to​

```js
func get_fee_to() -> (address: felt):
```

Get fee recipient address. See Protocol Charge Calculation. TODO

### get\_fee\_to\_setter​

```js
func get_fee_to_setter() -> (address: felt):
```

The address allowed to change fee\_to via set\_fee\_to.

### get\_pair\_contract\_class\_hash​

```js
func get_pair_contract_class_hash() -> (class_hash: felt):
```

Get the class hash of the [Canvas(Pair)](/for-developers/jediswap-v1/smart-contract-reference/pair) contract which is deployed for each [create\_pair](#create_pair).

## State-Changing Functions

### create\_pair​

```js
func create_pair(tokenA: felt, tokenB: felt) -> (pair: felt):
```

Creates a pair for tokenA and tokenB.

* tokenA and tokenB are interchangeable.
* Emits [PairCreated](#paircreated).

### set\_fee\_to​

```js
func set_fee_to(new_fee_to: felt):
```

Updates fee recipient

* only fee\_to\_setter can call.

### set\_fee\_to\_setter​

```js
func set_fee_to_setter(new_fee_to_setter: felt):
```

Updates fee to setter

* only fee\_to\_setter can call.
* new\_fee\_to\_setter can not be zero

## Interface

```js
%lang starknet

@contract_interface
namespace IFactory:
    func get_pair(token0: felt, token1: felt) -> (pair: felt):
    end

    func get_all_pairs() -> (all_pairs_len: felt, all_pairs: felt*):
    end
    
    func get_num_of_pairs() -> (num_of_pairs: felt):
    end

    func get_fee_to() -> (address: felt):
    end

    ​func get_fee_to_setter() -> (address: felt):
    end

    ​func get_pair_contract_class_hash() -> (class_hash: felt):
    end

    ​func create_pair(tokenA: felt, tokenB: felt) -> (pair: felt):
    end

    ​func set_fee_to(new_fee_to: felt):
    end

    ​func set_fee_to_setter(new_fee_to_setter: felt):
    end
end
```

## ABI

```js
[
    {
        "data": [
            {
                "name": "token0",
                "type": "felt"
            },
            {
                "name": "token1",
                "type": "felt"
            },
            {
                "name": "pair",
                "type": "felt"
            },
            {
                "name": "total_pairs",
                "type": "felt"
            }
        ],
        "keys": [],
        "name": "PairCreated",
        "type": "event"
    },
    {
        "inputs": [
            {
                "name": "pair_contract_class_hash",
                "type": "felt"
            },
            {
                "name": "fee_to_setter",
                "type": "felt"
            }
        ],
        "name": "constructor",
        "outputs": [],
        "type": "constructor"
    },
    {
        "inputs": [
            {
                "name": "token0",
                "type": "felt"
            },
            {
                "name": "token1",
                "type": "felt"
            }
        ],
        "name": "get_pair",
        "outputs": [
            {
                "name": "pair",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get_all_pairs",
        "outputs": [
            {
                "name": "all_pairs_len",
                "type": "felt"
            },
            {
                "name": "all_pairs",
                "type": "felt*"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get_num_of_pairs",
        "outputs": [
            {
                "name": "num_of_pairs",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get_fee_to",
        "outputs": [
            {
                "name": "address",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get_fee_to_setter",
        "outputs": [
            {
                "name": "address",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get_pair_contract_class_hash",
        "outputs": [
            {
                "name": "class_hash",
                "type": "felt"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "tokenA",
                "type": "felt"
            },
            {
                "name": "tokenB",
                "type": "felt"
            }
        ],
        "name": "create_pair",
        "outputs": [
            {
                "name": "pair",
                "type": "felt"
            }
        ],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "new_fee_to",
                "type": "felt"
            }
        ],
        "name": "set_fee_to",
        "outputs": [],
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "new_fee_to_setter",
                "type": "felt"
            }
        ],
        "name": "set_fee_to_setter",
        "outputs": [],
        "type": "function"
    }
]

```


# Pair (ERC 20)

This documentation covers ERC-20 functionality for denominating pool tokens. For JediSwap-specific functionality, see [Pair](/for-developers/jediswap-v1/smart-contract-reference/pair).

## Code

[Pair.cairo](https://github.com/jediswaplabs/jediswap/blob/main/contracts/pair.cairo)

## Events

### Approval​

```js
@event
func Approval(owner: felt, spender: felt, amount: Uint256):
end
```

Emitted each time allowances is updated in [approve](#approve), [increaseAllowance](#increaseallowance), [decreaseAllowance](#decreaseallowance) or [transferFrom](#transferfrom)

### Transfer​

```js
@event
func Transfer(from_address: felt, to_address: felt, amount: Uint256):
end
```

Emitted each time a transfer occurs via [transfer](#transfer-1), [transferFrom](#transferfrom), [mint](/for-developers/jediswap-v1/smart-contract-reference/pair#mint-1), or [burn](/for-developers/jediswap-v1/smart-contract-reference/pair#burn-1).

## View Functions

### name​

```js
func name() -> (name: felt):
```

Returns JediSwap Pair for all pairs.

### symbol​

```js
func symbol() -> (symbol: felt):
```

Returns JEDIP for all pairs.

### decimals​

```js
func decimals() -> (decimals: felt):
```

Returns 18 for all pairs.

### totalSupply​

```js
func totalSupply() -> (totalSupply: Uint256):
```

Returns the total amount of pool tokens for a pair.

### balanceOf​

```js
func balanceOf(account: felt) -> (balance: Uint256):
```

Returns the amount of pool tokens owned by an address.

### allowance​

```js
func allowance(owner: felt, spender: felt) -> (remaining: Uint256):
```

Returns the amount of liquidity tokens owned by an address that a spender is allowed to transfer via transferFrom.

## State-Changing Functions

### approve​

```js
func approve(spender: felt, amount: Uint256) -> (success: felt):
```

Lets *caller* set their allowance for a spender.

* Emits [Approval](#approval).

### increaseAllowance​

```js
func increaseAllowance(spender: felt, added_value: Uint256) -> (success: felt):
```

Lets *caller* increase their allowance for a spender by added\_value.

* Emits [Approval](#approval).

### decreaseAllowance​

```js
func decreaseAllowance(spender: felt, subtracted_value: Uint256) -> (success: felt):
```

Lets *caller* decrease their allowance for a spender by subtracted\_value.

* Emits [Approval](#approval).

### transfer​

```js
func transfer(recipient: felt, amount: Uint256) -> (success: felt):
```

Lets *caller* send pool tokens to an address.

* Emits [Transfer](#transfer).

### transferFrom​

```js
func transferFrom(
            sender: felt, 
            recipient: felt, 
            amount: Uint256
        ) -> (success: felt):
```

Sends pool tokens from one address to another.

* Requires approval.
* Emits [Transfer](#transfer)

## Interface

```js
%lang starknet

from starkware.cairo.common.uint256 import Uint256

@contract_interface
namespace IJediSwapPairERC20:
    func name() -> (name: felt):
    end

    func symbol() -> (symbol: felt):
    end

    func decimals() -> (decimals: felt):
    end

    func totalSupply() -> (totalSupply: Uint256):
    end

    func balanceOf(account: felt) -> (balance: Uint256):
    end

    func allowance(owner: felt, spender: felt) -> (remaining: Uint256):
    end

    func transfer(recipient: felt, amount: Uint256) -> (success: felt):
    end

    func transferFrom(
            sender: felt, 
            recipient: felt, 
            amount: Uint256
        ) -> (success: felt):
    end

    func approve(spender: felt, amount: Uint256) -> (success: felt):
    end

    func increaseAllowance(spender: felt, added_value: Uint256) -> (success: felt):
    end

    func decreaseAllowance(spender: felt, subtracted_value: Uint256) -> (success: felt):
    end
end


```

## ABI

See [Pair ABI](/for-developers/jediswap-v1/smart-contract-reference/pair#abi)


# Risks associated with JediSwap

Below are some risks associated with JediSwap that must be considered before using the protocol.

1\. Network risk

JediSwap is built on Starknet, a layer-2 scaling solution for Ethereum that is still in its infancy.

This presents a systemic risk, as JediSwap users could be affected by any technical or operational problems Starknet suffers.

#### 2. Risk of high slippage

JediSwap is a new project on a new chain with relatively low liquidity. This could lead to severe volatility and high slippage.

It is recommended to set a certain slippage before executing trades. This way, if the actual slippage exceeds the allowed slippage, the transaction will just fail.

Despite this, JediSwap is still the most liquid protocol on Starknet, controlling over 50% of the network's total value locked (TVL).

#### 3. Risk of impermanent loss

Impermanent loss refers to the temporary reduction in the value of an asset when providing liquidity to a liquidity pool.

Understanding impermanent loss is crucial before investing with JediSwap or any other automated market maker (AMM) platform. Knowing impermanent loss helps assess the potential risks and rewards associated with providing liquidity and understand how asset price changes can affect overall returns.

#### 4. Fake tokens

JediSwap is a fully permissionless protocol that enables anyone to create and deploy a liquidity pool for any tokens.

As such, it is important to be very careful and verify a token's contract address before trading or providing liquidity.

Finally, before investing or using any protocol, it is important to do your own research, as JediSwap takes no responsibility for any funds lost.

<br>


