Handles all mathematical calculations in the protocol (swap, provide/remove liquidity), stores an array of bins and LP tokens held in the pool.
Interfaces
provide
Message from pool contract for liquidity provision.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0xbe83bf33 |
| query_id | uint64 | query id |
| code | maybe_cell | range contract code |
| data | maybe_cell | range contract data |
| new_codes | new_code | maybe_cell | new code for range contract. |
| new_codes | new_lpmt_code | maybe_cell | new code for lp multitoken contract. |
| amount_x | coins | total amount of token_x in provision |
| amount_y | coins | total amount of token_y in provision |
| user_address | address | |
| msg_1 | first_bin | int32 | first bin where provision starts. |
| msg_1 | tokens | dict | dictionary with coins for 4 bins of provision. |
| msg_1 | current_bin | int32 | active bin of provision. |
| msg_1 | price_stored | int | flag of further parsing (see below) |
|price_stored=1|sqrt_price|uint256|initial provide price. Ignored if sqrt price already set.|
|msg_1|reject_payload|maybe_cell|reject payload for liquidity provision. Sender recieves it with tokens refund.|
|msg_1|forward_payload|maybe_cell|forward payload for liquidity provision. Sender recieves it with notify from lp multitoken contract.|
notify
Message from pool contract for notifing range contract about its neighbours.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0x5295272c |
| query_id | uint64 | query id |
| code | maybe_cell | range contract code |
| data | maybe_cell | range contract data |
| right? | bool | is message from next range to current |
| range_address | address | address of previous or next range |
swap
Message from pool contract for swap.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0x2198e14d |
| query_id | uint64 | query id |
| to_address | address | receiver address. |
| account? | bool | is trade account contract a receiver. |
| is_x | bool | first or second asset will be sent to the pool. |
| amount | coins | amount of asset for swap. |
| out | coins | amount of asset from swap. |
| exact_out | coins | exact out of tokens to recieve from swap. |
| partial_execution | int | flag of further parsing (see below) |
| partial_execution=0 | normal_slippage | coins | min token out. |
| partial_execution=1 | slippage | uint256 | last sqrt price of swap. |
| ref_cell | maybe_cell | cell with referral address if present. |
| additional_data | maybe_cell | additional data for swap. Now it is address of swap origin. |
| reject_payload | maybe_cell | reject payload for swap. Sender recieves it with tokens refund. |
| forward_payload | maybe_cell | forward payload for swap. Sender recieves it with swapped tokens. |
swap_v2
Message from pool contract for swap.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0xe8e0f806 |
| query_id | uint64 | query id |
| to_address | address | receiver address. |
| account? | bool | is trade account contract a receiver. |
| is_x | bool | first or second asset will be sent to the pool. |
| amount | coins | amount of asset for swap. |
| out | coins | amount of asset from swap. |
| exact_out | coins | exact out of tokens to recieve from swap. |
| partial_execution | int | flag of further parsing (see below) |
| partial_execution=0 | normal_slippage | coins | min token out. |
| partial_execution=1 | slippage | uint256 | last sqrt price of swap. |
| farming_data | distributed_x_amount | coins | amount of rewards distributed. |
| farming_data | distributed_y_amount | coins | amount of rewards distributed. |
| additional_data | maybe_cell | additional data for swap. Now it is address of swap origin and referral address. |
| reject_payload | maybe_cell | reject payload for swap. Sender recieves it with tokens refund. |
| forward_payload | maybe_cell | forward payload for swap. Sender recieves it with swapped tokens. |
continue_swap_v2
Message from itself for continuing swap.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0x60e68ef4 |
| query_id | uint64 | query id |
| to_address | address | receiver address. |
| account? | bool | is trade account contract a receiver. |
| is_x | bool | first or second asset will be sent to the pool. |
| amount | coins | amount of asset for swap. |
| out | coins | amount of asset from swap. |
| exact_out | coins | exact out of tokens to recieve from swap. |
| partial_execution | int | flag of further parsing (see below) |
| partial_execution=0 | normal_slippage | coins | min token out. |
| partial_execution=1 | slippage | uint256 | last sqrt price of swap. |
| rest | previous_time | uint64 | previous swap timestamp. |
| rest | start_price | uint256 | initial price before swap started |
| rest | actual_fee | uint16 | |
| rest | distributed_x_amount | coins | amount of rewards distributed. |
| rest | distributed_y_amount | coins | amount of rewards distributed. |
| additional_data | maybe_cell | additional data for swap. Now it is address of swap origin. |
| reject_payload | maybe_cell | reject payload for swap. Sender recieves it with tokens refund. |
| forward_payload | maybe_cell | forward payload for swap. Sender recieves it with swapped tokens. |
continue_provide
Message from itself for continuing liquidity provision.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0x3685c9c1 |
| query_id | uint64 | query id |
| provide_token1 | coins | amount of token_x in provision |
| provide_token2 | coins | amount of token_y in provision |
| x_excess | coins | excess of token_x to refund to user |
| y_excess | coins | excess of token_y to refund to user |
| user_address | address | |
| first_bin | int32 | first bin where provision starts. |
| bins_num | uint | amount of bins provided previously |
| tokens | dict | dictionary with coins for 4 bins of provision. |
| lp_tokens_to_mint | dict | dictionary with lp tokens to mint. |
| reject_payload | maybe_cell | reject payload for liquidity provision. Sender recieves it with tokens refund. |
| forward_payload | maybe_cell | forward payload for liquidity provision. Sender recieves it with notify from lp multitoken contract. |
burn
Message from lp multitoken contract or itself for burning the liquidity.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0x51597928 |
| query_id | uint64 | query id |
| user_address | address | |
| pay_amount_x | coins | token_x to pay to user |
| pay_amount_y | coins | token_y to pay to user |
| first_bin | int32 | fist bin where burning starts. |
| tokens_to_burn | dict | dictionary with lp tokens to mint. |
| forward_payload | maybe_cell | forward payload which is sent to the user address with withdrawn tokens. |
burn_move
Message from lp multitoken contract or itself for burning and moving the liquidity.
| Path | Mnemonic | Type | Description |
|---|
| op | uint32 | 0x9550b59a |
| query_id | uint64 | query id |
| user_address | address | |
| pay_amount_x | coins | token_x to pay to user |
| pay_amount_y | coins | token_y to pay to user |
| first_bin | int32 | fist bin where burning starts. |
| tokens_to_burn | dict | dictionary with lp tokens to mint. |
| first_bin_to_provide | int32 | fist bin where provision starts. |
| tokens_to_provide | dict | dictionary with coins for 4 bins of provision. |
| forward_payload | maybe_cell | |
Get-methods
get_sqrt_price
Return
| Path | Mnemonic | Type | Description |
|---|
| sqrt_p | number | current sqrt price. |
get_first_bin_number
Return
| Path | Mnemonic | Type | Description |
|---|
| first_bin | number | first bin of current range contract. |
get_bin_step
Return
| Path | Mnemonic | Type | Description |
|---|
| bin_step | number | pool bin step basis point. Number between 0 and 10000. |
get_lp_fee
Return
| Path | Mnemonic | Type | Description |
|---|
| lp_fee | number | lp fee rate. Number between 0 and 10000, where 10000 is 100% lp fee. |
get_current_bin
Return
| Path | Mnemonic | Type | Description |
|---|
| bin_number | number | active bin. |
get_pool_addr
Return
| Path | Mnemonic | Type | Description |
|---|
| pool_addr | address | pool of range contract. |
get_bins_dict
Return
| Path | Mnemonic | Type | Description |
|---|
| liquidity_dict | cell | dictionary with liquidity for each bin |
get_bins_dicts
Return
| Path | Mnemonic | Type | Description |
|---|
| liquidity_dict | cell | dictionary with liquidity for each bin |
| lp_supply_dict | cell | dictionary with lp supply for each bin |
get_lp_multitoken_wallet
| Path | Mnemonic | Type | Description |
|---|
| user_address | slice | lp multitoken owner's address. |
Return
| Path | Mnemonic | Type | Description |
|---|
| lp_multitoken_address | slice | |
get_left_range
Return
| Path | Mnemonic | Type | Description |
|---|
| range_addr | address | previous range address. |
get_right_range
Return
| Path | Mnemonic | Type | Description |
|---|
| range_addr | address | next range address. |
get_bin
| Path | Mnemonic | Type | Description |
|---|
| bin_number | number | |
Return
| Path | Mnemonic | Type | Description |
|---|
| liquidity_in_bin | number | total liquidity in specific bin. |
get_bin_lp
| Path | Mnemonic | Type | Description |
|---|
| bin_number | number | |
Return
| Path | Mnemonic | Type | Description |
|---|
| lp_supply_in_bin | number | supply of lp tokens in specific bin. |
get_price_bounds
| Path | Mnemonic | Type | Description |
|---|
| bin_number | number | |
Return
| Path | Mnemonic | Type | Description |
|---|
| bin_start_price | number | left edge sqrt price of specific bin. |
| bin_end_price | number | right edge sqrt price of specific bin. |
get_collection_data
Return
| Path | Mnemonic | Type | Description |
|---|
| zero | number | |
| content_data | cell | |
| pool_address | address | |
get_dynamic_fee
Return
| Path | Mnemonic | Type | Description |
|---|
| dynamic_fee | number | |
get_get_dynamic_fee_by_timestamp
| Path | Mnemonic | Type | Description |
|---|
| timestamp | number | |
Return
| Path | Mnemonic | Type | Description |
|---|
| dynamic_fee | number | |
get_dynamic_fees_info
Return
| Path | Mnemonic | Type | Description |
|---|
| dynamic_fee | number | |
| dynamic_fee_factor | number | |
| previous_time | number | |
| time_filter | number | |
| time_decay | number | |
get_storage
Return
| Path | Mnemonic | Type | Description |
|---|
| storage | cell | full current storage of the contract. |