jediswap_v2_pool
Functions
initialize
fn initialize(ref self: ContractState, sqrt_price_X96: u256)
Sets the initial price for the pool
Emits Initialize.
Parameters:
sqrt_price_X96
u256
The initial sqrt price of the pool as a Q64.96
mint
fn mint(ref self: ContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount: u128, data: Array<felt252>) -> (u256, u256)
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 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.
Parameters:
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:
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
fn collect(ref self: ContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128)
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.
Parameters:
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:
u128
The amount of fees collected in token0
u128
The amount of fees collected in token1
burn
fn burn(ref self: ContractState, tick_lower: i32, tick_upper: i32, amount: u128) -> (u256, u256)
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.
Emits Burn.
Parameters:
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:
u256
The amount of token0 sent to the recipient
u256
The amount of token1 sent to the recipient
swap
fn swap(ref self: ContractState, recipient: ContractAddress, zero_for_one: bool, amount_specified: i256, sqrt_price_limit_X96: u256, data: Array<felt252>) -> (i256, i256)
Swap token0 for token1, or token1 for token0
The caller of this method receives a callback in the form of jediswap_v2_swap_callback
Emits Swap.
Parameters:
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:
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
fn collect_protocol(ref self: ContractState, recipient: ContractAddress, amount0_requested: u128, amount1_requested: u128) -> (u128, u128)
Collect the protocol fee accrued to the pool
Only the factory owner can call this function.
Emits CollectProtocol.
Parameters:
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:
u128
The protocol fee collected in token0
u128
The protocol fee collected in token1
Events
Initialize
struct Initialize {
sqrt_price_X96: u256,
tick: i32
}
Emitted exactly once by a pool when initialize is first called on the pool
Mint/Burn/Swap cannot be emitted by the pool before Initialize
Parameters:
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
struct Mint {
sender: ContractAddress,
owner: ContractAddress,
tick_lower: i32,
tick_upper: i32,
amount: u128,
amount0: u256,
amount1: u256
}
Parameters:
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
Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
struct Collect {
owner: ContractAddress,
recipient: ContractAddress,
tick_lower: i32,
tick_upper: i32,
amount0: u128,
amount1: u128
}
Parameters:
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
struct Burn {
owner: ContractAddress,
tick_lower: i32,
tick_upper: i32,
amount: u128,
amount0: u256,
amount1: u256
}
Parameters:
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
struct Swap {
sender: ContractAddress,
recipient: ContractAddress,
amount0: i256,
amount1: i256,
sqrt_price_X96: u256,
liquidity: u128,
tick: i32
}
Parameters:
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
struct CollectProtocol {
sender: ContractAddress,
recipient: ContractAddress,
amount0: u128,
amount1: u128
}
Parameters:
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
//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);
}
Last updated