# 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.md) 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"
    }
]

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jediswap.xyz/for-developers/jediswap-v1/smart-contract-reference/factory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
