Skip to main content

Pool

Operations

Operation provide_pool_state

Allows the retrieval of the pool's state in an on-chain manner.

When executed, the pool sends a take_pool_state message to the sender containing the requested details.

TL-B
provide_pool_state#6e24728d query_id:uint64 include_assets:Bool = InMsgBody;

take_pool_state#bddd4954 query_id:uint64
reserve0:Coins reserve1:Coins total_supply:Coins
assets:(Maybe ^[ asset0:Asset asset1:Asset ]) = InMsgBody;

Operation configure_start_time

Sets the start_at parameter, defining the UNIX timestamp for the start of trading.

Swap attempts made before this timestamp will be rejected with the error code NOT_STARTED (exit code 306).

TL-B
configure_start_time#7ed7f6ce query_id:uint64 start_at:Timestamp = InMsgBody;

Events

Event swap

TL-B
swap#9c610de3 asset_in:Asset asset_out:Asset amount_in:Coins amount_out:Coins
^[ sender_addr:MsgAddressInt referral_addr:MsgAddress
reserve0:Coins reserve1:Coins ] = ExtOutMsgBody;
NameTypeDescription
asset_inAssetThe asset provided by the user
asset_outAssetThe asset received by the user
amount_inCoinsAmount of asset_out received by the user
amount_outCoinsAmount of asset_out received by the user
sender_addrMsgAddressIntAddress of the contract that initiated the swap
referral_addrMsgAddressreferral_addr passed to SwapParams
reserve0CoinsAmount of asset0 remaining in reserve after the swap
reserve1CoinsAmount of asset1 remaining in reserve after the swap

Event deposit

TL-B
deposit#b544f4a4 sender_addr:MsgAddressInt amount0:Coins amount1:Coins
reserve0:Coins reserve1:Coins liquidity:Coins = ExtOutMsgBody;
NameTypeDescription
sender_addrMsgAddressIntAddress of the contract that initiated the deposit
amount0CoinsAmount of asset_out provided by the sender
amount1CoinsAmount of asset_out provided by the sender
reserve0CoinsAmount of asset0 remaining in reserve after the withdrawal
reserve1CoinsAmount of asset1 remaining in reserve after the withdrawal
liquidityCoinsAmount of LP tokens issued for the sender

Event withdrawal

TL-B
withdrawal#3aa870a6 sender_addr:MsgAddressInt liquidity:Coins
amount0:Coins amount1:Coins
reserve0:Coins reserve1:Coins = ExtOutMsgBody;
NameTypeDescription
sender_addrMsgAddressIntAddress of the contract that initiated the withdrawal
liquidityCoinsAmount of LP tokens burned by the sender
amount0CoinsAmount of asset_out sent to the sender
amount1CoinsAmount of asset_out sent to the sender
reserve0CoinsAmount of asset0 remaining in reserve after the withdrawal
reserve1CoinsAmount of asset1 remaining in reserve after the withdrawal

Get-Methods

Method is_stable

Returns whether the pool operates as a stable-swap pool.

Returns

NameTypeDescription
is_stableint (boolean)Indicates if the pool is a stable-swap pool.

Method get_assets

Returns the assets that constitute the pool.

Returns

NameTypeDescription
asset0slice (Asset)The first asset in the pool.
asset1slice (Asset)The second asset in the pool.

Each asset is represented as a slice and corresponds to an Asset structure.

Method get_trade_fee

Returns the trading fee details of the pool.

The trading fee is calculated as:

trade_fee = (trade_fee_numerator / trade_fee_denominator)

Returns

NameTypeDescription
trade_fee_numeratorint (uint16)The numerator of the trading fee fraction.
trade_fee_denominatorint (uint16)The denominator of the trading fee fraction.

Method get_reserves

Retrieves the current reserves of the assets in the pool.

Returns

NameTypeDescription
reserve0int (Coins)The reserve amount of asset0.
reserve1int (Coins)The reserve amount of asset1.

Method get_protocol_fees

Retrieves the amount of unclaimed protocol fees accrued from trading fees.

Returns

NameTypeDescription
protocol_fees0int (Coins)The unclaimed protocol fees for asset0.
protocol_fees1int (Coins)The unclaimed protocol fees for asset1.

Method get_decimals

Provides information about the decimal precision of the assets in the pool. This is applicable only to stable-swap pools. For volatile pools, the returned values are always 0.

Returns

NameTypeDescription
decimals0int (uint8)The decimal precision of asset0.
decimals1int (uint8)The decimal precision of asset1.

Method estimate_swap_out

Calculates the estimated output and associated fees for a given input amount during a swap.

Parameters

NameTypeDescription
asset_inslice (Asset)The asset being provided for the swap.
amount_inint (Coins)The amount of asset_in being swapped.

Returns

NameTypeDescription
asset_outslice (Asset)The asset being received from the swap.
amount_outint (Coins)The estimated amount of asset_out to be received.
trade_feeint (Coins)The fee deducted in terms of the asset_in provided.

Method estimate_deposit_out

Estimates the output of assets and the corresponding LP tokens when depositing into the pool.

Parameters

NameTypeDescription
amount0int (Coins)The amount of asset0 to be deposited.
amount1int (Coins)The amount of asset1 to be deposited.

Returns

NameTypeDescription
amount0int (Coins)The actual deposited amount of asset0.
amount1int (Coins)The actual deposited amount of asset1.
fair_supplyint (Coins)The amount of minted LP tokens received.

Method get_start_at

Retrieves the start_at parameter, which specifies the UNIX timestamp for the start of trading. This value can be updated using the configure_start_time operation.

By default, start_at is set to 0, indicating no start time is configured.

Returns

NameTypeDescription
start_atint (Timestamp)The UNIX timestamp for trading start.