Factory

Code

Factory.cairo

Address

Factory is deployed at:

Starknet Alpha Testnet: 0x0262744f8cea943dadc8823c318eaf24d0110dee2ee8026298f49a3bc58ed74a

Starknet Alpha Mainnet: 0x00dad44c139a476c7a17fc8141e6db680e9abc9f56fe249a105094c44382c2fd

Events

PairCreated​

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

Emitted each time a pair is created via create_pair.

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

View Functions

get_pair

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​

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​

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

Returns the number of pairs created.

get_fee_to​

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

Get fee recipient address. See Protocol Charge Calculation. TODO

get_fee_to_setter​

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

The address allowed to change fee_to via set_fee_to.

get_pair_contract_class_hash​

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

Get the class hash of the Canvas(Pair) contract which is deployed for each create_pair.

State-Changing Functions

create_pair​

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

Creates a pair for tokenA and tokenB.

  • tokenA and tokenB are interchangeable.

set_fee_to​

func set_fee_to(new_fee_to: felt):

Updates fee recipient

  • only fee_to_setter can call.

set_fee_to_setter​

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

%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

[
    {
        "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"
    }
]

Last updated