Pair

This documentation covers Uniswap-specific functionality. For ERC-20 functionality, see Pair (ERC-20).

Code

Pair.cairo

Address

See Pair Addresses

Events

Mint​

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

Emitted each time liquidity tokens are created via mint.

Burn​

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

Emitted each time liquidity tokens are destroyed via burn.

Swap​

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

Emitted each time a swap occurs via swap.

Sync​

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

Emitted each time reserves are updated via mint, burn, swap or sync.

View Functions

token0​

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

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

token1​

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

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

get_reserves

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

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

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

price_1_cumulative_last

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

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

kLast​

​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​

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

Creates pool tokens.

burn​

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

Destroys pool tokens.

swap​

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

skim​

func skim(to: felt):

See the uniswap whitepaper.

sync​

func sync():

See the uniswap whitepaper.

Interface

%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

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

Last updated