Max Size and Locked Amounts
Introduction
Positions on initialization receive two unique values that do not come from the original Jupiter inspiration - max_size and locked_amount.
locked_amount is always a fraction of max_size given by pool_profit_load_percentage_bps on the Pool Limit object, which is present both on Custody and Pool, with the larger of the two values winning out as a deciding factor when calculating the fraction (according to the more reasonable principle).
max_size is determined by the following simple steps, we'll use a long for this example but it can be done easily for a short too.
let min_max_long_size = min(pool.limit.max_long_size, custody.limit.max_long_size);
let unlocked_tokens = custody.assets.base - custody.assets.locked; // usable for loans
let modded_for_incentives = min_max_long_size*position.leverage_modifier_bps;
Ok(min(modded_for_incentives, unlocked_tokens));
You'll note use of the leverage_modifier_bps constant, which is set on initialization of the Position as well and exists partially for modifying max_size to incentivize ratio balancing. You'll also notice that we want to never allow a trade size larger than the current tokens available for loaning, or the max trade size allowed between a Custody and Pool.
How locked_amount is used
When locked_amount is set, it also actually increases the locked field of Custody (cross-covered here) to account for tokens of base being unusable by others. Every time tokens are withdrawn from the Position in a partial closure, or for fee payment, or any reason really, locked_amount (and locked) are decreased.
It represents an amount greater than the initial starting loan + collateral amount for the Position and with the settings on the Custody and Pool is meant to ensure that most Positions never see profits exceeding the locked_amount, so that in normal operations, LP should expect to see losses well contained within the tokens allotted to the Position at creation, but this all requires fine tuning of constants and is not guaranteed.
When this amount is not enough to pay trader profits, the Insurance Fund is the first line of the defense, and following that, the base tokens in the Custody according to the payout rules.
How max_size is used
Aside from being used, as mentioned above, to determine locked_amount, max_size is very important in determining when a Position can be liquidated for being too profitable. If a Position goes even a $1 beyond it's max_size, it is eligible to be liquidated by a liquidator, and when that happens, all owed profits will be paid out to the trader according to the rules laid out in the Liquidation Engine article, however no profits will be paid about beyond the max_size limit.
Last updated