# 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);
}
```
