Skip to content

Commit 5cef2f8

Browse files
moosecat20xbigzwphancrispheaneyLukasDeco
authored
Bigz/init lp pool (#1884)
* program: init lp pool * cargo fmt -- * add total fee fields * add update_target_weights math * program: use sparse matrix for constituent map and update tests * zero copy accounts, init ix (#1578) * update accounts (#1580) * zero copy + permissionless crank ixs (#1581) * program: support negative target weights for borrow-lend * fix tests to work with zero copy * few comment changes * remove discriminator from impl macro * add get_swap_amount, get_swap_fees, get_weight (#1579) * add get_swap_amount, get_swap_fees, get_weight * update accounts * add back ts * rebase * add constituent swap fees * fix swap fee calc (#1582) * add init amm mapping to lp context (#1583) * init constituent * add initializeLpPool test (#1585) * add initializeLpPool test * add check for constituent target weights * add add datum ix * add init tests and invariant checks * rename data to more useful names * dlp use spl token program (#1588) * add crank ix * update total_weight for validation_flags check * push test so far * overriding perp position works * remove message * fix dup total_weight add * constituent map remaining accounts * compiles * bankrun tests pass * compiles but casting failure in overflow protection test * address comment and change token arguments from u64 to u128 * bankrun tests pass * init constituent token account (#1596) * update aum calc * add update /remove mapping ixs * fix test - init constituent spot market * add crank improvements * passes tests * precision fix crank aum * precision fixes and constituent map check for account owner * add passthrough account logic (#1602) * add passthrough account logic * cant read yet * fix all zc alignment issues * make oracle source a u8 on zc struct * Wphan/dlp-swap-ixs (#1592) * add lp_swap ix * rebase * test helpers * swap works * fix swaps, add more cargo tests for fees n swap amt * remove console.logs * address PR comments * merge upstream * post-merge fixes * store bumps on accounts (#1604) * store bumps on accounts * do pda check in constituent map * address comments * Wphan/add liquidity (#1607) * add add remove liquidity fees calc * add liquidity ix * fix init mint and lppool token account, refactor test fees * add removeLiquidity bankrun test * merge upstream * add LPPool.next_mint_redeem_id * program: lp-pool-to-use-target-base-vector (#1615) * init lp pool target-base matrix * working target-base logic * add todos for add/remove liquidity aum * add renames + fix test * add beta and cost to trade in bps to target datum * add more tests * add fields to LP events, fix tests (#1620) * add fields to LP events, fix tests * revert target weight calc * add constituent.next_swap_id, fix cost_to_trade math * dlp jup swap (#1636) * dlp jup swap * add admin client ixs * almost fixed * test working? * update begin and end swap * tweaks * fix math on how much was swapped * remove unnecessary lp pool args * extra account validation * added token account pda checks in other ixs * stablecoin targets (#1638) * is stablecoin * address comments --------- Co-authored-by: Chris Heaney <[email protected]> * cleanup * transfer oracle data ix to constituent (#1643) * transfer oracle data ix to constituent * add lib entrypoint * simplify more * add spot market constraint * big cargo test (#1644) * derivative constituents + better testing + bug fixes (#1657) * all tests technically pass * update tests + prettify * bug fixes and tests pass * fix many bugs and finalize logic * deposit/borrow working and changing positions (#1652) * sdk: allow custom coder * program: dlp add upnl for settles to amm cache (#1659) * program: dlp add-upnl-for-settles-to-amm-cache * finish up lp pool transfer from perp market * add amount_to_transfer using diff * merge * add pnl and fee pool accounting + transfer from dlp to perp market --------- Co-authored-by: Nour Alharithi <[email protected]> * remove unused accounts coder * move customCoder into sdk, lint * testing: ix: settle perp to dlp, insufficient balance edge case and improvements (#1688) * finish edge case test * aum check also passes * prettify * added more settle test coverage and squash bugs (#1689) * dlp: add constituentMap (#1699) * Nour/gauntlet fee impl (#1698) * added correlation matrix infra * refactor builds * mint redeem handled for usdc * remove liquidity also should work * all tests pass * bankrun tests pass too * update aum considers amm cache (#1701) * prettify (#1702) * Wphan/merge master dlp (#1703) * feat: init swift user orders on user account creation if needed * fix: wrong pushing of swift user orders ixs * fix: broken swift tests * fix: swift -> signed msg * refactor(sdk): update jupiter's api url * fix(sdk): remove error thrown * indicative qutoes server changes * sdk: release v2.121.0-beta.7 * sdK: update market index 33 oracle rr (#1606) * sdk: add to spot constants market index 34 * revert adminClient.ts change * sdk: update spot market constants oracle index 33 * sdk: release v2.121.0-beta.8 * sdk: high leverage mode updates (#1605) * sdk: high leverage mode updates * add optional param for fee calc * update changelog * sdk: release v2.121.0-beta.9 * getPlaceSignedMsgTakerPerpOrderIxs infer HLM mode from bitflags (#1608) * sdk: release v2.121.0-beta.10 * fix: dehexify in getPlaceSignedMsgTakerPerpOrderIxs (#1610) * fix: dehexify in getPlaceSignedMsgTakerPerpOrderIxs * bankrun test * sdk: release v2.121.0-beta.11 * sdk: round tick/step size for getVammL2Generateor (#1612) * sdk: round tick/step size for etVammL2Generateor * use standard functions, include in all fcns * fix const declare, rm whitespace * fix posdir sign * sdk: release v2.121.0-beta.12 * sdk: release v2.121.0-beta.13 * sdk: constants market-index-45-46 (#1618) * sdk: release v2.121.0-beta.14 * robustness check for indicative quotes sender (#1621) * robustness check for indicative quotes sender * delete quote from market index of bad quote * sdk: release v2.121.0-beta.15 * Added launchTs for ZEUS, zBTC * sdk: release v2.121.0-beta.16 * sdk: bigz/fix-vamm-l2-generator-baseSwapped var assign (#1622) * sdk: release v2.121.0-beta.17 * sdk: fix vamm l2 generator base swapped (#1623) * sdk: bigz/fix-vamm-l2-generator-baseSwapped var assign * fix ask book else baseSwapped calc * sdk: release v2.121.0-beta.18 * sdk: revert vamm l2 gen (#1624) * Revert "sdk: fix vamm l2 generator base swapped (#1623)" This reverts commit 56bc78d. * Revert "sdk: bigz/fix-vamm-l2-generator-baseSwapped var assign (#1622)" This reverts commit e49cfd5. * Revert "sdk: round tick/step size for getVammL2Generateor (#1612)" This reverts commit f932a4e. * sdk: release v2.121.0-beta.19 * sdk: show protected-asset have zero-borrow-limit (#1603) * sdk: show protected-asset have zero-borrow-limit * rm unused AssetTier import * sdk: release v2.121.0-beta.20 * sdk: market-constants-index-74 (#1629) * sdk: release v2.121.0-beta.21 * program: use saturating_sub for number_of_users (#1616) * program: use saturating_sub for number_of_users * update CHANGELOG.md * program: allow fixing hlm num users (#1630) * sdk: release v2.121.0-beta.22 * sdk: fix switchboard on demand client to use landed at * sdk: release v2.121.0-beta.23 * sdk: spot-market-poolid-4 constants (#1631) * sdk: release v2.121.0-beta.24 * fix high lev mode liq price (#1632) * sdk: release v2.121.0-beta.25 * replace deprecated solana install scripts (#1634) * sdk: release v2.121.0-beta.26 * refactor(sdk): use ReturnType for Timeout types (#1637) * sdk: release v2.121.0-beta.27 * auction price sdk fix * sdk: release v2.121.0-beta.28 * program: multi piecewise interest rate curve (#1560) * program: multi-piecewise-interest-rate-curve * update tests * widen out borrow limits/healthy util check * add break, use array of array for borrow slope segments * program: fix cargo test * sdk: add segmented IR curve to interest rate calc * clean up unusded var, make interest rate segment logic a const * incorp efficiency feedback points * test: add sol realistic market example * cargo fmt -- * CHANGELOG --------- Co-authored-by: Chris Heaney <[email protected]> * sdk: release v2.121.0-beta.29 * program: allow hot admin to update market fuel params (#1640) * v2.121.0 * sdk: release v2.122.0-beta.0 * sdk: fix nullish coalescing * sdk: release v2.122.0-beta.1 * program: add logging for wrong perp market mutability * sdk: check free collateral change in maxTradeSizeUsdcForPerp (#1645) * sdk: check free collateral change in maxTradeSizeUsdcForPerp * update changelog * sdk: release v2.122.0-beta.2 * refactor(sdk): emit newSlot event on initial subscribe call (#1646) * sdk: release v2.122.0-beta.3 * sdk: spot-market-constants-pool-id-2 (#1647) * sdk: release v2.122.0-beta.4 * sdk: add-spot-market-index-52-constants (#1649) * sdk: release v2.122.0-beta.5 * program: add existing position fields to order records (#1614) * program: add quote entry amount to order records * fix cargo fmt and test * more reusable code * more reusable code * add another comment * fix math * account for pos flip * fix typo * missed commit * more fixes * align naming * fix typo * CHANGELOG * program: check limit price after applying buffer in trigger limit ord… (#1648) * program: check limit price after applying buffer in trigger limit order auction * program: reduce duplicate code * fix tests * CHANGELOG --------- Co-authored-by: 0xbigz <[email protected]> * program: fix cargo tests * program: check limit price when setting auction for limit order (#1650) * program: check limit price after applying buffer in trigger limit order auction * program: reduce duplicate code * program: check limit price when setting limit auction params * cargo fmt -- * fix CHANGELOG * tests: updates switchboardTxCus.ts * program: try to fix iteration for max order size (#1651) * Revert "program: try to fix iteration for max order size (#1651)" This reverts commit 3f0eab3. * disable debug logging in bankrun tests * v2.122.0 * sdk: release v2.123.0-beta.0 * sdk: constants-spot-market-index-53 (#1655) * sdk: release v2.123.0-beta.1 * sdk: idl for new existing position order action records * fix: protocol test prettier fix * make ci lut checks not shit * sdk: release v2.123.0-beta.2 * sdk: fix vamm l2 generator base swapped and add new top of book (#1626) * sdk: bigz/fix-vamm-l2-generator-baseSwapped var assign * fix ask book else baseSwapped calc * use proper quoteAmount with baseSwap for top of book orders * clean up console.log * sdk: getVammL2Generator reduce loc (#1628) * sdk: getVammL2Generator-reduce-loc * add MAJORS_TOP_OF_BOOK_QUOTE_AMOUNTS * add marketindex check topOfBookAmounts * yarn lint/prettier * sdk: release v2.123.0-beta.3 * program: allow all limit orders to go through swift (#1661) * program: allow all limit orders to go through swift * add anchor test * CHANGELOG * sdk: add optional initSwiftAccount on existing account deposits (#1660) * sdk: release v2.123.0-beta.4 * program: add taker_speed_bump_override and amm_spread_adjustment * Revert "program: add taker_speed_bump_override and amm_spread_adjustment" This reverts commit 1e19b7e. * program: tests-fee-adjustment-neg-100 (#1656) * program: tests-fee-adjustment-neg-100 * add HLM field to test * cargo fmt -- --------- Co-authored-by: Chris Heaney <[email protected]> * program: simplify user can skip duration (#1668) * program: simplify user can skip duration * update context * CHANGELOG * fix test * fix pmm tests --------- Co-authored-by: Chris Heaney <[email protected]> * program: add taker_speed_bump_override and amm_spread_adjustment (#1665) * program: add taker_speed_bump_override and amm_spread_adjustment * add admin client * cargo test * add impl for amm_spread_adjustment * ensure no overflows * CHANGELOG * cargo fmt -- * sdk types * prettify --------- Co-authored-by: 0xbigz <[email protected]> * program: update-amm-spread-and-availability-constraints (#1663) * program: update-amm-spread-and-availability-constraints * fix cargo tests * program: use saturating mul for amm spread adj * nour/indic-quotes-sender-v2 (#1667) * nour/indic-quotes-sender-v2 * prettify * pass margin category into calculateEntriesEffectOnFreeCollateral (#1669) * fix cargo test * tests: fix oracle guardrail test * sdk: update idl * yarn prettify:fix * tests: fix a few more place and make tests * prettify fix * whitespace readme change * sdk: release v2.123.0-beta.5 * v2.123.0 * sdk: release v2.124.0-beta.0 * v2.123.0-1 * sdk: calculateVolSpreadBN-sync (#1671) * sdk: release v2.124.0-beta.1 * sdk: calculate-spread-bn-add-amm-spread-adjustment (#1672) * sdk: calculate-spread-bn-add-amm-spread-adjustment * corect sign * add math max 1 * prettify * sdk: release v2.124.0-beta.2 * sdk: correct calculateVolSpreadBN reversion * sdk: release v2.124.0-beta.3 * sdk: add getTriggerAuctionStartPrice (#1654) * sdk: add getTriggerAuctionStartPrice * updates * precisions * remove startBuffer param --------- Co-authored-by: Chris Heaney <[email protected]> * sdk: release v2.124.0-beta.4 * feat: customized cadence account loader (#1666) * feat: customized cadence account loader bby * feat: method to read account cadence on custom cadence account loader * feat: PR feedback on customized loader cleaup code and better naming * fix: lint and prettify * feat: more efficient rpc polling on custom polling intervals * feat: custom cadence acct loader override load * chore: prettify * sdk: release v2.124.0-beta.5 * sdk: sync-user-trade-tier-calcs (#1673) * sdk: sync-user-trade-tier-calcs * prettify --------- Co-authored-by: Nick Caradonna <[email protected]> * sdk: release v2.124.0-beta.6 * sdk: add new admin client fn * Revert "sdk: add new admin client fn" This reverts commit c7a4f0b. * sdk: release v2.124.0-beta.7 * refactor(ui): add callback logic, fix polling frequency update * sdk: release v2.124.0-beta.8 * program: less order param sanitization for long tail perps (#1680) * program: allow-auction-start-buffer-on-tail-mkt * fix test * cargo fmt -- * CHANGELOG --------- Co-authored-by: 0xbigz <[email protected]> * Wphan/custom coder (#1682) * sdk: allow custom coder * remove unused accounts coder * linter * move customCoder into sdk, lint * update test helpers * update testhelpers.ts * sdk: release v2.124.0-beta.9 * update sdk exports * sdk: release v2.124.0-beta.10 * sdk: safer-calculate-spread-reserve-math (#1681) * sdk: release v2.124.0-beta.11 * update getMaxLeverageForPerp to use usdc logic (#1678) * sdk: release v2.124.0-beta.12 * program: override for oracle delay (#1679) * programy: override for oracle delay * update impl * switch to i8 * CHANGELOG * program: programmatic rebalance between protocol owned if holdings (#1653) * program: if swap * program: add initial config * add update * more * moar * moar * moar * program: update how swap epoch works * add test * add an invariant * cargo fmt -- * add transfer to rev pool * add mint validation * cargo fmt -- * track in amount between tranfsers * add to ci tests * separate key * program: always transfer max amount to rev pool * CHANGELOG * sdk: release v2.124.0-beta.13 * sdk: improve-aclient-accounts-logic (#1684) * sdk: release v2.124.0-beta.14 * program: improve-amm-spread-validates (#1685) * program: let hot wallet update amm jit intensity * sdk: hot wallet can update amm jit intensity * program: hot wallet can update curve intensity * program: fix build * sdk: update idl * sdk: release v2.124.0-beta.15 * v2.124.0 * sdk: release v2.125.0-beta.0 * program: three-point-std-estimator (#1686) * program: three-point-std-estimator * update tests and add sdk * update changelog * sdk: add-updatePerpMarketOracleSlotDelayOverride (#1691) * sdk: release v2.125.0-beta.1 * program: add-amm-inventory-spread-adjustment-param (#1690) * program: add-amm-inventory-spread-adjustment-param * cargo fmt -- * update sdk * prettier * fix syntax { --------- Co-authored-by: Chris Heaney <[email protected]> * program: max-apr-rev-settle-by-spot-market (#1692) * program: max-apr-rev-settle-by-spot-market * update max * default to u128 to avoid casts * changelog * sdk: release v2.125.0-beta.2 * program: better account for imf in calculate_max_perp_order_size (#1693) * program: better account for imf in calculate_max_perp_order_size * CHANGELOG * v2.125.0 * sdk: release v2.126.0-beta.0 * sdk: only count taker fee in calculateEntriesEffectOnFreeCollateral for maintenance (#1694) * sdk: release v2.126.0-beta.1 * Separate getAddInsuranceFundStakeIxs (#1695) * sdk: release v2.126.0-beta.2 * idl: amm-inv-adj-latest-idl (#1697) * sdk: release v2.126.0-beta.3 * sdk: spot-market-index-54 constants (#1696) * sdk: release v2.126.0-beta.4 * sdk: update spot market index 54 pythlazer id * sdk: release v2.126.0-beta.5 * Update spotMarkets.ts * sdk: release v2.126.0-beta.6 * prettify --------- Co-authored-by: Lukas deConantsesznak <[email protected]> Co-authored-by: Chester Sim <[email protected]> Co-authored-by: Nour Alharithi <[email protected]> Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: bigz_Pubkey <[email protected]> Co-authored-by: lowkeynicc <[email protected]> Co-authored-by: jordy25519 <[email protected]> Co-authored-by: Luke Steyn <[email protected]> Co-authored-by: lil perp <[email protected]> Co-authored-by: LukasDeco <[email protected]> Co-authored-by: Nick Caradonna <[email protected]> Co-authored-by: Jesse Cha <[email protected]> * slot staleness checks (#1705) * slot staleness checks * update aum ix to use constituent oracles * Nour/derivative constituent testing (#1708) * slot staleness checks * update aum ix to use constituent oracles * constituent test works when adjusting derivative index * constituent depeg kill switch works * works with multiple derivatives on the same parent * remove incorrect usage of nav * fix adminClient and tests * Nour/fee grid search testing (#1714) * grid search * grid search swap test * Nour/address comments (#1715) * low hanging fruit comments * remove pda checks and store lp pool on zero copy accounts * parameterize depeg threshold * make description in lp pool event * update idl for event change * add swap fee unit tests (#1713) * add swap fee unit tests * remove linear inventory fee component * Nour/settle accounting (#1723) * fixing the main settle test and settle function * all current tests pass * update msg occurrences * dont update lp quote owed unless collateralized * Nour/settle testing (#1725) * refactor settle pnl to modularize and add tests * more cargo tests * prettify * Nour/address more comments (#1726) * use oracle staleness threshold for staleness * add spot market vault invariant * refactor update_aum, add unit tests (#1727) * refactor update_aum, add unit tests * add constituent target base tests * update doc * Nour/parameterize dlp (#1731) * add validates and test for withdraw limit * settlement max * update idl * merge conflicts * fixes * update idl * bug fixes * mostly sdk fixes * bug fixes * bug fix and deploy script * program: new amm oracle (#1738) * zero unused amm fields * cargo fmt * bare bones ix * minimal anchor mm oracle impl * update test file * only do admin validate when not anchor test * updates * generalize native entry * fix weird function name chop off * make it compile for --feature cpi (#1748) Co-authored-by: jordy25519 <[email protected]> * more efficeint clock and state bit flags check * vamm uses mm oracle (#1747) * add offset * working tests * refactor to use MM oracle as its own type * remove weird preface * sdk updates * bankrun tests all pass * fix test * changes and fixes * widen confidence if mm oracle too diff * sdk side for confidence adjust * changelog * fix lint * fix cargo tests * address comments * add conf check * remove anchor ix and cache oracle confidence * only state admin can reenable mm oracle kill switch * cargo fmt --------- Co-authored-by: jordy25519 <[email protected]> * fix tests (#1764) * Nour/move ixs around (#1766) * move around ixs * remove message * add devnet oracle crank wallet * refactored mm oracle * sdk changes + cargo fmt * fix tests * validate price bands with fill fix * normalize fill within price bands * add sdk warning * updated type * undefined guard so anchor tests pass * accept vec for update amm and view amm * adjust test to work with new price bands * Revert "adjust test to work with new price bands" This reverts commit ee40ac8. * remove price bands logic * add zero ix for mm oracle for reset * add new drift client ix grouping * v1 safety improvements * isolate funding from MM oracle * add cargo tests for amm availability * change oracle validity log bool to enum * address comment * make validate fill direction agnostic * fix liquidate borrow for perp pnl test * fix tests and address comments * commit constituent map to barrel file * add lp fields to perp market account * rearrange perp market struct for lp fields * bug fix for notional position tracking * view function * fee view functions * max aum + whitelist check and removing get_mint_redeem_fee for now * add wsol support for add liquidity * fix sdk and typing bugs * update lp pool params ix * admin override cache and disable settle functions * devnet swap working * dlp taker discovered bug fixes and sdk changes * refactor last settle ts to last settle slot * Nour/settle pnl fix (#1817) * settle perp to lp pool bug fixes * update bankrun test to not use admin fee pool deposit * fix tests using update spot market balances too * add log msgs for withdraw and fix casting bug * check in for z (#1823) * feat: option for custom oracle ws subscriber * fix: pass custom oracle ws sub option in dc constructor * sdk: add spot-market-index-57 to constants (#1815) * sdk: release v2.134.0-beta.2 * lazer oracle migration (#1813) * lazer oracle migration * spot markets too * sdk: release v2.134.0-beta.3 * sdk: release v2.134.0-beta.4 * program: settle pnl invariants (#1812) * program: settle pnl invariants * add test * fix lint * lints * add msg * CHANGELOG * cargo fmt -- * program: add_update_perp_pnl_pool (#1810) * program: add_update_perp_pnl_pool * test * CHANGELOG * sdk: release v2.134.0-beta.5 * program: update-mark-twap-integer-bias (#1783) * program: update-mark-twap-integer-bias * changelog update * program: update-fee-tier-determine-fix5 (#1800) * program: update-fee-tier-determine-fix5 * update changelog * program: update-mark-twap-crank-use-5min-basis (#1769) * program: update-mark-twap-crank-use-5min-basis * changelog * program: update-min-margin-const-limit (#1802) * program: update-min-margin-const-limit * add CHANGELOG.md * sdk: release v2.134.0-beta.6 * program: rm-burn-lp-shares-invariant (#1816) * program: rm-burn-lp-shares-invariant * update changelog * fix test and cargo fmt * fix anchor tests * yarn prettify:fix * reenable settle_pnl mode test * v2.134.0 * sdk: release v2.135.0-beta.0 * Merge pull request #1820 from drift-labs/chester/fix-zod * sdk: release v2.135.0-beta.1 * mm oracle sdk change (#1806) * mm oracle sdk change * better conditional typing * DLOB bug fix * updated idl * rm getAmmBidAskPrice * sdk: release v2.135.0-beta.2 * sdk: fix isHighLeverageMode * sdk: release v2.135.0-beta.3 * refactor(sdk): add update delegate ix method, ovrride authority for settle multiple pnl (#1822) * check in for z * more logging changes * mm oracle sdk additions (#1824) * strict typing for more MM oracle contact points * add comments to auction.ts * prettify * sdk: release v2.135.0-beta.4 * init constituent bug fix and type change * add in invariant to be within 1 bp of balance before after * add strict typing for getPrice and new auction trigger function (#1826) * add strict typing for getPrice and new auction trigger function * refactor getTriggerAuctionStartAndExecutionPrice * sdk: release v2.135.0-beta.5 * update tests and enforce atomic settles for withdraw * add failing withdraw test * withdraw fix * bring diff in validate back to 1 * make lp pool test fail * better failed test * only check after < before, do to spot precision limits * add balance check to be < 1 cent --------- Co-authored-by: Lukas deConantsesznak <[email protected]> Co-authored-by: bigz_Pubkey <[email protected]> Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: LukasDeco <[email protected]> Co-authored-by: lil perp <[email protected]> Co-authored-by: wphan <[email protected]> Co-authored-by: Chester Sim <[email protected]> * add price for lp validates (#1833) * add missing token account reloads and syncs * add disabled lp pool swaps by default * more extensive aum logging * Wphan/merge-builder-codes (#1842) * add RevenueShare and RevenueShareEscrow accounts an init ixs * fix multiple array zc account, and handling different message types in place_signed_msg_taker_order * decoding error * recording orders in RevenueShareEscrow workin * cancel and fill orders * idl * fix sdk build * fix math * update RevenueShareOrder bitflags, store builder_idx instead of pubkey * merge RevenueShareOrders on add * remove builder accounts from cancel ixs, wip settle impl * dont fail settlpnl if no builder users provided * finish settle, rename RevenueShare->Builder, RevenueShareEscrow->BuilderEscrow * feat: option for custom oracle ws subscriber * fix: pass custom oracle ws sub option in dc constructor * sdk: add spot-market-index-57 to constants (#1815) * sdk: release v2.134.0-beta.2 * lazer oracle migration (#1813) * lazer oracle migration * spot markets too * sdk: release v2.134.0-beta.3 * sdk: release v2.134.0-beta.4 * program: settle pnl invariants (#1812) * program: settle pnl invariants * add test * fix lint * lints * add msg * CHANGELOG * cargo fmt -- * program: add_update_perp_pnl_pool (#1810) * program: add_update_perp_pnl_pool * test * CHANGELOG * sdk: release v2.134.0-beta.5 * program: update-mark-twap-integer-bias (#1783) * program: update-mark-twap-integer-bias * changelog update * program: update-fee-tier-determine-fix5 (#1800) * program: update-fee-tier-determine-fix5 * update changelog * program: update-mark-twap-crank-use-5min-basis (#1769) * program: update-mark-twap-crank-use-5min-basis * changelog * program: update-min-margin-const-limit (#1802) * program: update-min-margin-const-limit * add CHANGELOG.md * sdk: release v2.134.0-beta.6 * program: rm-burn-lp-shares-invariant (#1816) * program: rm-burn-lp-shares-invariant * update changelog * fix test and cargo fmt * fix anchor tests * yarn prettify:fix * reenable settle_pnl mode test * v2.134.0 * sdk: release v2.135.0-beta.0 * add more bankrun tests, clean up * clean up, fix tests * why test fail * add subaccountid to BuilderOrder * reduce diff * add referrals * add test can fill settle user with no builderescrow * add referral builder feature flag and referral migration method * fix cargo tests, try fix bankrun test timing issue * Merge pull request #1820 from drift-labs/chester/fix-zod * sdk: release v2.135.0-beta.1 * mm oracle sdk change (#1806) * mm oracle sdk change * better conditional typing * DLOB bug fix * updated idl * rm getAmmBidAskPrice * sdk: release v2.135.0-beta.2 * sdk: fix isHighLeverageMode * sdk: release v2.135.0-beta.3 * refactor(sdk): add update delegate ix method, ovrride authority for settle multiple pnl (#1822) * mm oracle sdk additions (#1824) * strict typing for more MM oracle contact points * add comments to auction.ts * prettify * sdk: release v2.135.0-beta.4 * add strict typing for getPrice and new auction trigger function (#1826) * add strict typing for getPrice and new auction trigger function * refactor getTriggerAuctionStartAndExecutionPrice * sdk: release v2.135.0-beta.5 * sdk: handle unfillable reduce only orders (#1790) * sdk: handle unfillable reduce only orders * fix dlob tests build errors * fix some test build errors * sdk: release v2.135.0-beta.6 * ref price offset amm math fix (#1828) * ref price offset amm math fix * add latest slot optional var to callers of update amm spread * sdk: release v2.135.0-beta.7 * latest slot as argument to getL2 (#1829) * latest slot as argument to getL2 * add comment * update BN import * sdk: release v2.135.0-beta.8 * add SignedMsgOrderParamsMessageV2 * program: trigger price use 5min mark price (#1830) * program: trigger price use 5min mark price * cargo fmt -- --------- Co-authored-by: 0xbigz <[email protected]> * v2.135.0 * sdk: release v2.136.0-beta.0 * zero pad swift messages to make backwards compatible * PR feedback * update tests/placeAndMakeSignedMsgBankrun.ts to handle client side errors * lukas/websocket improvements (#1807) * feat: initial implementation for users and markets WS improvements * lukas/gill websocket sub (#1781) * websockets gill temp * feat: feature parity between gill version ws acct sub and reg one + optional passing into driftClient * fix: post rebase bugs and cleanup * chore: websocket account subscriber export * feat: logging string update on ws acct v2 * rm: useless logging * chore: cleanup ws subscriber v2 docs * chore: specific name on custom ws acct sub param * fix: post rebase again cleanup * fix: prettier fixed * feat: initial implementation for users and markets WS improvements * feat: polling check on websocket acct subscriber v2 + naming * fix: lint * fix: non-hanging WS subscription async loop handling * fix: bugs with program ws subs hanging on asynciter * fix: goofy self imports * feat: initial batch fetching temp * temp: sub second WS subscribe time * fix: ws program account subscriber v2 bugs and optimizations * feat: chunk stuff account requests * feat: more subscribe optimizations ws driftclient sub v2 * chore: cleanup ws sub v2 logs * feat: conditional check on using ws account subscriber + unused * fix: bad import * chore: add export of WebSocketProgramAccountSubscriberV2 * fix: unneeded drift idl export messing up common build * fix: consolidate rpc ws subscriptions for oracles * feat: docs for ws v2 and cleanup * chore: more docs on ws acct susbcriber v2 * feat: PR feedback round 2 * fix: default timeout for ws v2 susbcribers * feat: PR feedback on resubOpts and simplify logic * fix: prettier * sdk: release v2.136.0-beta.1 * refactor(sdk): add decimal override for bignum prettyPrint * sdk: release v2.136.0-beta.2 * sdk: while valid tx sender memory leak fix * sdk: release v2.136.0-beta.3 * refactor account logic for borrows * remove double fee count, update tests to check filled position and quote amounts fda * rename Builder -> RevenueShare * add test check accumulated builder/ref fees * fix settle multiple pnl accounts, test ref rewards in multiple markets * [ FIX ] `posaune0423/fix tx fee payer` (#1837) * sdk: release v2.136.0-beta.4 * sdk: add constant for spot market index 58 (#1840) * sdk: add spot market constant 58 * revert .sh * sdk: release v2.136.0-beta.5 * Revert "[ FIX ] `posaune0423/fix tx fee payer` (#1837)" (#1841) This reverts commit 8cc07e0. * sdk: release v2.136.0-beta.6 * express builder fees in tenth of bps * update referral migration params * PR feedback * add builder code feature gate * fix tests * add referral fields * run all tests * kickoff build * disable extra instructions, fix builder code feature flag selection --------- Co-authored-by: Lukas deConantsesznak <[email protected]> Co-authored-by: bigz_Pubkey <[email protected]> Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: moosecat <[email protected]> Co-authored-by: LukasDeco <[email protected]> Co-authored-by: lil perp <[email protected]> Co-authored-by: Chester Sim <[email protected]> Co-authored-by: asuma <[email protected]> * calc aum bug fix for borrows * idl changes and drift client working * Wphan/dlp revert builder codes (#1854) * Revert "Wphan/merge-builder-codes (#1842)" This reverts commit c999f83. * fix conflicts * fix incorrect merges * address some perp comments * respond to more comments * pda efficiency changes * Revert "pda efficiency changes" This reverts commit 578b957. * Revert "respond to more comments" This reverts commit 27600a1. * better wsol handling * subtract exchange fees from amount settled (#1849) * subtract exchange fees from amount settled * add exchange fee scalar to settling * use percents isntead of scalars * re-introduce breaking bchanges * pda efficiency changes * more pda changes * fix tests * merge in crisp token authority changes * address more comments * amm cache rework (#1863) * Crispheaney/lp whitelist mint (#1866) * lp whitelist mint * test * prettify * Crispheaney/zero copy oracle validity (#1865) * amm cache zero copy validity * remove unnecessary fields from amm cache * update pda --------- Co-authored-by: Nour Alharithi <[email protected]> * address renaming comments * Nour/cu profiling (#1870) * add CU profiling test * reduce CUs for target base * cache robustness and limit testing CUs * pass through trade ratio in fee calcs * Crispheaney/withdraw in rm liquidity (#1871) * init * fail transfer_from_program_vault if withdraw too big * test * Nour/expand lp status (#1867) * constituent status and paused operations * add admin functions and tests * add lp status checks * testing expanded to lp pool paushed operations on perp markets * make new wallet for lp taker swaps rather than hot wallet * idl changes and bug fixes * improve CUs for target base * more CU opts * more CU reduction in target crank * lp/init lp-settle-records (#1872) * init lp-settle-records * update pr to emit event * add in last settle ts --------- Co-authored-by: Nour Alharithi <[email protected]> * remove more unused lp pool params * update idl * update constituent target params vals * update idl * Crispheaney/rm mint (#1875) * rm unnecessary mints * sdk updates --------- Co-authored-by: Nour Alharithi <[email protected]> * add constituent map memcmp and lp status on cache * update tests and amm cache iteration method * change target base ix ordering * update admin client whitelistdlp token ix and other things --------- Co-authored-by: 0xbigz <[email protected]> Co-authored-by: wphan <[email protected]> Co-authored-by: Chris Heaney <[email protected]> Co-authored-by: Lukas deConantsesznak <[email protected]> Co-authored-by: Chester Sim <[email protected]> Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lowkeynicc <[email protected]> Co-authored-by: jordy25519 <[email protected]> Co-authored-by: Luke Steyn <[email protected]> Co-authored-by: LukasDeco <[email protected]> Co-authored-by: Nick Caradonna <[email protected]> Co-authored-by: Jesse Cha <[email protected]> Co-authored-by: asuma <[email protected]>
1 parent 803fc32 commit 5cef2f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+22066
-599
lines changed

CHANGELOG.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939

4040
### Breaking
4141

42-
## [2.135.0] - 2025-08-22
43-
44-
### Features
45-
46-
### Fixes
47-
48-
- program: trigger price use 5min mark price ([#1830](https://github.com/drift-labs/protocol-v2/pull/1830))
49-
50-
### Breaking
51-
5242
## [2.134.0] - 2025-08-13
5343

5444
### Features

programs/drift/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ drift-rs=[]
2020
[dependencies]
2121
anchor-lang = "0.29.0"
2222
solana-program = "1.16"
23-
anchor-spl = "0.29.0"
23+
anchor-spl = { version = "0.29.0", features = [] }
2424
pyth-client = "0.2.2"
2525
pyth-lazer-solana-contract = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "d790d1cb4da873a949cf33ff70349b7614b232eb", features = ["no-entrypoint"]}
2626
pythnet-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "3e8a24ecd0bcf22b787313e2020f4186bb22c729"}

programs/drift/src/controller/amm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::math::amm::calculate_quote_asset_amount_swapped;
1515
use crate::math::amm_spread::{calculate_spread_reserves, get_spread_reserves};
1616
use crate::math::casting::Cast;
1717
use crate::math::constants::{
18-
CONCENTRATION_PRECISION, FEE_ADJUSTMENT_MAX, FEE_POOL_TO_REVENUE_POOL_THRESHOLD,
19-
K_BPS_UPDATE_SCALE, MAX_CONCENTRATION_COEFFICIENT, MAX_K_BPS_INCREASE, MAX_SQRT_K,
18+
CONCENTRATION_PRECISION, FEE_POOL_TO_REVENUE_POOL_THRESHOLD, K_BPS_UPDATE_SCALE,
19+
MAX_CONCENTRATION_COEFFICIENT, MAX_K_BPS_INCREASE, MAX_SQRT_K,
2020
};
2121
use crate::math::cp_curve::get_update_k_result;
2222
use crate::math::repeg::get_total_fee_lower_bound;

programs/drift/src/controller/liquidation.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ use crate::math::safe_math::SafeMath;
5050

5151
use crate::math::spot_balance::get_token_value;
5252
use crate::state::events::{
53-
emit_stack, LPAction, LPRecord, LiquidateBorrowForPerpPnlRecord,
54-
LiquidatePerpPnlForDepositRecord, LiquidatePerpRecord, LiquidateSpotRecord, LiquidationRecord,
55-
LiquidationType, OrderAction, OrderActionExplanation, OrderActionRecord, OrderRecord,
56-
PerpBankruptcyRecord, SpotBankruptcyRecord,
53+
LiquidateBorrowForPerpPnlRecord, LiquidatePerpPnlForDepositRecord, LiquidatePerpRecord,
54+
LiquidateSpotRecord, LiquidationRecord, LiquidationType, OrderAction, OrderActionExplanation,
55+
OrderActionRecord, OrderRecord, PerpBankruptcyRecord, SpotBankruptcyRecord,
5756
};
5857
use crate::state::fill_mode::FillMode;
5958
use crate::state::margin_calculation::{MarginCalculation, MarginContext, MarketIdentifier};
@@ -65,7 +64,6 @@ use crate::state::perp_market_map::PerpMarketMap;
6564
use crate::state::spot_market::SpotBalanceType;
6665
use crate::state::spot_market_map::SpotMarketMap;
6766
use crate::state::state::State;
68-
use crate::state::traits::Size;
6967
use crate::state::user::{MarketType, Order, OrderStatus, OrderType, User, UserStats};
7068
use crate::state::user_map::{UserMap, UserStatsMap};
7169
use crate::{get_then_update_id, load_mut, LST_POOL_ID};

programs/drift/src/controller/orders.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ use crate::math::spot_balance::{get_signed_token_amount, get_token_amount};
4848
use crate::math::spot_swap::select_margin_type_for_swap;
4949
use crate::math::{amm, fees, margin::*, orders::*};
5050
use crate::print_error;
51-
use crate::state::events::{
52-
emit_stack, get_order_action_record, LPAction, LPRecord, OrderActionRecord, OrderRecord,
53-
};
51+
use crate::state::events::{emit_stack, get_order_action_record, OrderActionRecord, OrderRecord};
5452
use crate::state::events::{OrderAction, OrderActionExplanation};
5553
use crate::state::fill_mode::FillMode;
5654
use crate::state::fulfillment::{PerpFulfillmentMethod, SpotFulfillmentMethod};

programs/drift/src/controller/position/tests.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ fn amm_perp_ref_offset() {
11771177
max_ref_offset,
11781178
)
11791179
.unwrap();
1180-
assert_eq!(res, (perp_market.amm.max_spread / 2) as i32);
1180+
assert_eq!(res, 45000);
11811181
assert_eq!(perp_market.amm.reference_price_offset, 18000); // not updated vs market account
11821182

11831183
let now = 1741207620 + 1;
@@ -1256,21 +1256,15 @@ fn amm_perp_ref_offset() {
12561256
// Uses the original oracle if the slot is old, ignoring MM oracle
12571257
perp_market.amm.mm_oracle_price = mm_oracle_price_data.get_price() * 995 / 1000;
12581258
perp_market.amm.mm_oracle_slot = clock_slot - 100;
1259-
let mut mm_oracle_price = perp_market
1259+
let mm_oracle_price = perp_market
12601260
.get_mm_oracle_price_data(
12611261
oracle_price_data,
12621262
clock_slot,
12631263
&state.oracle_guard_rails.validity,
12641264
)
12651265
.unwrap();
12661266

1267-
let _ = _update_amm(
1268-
&mut perp_market,
1269-
&mut mm_oracle_price,
1270-
&state,
1271-
now,
1272-
clock_slot,
1273-
);
1267+
let _ = _update_amm(&mut perp_market, &mm_oracle_price, &state, now, clock_slot);
12741268
let reserve_price_mm_offset_3 = perp_market.amm.reserve_price().unwrap();
12751269
let (b3, a3) = perp_market
12761270
.amm

programs/drift/src/controller/spot_balance.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ pub fn update_spot_balances(
250250
}
251251

252252
if token_amount > 0 {
253+
msg!("token amount to transfer: {}", token_amount);
253254
spot_balance.update_balance_type(*update_direction)?;
254255
let round_up = update_direction == &SpotBalanceType::Borrow;
255256
let balance_delta =
256257
get_spot_balance(token_amount, spot_market, update_direction, round_up)?;
258+
msg!("balance delta {}", balance_delta);
257259
spot_balance.increase_balance(balance_delta)?;
258260
increase_spot_balance(balance_delta, spot_market, update_direction)?;
259261
}

programs/drift/src/controller/token.rs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use anchor_spl::token_2022::spl_token_2022::extension::{
99
};
1010
use anchor_spl::token_2022::spl_token_2022::state::Mint as MintInner;
1111
use anchor_spl::token_interface::{
12-
self, CloseAccount, Mint, TokenAccount, TokenInterface, Transfer, TransferChecked,
12+
self, Burn, CloseAccount, Mint, MintTo, TokenAccount, TokenInterface, Transfer, TransferChecked,
1313
};
1414
use std::iter::Peekable;
1515
use std::slice::Iter;
@@ -25,7 +25,31 @@ pub fn send_from_program_vault<'info>(
2525
remaining_accounts: Option<&mut Peekable<Iter<'info, AccountInfo<'info>>>>,
2626
) -> Result<()> {
2727
let signature_seeds = get_signer_seeds(&nonce);
28-
let signers = &[&signature_seeds[..]];
28+
29+
send_from_program_vault_with_signature_seeds(
30+
token_program,
31+
from,
32+
to,
33+
authority,
34+
&signature_seeds,
35+
amount,
36+
mint,
37+
remaining_accounts,
38+
)
39+
}
40+
41+
#[inline]
42+
pub fn send_from_program_vault_with_signature_seeds<'info>(
43+
token_program: &Interface<'info, TokenInterface>,
44+
from: &InterfaceAccount<'info, TokenAccount>,
45+
to: &InterfaceAccount<'info, TokenAccount>,
46+
authority: &AccountInfo<'info>,
47+
signature_seeds: &[&[u8]],
48+
amount: u64,
49+
mint: &Option<InterfaceAccount<'info, Mint>>,
50+
remaining_accounts: Option<&mut Peekable<Iter<'info, AccountInfo<'info>>>>,
51+
) -> Result<()> {
52+
let signers = &[signature_seeds];
2953

3054
if let Some(mint) = mint {
3155
if let Some(remaining_accounts) = remaining_accounts {
@@ -137,6 +161,56 @@ pub fn close_vault<'info>(
137161
token_interface::close_account(cpi_context)
138162
}
139163

164+
pub fn mint_tokens<'info>(
165+
token_program: &Interface<'info, TokenInterface>,
166+
destination: &InterfaceAccount<'info, TokenAccount>,
167+
authority: &AccountInfo<'info>,
168+
signature_seeds: &[&[u8]],
169+
amount: u64,
170+
mint: &InterfaceAccount<'info, Mint>,
171+
) -> Result<()> {
172+
let signers = &[signature_seeds];
173+
174+
let mint_account_info = mint.to_account_info();
175+
176+
validate_mint_fee(&mint_account_info)?;
177+
178+
let cpi_accounts = MintTo {
179+
mint: mint_account_info,
180+
to: destination.to_account_info(),
181+
authority: authority.to_account_info(),
182+
};
183+
184+
let cpi_program = token_program.to_account_info();
185+
let cpi_context = CpiContext::new_with_signer(cpi_program, cpi_accounts, signers);
186+
token_interface::mint_to(cpi_context, amount)
187+
}
188+
189+
pub fn burn_tokens<'info>(
190+
token_program: &Interface<'info, TokenInterface>,
191+
destination: &InterfaceAccount<'info, TokenAccount>,
192+
authority: &AccountInfo<'info>,
193+
signature_seeds: &[&[u8]],
194+
amount: u64,
195+
mint: &InterfaceAccount<'info, Mint>,
196+
) -> Result<()> {
197+
let signers = &[signature_seeds];
198+
199+
let mint_account_info = mint.to_account_info();
200+
201+
validate_mint_fee(&mint_account_info)?;
202+
203+
let cpi_accounts = Burn {
204+
mint: mint_account_info,
205+
from: destination.to_account_info(),
206+
authority: authority.to_account_info(),
207+
};
208+
209+
let cpi_program = token_program.to_account_info();
210+
let cpi_context = CpiContext::new_with_signer(cpi_program, cpi_accounts, signers);
211+
token_interface::burn(cpi_context, amount)
212+
}
213+
140214
pub fn validate_mint_fee(account_info: &AccountInfo) -> Result<()> {
141215
let mint_data = account_info.try_borrow_data()?;
142216
let mint_with_extension = StateWithExtensions::<MintInner>::unpack(&mint_data)?;

programs/drift/src/error.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use anchor_lang::prelude::*;
2-
32
pub type DriftResult<T = ()> = std::result::Result<T, ErrorCode>;
43

54
#[error_code]
@@ -639,6 +638,48 @@ pub enum ErrorCode {
639638
InvalidIfRebalanceConfig,
640639
#[msg("Invalid If Rebalance Swap")]
641640
InvalidIfRebalanceSwap,
641+
#[msg("Invalid Constituent")]
642+
InvalidConstituent,
643+
#[msg("Invalid Amm Constituent Mapping argument")]
644+
InvalidAmmConstituentMappingArgument,
645+
#[msg("Invalid update constituent update target weights argument")]
646+
InvalidUpdateConstituentTargetBaseArgument,
647+
#[msg("Constituent not found")]
648+
ConstituentNotFound,
649+
#[msg("Constituent could not load")]
650+
ConstituentCouldNotLoad,
651+
#[msg("Constituent wrong mutability")]
652+
ConstituentWrongMutability,
653+
#[msg("Wrong number of constituents passed to instruction")]
654+
WrongNumberOfConstituents,
655+
#[msg("Oracle too stale for LP AUM update")]
656+
OracleTooStaleForLPAUMUpdate,
657+
#[msg("Insufficient constituent token balance")]
658+
InsufficientConstituentTokenBalance,
659+
#[msg("Amm Cache data too stale")]
660+
AMMCacheStale,
661+
#[msg("LP Pool AUM not updated recently")]
662+
LpPoolAumDelayed,
663+
#[msg("Constituent oracle is stale")]
664+
ConstituentOracleStale,
665+
#[msg("LP Invariant failed")]
666+
LpInvariantFailed,
667+
#[msg("Invalid constituent derivative weights")]
668+
InvalidConstituentDerivativeWeights,
669+
#[msg("Unauthorized dlp authority")]
670+
UnauthorizedDlpAuthority,
671+
#[msg("Max DLP AUM Breached")]
672+
MaxDlpAumBreached,
673+
#[msg("Settle Lp Pool Disabled")]
674+
SettleLpPoolDisabled,
675+
#[msg("Mint/Redeem Lp Pool Disabled")]
676+
MintRedeemLpPoolDisabled,
677+
#[msg("Settlement amount exceeded")]
678+
LpPoolSettleInvariantBreached,
679+
#[msg("Invalid constituent operation")]
680+
InvalidConstituentOperation,
681+
#[msg("Unauthorized for operation")]
682+
Unauthorized,
642683
}
643684

644685
#[macro_export]

programs/drift/src/ids.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use anchor_lang::prelude::Pubkey;
2+
use solana_program::pubkey;
3+
14
pub mod pyth_program {
25
use solana_program::declare_id;
36
#[cfg(feature = "mainnet-beta")]
@@ -107,3 +110,8 @@ pub mod amm_spread_adjust_wallet {
107110
#[cfg(feature = "anchor-test")]
108111
declare_id!("1ucYHAGrBbi1PaecC4Ptq5ocZLWGLBmbGWysoDGNB1N");
109112
}
113+
114+
pub mod lp_pool_swap_wallet {
115+
use solana_program::declare_id;
116+
declare_id!("1ucYHAGrBbi1PaecC4Ptq5ocZLWGLBmbGWysoDGNB1N");
117+
}

0 commit comments

Comments
 (0)