Function: set_range_order
The set_range_order
function can be used to create or update an existing range order. It differs from update_range_order
in that it takes a specific amount of liquidity that the order should be set to, instead of an amount that should be added or subtracted. Similarly to update_range_order
, it also takes an order ID and a tick range.
If the order ID is associated with an existing order, that order will be updated; in this case, the tick range is optional, and if provided the order will also be moved from the current to the newly specified tick range. If the order ID does not correspond to an existing order, a new order will be created, and therefore the tick range is required.
The function ensures that safe mode is not enabled and that the caller is a registered liquidity provider. If an existing order ID and a new tick range were provided, it moves the existing order to the new tick range.
It then sets the order liquidity to the given amount. As with update_range_order
, the amount can be specified in terms of an amount of assets or in terms of liquidity.
The user balance is updated every time their position is changed, ensuring the balance is always consistent with the position.