Skip to content

Conversation

@gdev8317
Copy link
Contributor

@gdev8317 gdev8317 commented Mar 5, 2025

JIT stands for Just-in-time liquidity. This PR adds support for atomic execution of GLV shift and order in the same transaction. from product perspective the idea is to allow creating orders in markets even if there is not enough liquidity. keeper would detect such orders and shift liquidity to the order's market before executing it

Changes:

  • added new JitOrderHandler contract that allow for atomic execution of GLV shifts and orders in the same transaction
  • support GLV oracle price. now it can optionally be used to save gas costs in GLV value calculation. GLV oracle price may deviate slightly from calculated GLV price. added note to the GlvUtils.getGlvValue function. without this executing GLV shift and an order may not be possible due to high gas usage
  • added simulateExecuteLatestJitOrder to ExchangeRouter but had to remove existing simulateExecute* because of contract's side. for order/deposit/withdrawal creation simulateExecuteLatest* functions can be used instead (they don't require key argument)
  • removed onlyController from simulation functions in *Handler contracts. it didn't make much sense because ExchangeRouter's simulation functions (that were just proxies to *Handlers) were public and permissionless. these functions accept key and can be used instead of the ones removed from ExchangeRouter
  • renamed GLV_SHIFT_MAX_PRICE_IMPACT_FACTOR -> GLV_SHIFT_MAX_LOSS_FACTOR. in practice it's not exactly price impact and it led to a confusion

Migration notes:

  • Keeper should validate shifts are not executed too frequently and not too much funds are spent on them (including gas cost and price impact). As an alternative keeper could limit shifts by volume or spent funds instead of count, this would be more accurate
  • Keeper should always use the latest prices for JIT orders
  • Keeper should account for JIT_SHIFT_UPDATE_AT_TIME_BUFFER when validating prices
  • Keeper should fall back to OrderHandler if JitOrderHandler fails
  • GLV shiftMinInterval should be set to 0 after keeper supports shift interval validation. otherwise JIT orders would be blocked by on-chain validation
  • UI and all integrations should migrate to new simulateExecuteLatest* functions for simulations
  • should run glv config scripts to set GLV_SHIFT_MAX_LOSS_FACTOR
  • keeper should switch to GLV_SHIFT_MAX_LOSS_FACTOR
  • UI should validate max pnl of glvDeposit.market

@gdev8317 gdev8317 changed the base branch from updates to v2.2-branch August 18, 2025 20:54
orderKey
);

glvShiftHandler._executeGlvShift(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess it's better to rename _executeGlvShift or create new function, underscore usually means it's private/internal

@gdev8317 gdev8317 changed the title WIP Glv updates WIP Glv updates, JIT Aug 22, 2025

// @dev used by other handlers to avoid duplicating the same code on their side
// this method is similar to `executeOrder` but skips execution gas validation
function executeOrderForController(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should be named executeOrderFromController, to match e.g. DepositHandler.executeDepositFromController

DepositStoreUtils.remove(params.dataStore, params.key, deposit.account());

if (!skipRemoval) {
DepositStoreUtils.remove(params.dataStore, params.key, deposit.account());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if there should be a validation here, e.g.

if (dataStore.containsBytes32(Keys.SHIFT_LIST, key)) {
  revert Errors.RemovalShouldNotBeSkipped(Keys.SHIFT_LIST, key);
}

just to make it more difficult to incorrectly skip removal when code is updated

Base automatically changed from v2.2-branch to updates September 9, 2025 02:32
@sherlock-ai-beta
Copy link

Sherlock AI Findings

The automated tool completed its analysis of the codebase and found no potential security issues.

Next Steps: No immediate actions are required. Continue monitoring the codebase with future scans.

Full report available at: https://ai.sherlock.xyz/runs/132c13f8-6ac3-44ce-a477-fba4c04403be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants