Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@drift-labs/sdk

drift-labs30.7kApache-2.02.125.0-beta.0TypeScript support: included

SDK for Drift Protocol

drift-labs, drift, perps

readme

Drift Protocol v2

SDK npm package Docs Discord Chat License

Installation

npm i @drift-labs/sdk

Getting Started

Start here if you're integrating with Drift!

  • Drift v2-teacher + API Docs
    • Docs and examples for using the SDK in Typescript and Python
    • Useful concepts and examples when integrating Drift
    • Docs for Drift's "Data API"
  • Typescript API docs
    • JSDoc automated documentation for the Drift v2 Typescript SDK
  • Drift docs
    • Comprehensive universal docs for Drift

The below is a light overview of using Solana and Drift's typescript sdk. If you want comprehensive docs with examples of how to integrate with Drift you should use the v2-teacher docs.

Setting up a wallet for your program

# Generate a keypair
solana-keygen new

# Get the pubkey for the new wallet (You will need to send USDC to this address to Deposit into Drift (only on mainnet - devnet has a faucet for USDC))
solana address

# Put the private key into your .env to be used by your bot
cd {projectLocation}
echo BOT_PRIVATE_KEY=`cat ~/.config/solana/id.json` >> .env

Concepts

BN / Precision

The Drift SDK uses BigNum (BN), using this package, to represent numerical values. This is because Solana tokens tend to use levels of precision which are too precise for standard Javascript floating point numbers to handle. All numbers in BN are represented as integers, and we will often denote the precision of the number so that it can be converted back down to a regular number.

Example:
a BigNum: 10,500,000, with precision 10^6, is equal to 10.5 because 10,500,000 / 10^6 = 10.5.

The Drift SDK uses some common precisions, which are available as constants to import from the SDK.

Precision Name Value
FUNDING_RATE_BUFFER 10^3
QUOTE_PRECISION 10^6
PEG_PRECISION 10^6
PRICE_PRECISION 10^6
AMM_RESERVE_PRECISION 10^9
BASE_PRECISION 10^9

Important Note for BigNum division

Because BN only supports integers, you need to be conscious of the numbers you are using when dividing. BN will return the floor when using the regular division function; if you want to get the exact division, you need to add the modulus of the two numbers as well. There is a helper function convertToNumber in the SDK which will do this for you.

import {convertToNumber} from @drift-labs/sdk

// Gets the floor value
new BN(10500).div(new BN(1000)).toNumber(); // = 10

// Gets the exact value
new BN(10500).div(new BN(1000)).toNumber() + BN(10500).mod(new BN(1000)).toNumber(); // = 10.5

// Also gets the exact value
convertToNumber(new BN(10500), new BN(1000)); // = 10.5

Examples

Setting up an account and making a trade

import * as anchor from '@coral-xyz/anchor';
import { AnchorProvider } from '@coral-xyz/anchor';
import { getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from '@solana/spl-token';

import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import {
    calculateReservePrice,
    DriftClient,
    User,
    initialize,
    PositionDirection,
    convertToNumber,
    calculateTradeSlippage,
    PRICE_PRECISION,
    QUOTE_PRECISION,
    Wallet,
    PerpMarkets,
    BASE_PRECISION,
    getMarketOrderParams,
    BulkAccountLoader,
    BN,
    calculateBidAskPrice,
    getMarketsAndOraclesForSubscription,
    calculateEstimatedPerpEntryPrice,
} from '../sdk';

export const getTokenAddress = (
    mintAddress: string,
    userPubKey: string
): Promise<PublicKey> => {
    return getAssociatedTokenAddress(
        new PublicKey(mintAddress),
        new PublicKey(userPubKey)
    );
};

const main = async () => {
    const env = 'devnet';
    // const env = 'mainnet-beta';

    // Initialize Drift SDK
    const sdkConfig = initialize({ env });

    // Set up the Wallet and Provider
    if (!process.env.ANCHOR_WALLET) {
        throw new Error('ANCHOR_WALLET env var must be set.');
    }

    if (!process.env.ANCHOR_PROVIDER_URL) {
        throw new Error('ANCHOR_PROVIDER_URL env var must be set.');
    }

    const provider = anchor.AnchorProvider.local(
        process.env.ANCHOR_PROVIDER_URL,
        {
            preflightCommitment: 'confirmed',
            skipPreflight: false,
            commitment: 'confirmed',
        }
    );
    // Check SOL Balance
    const lamportsBalance = await provider.connection.getBalance(
        provider.wallet.publicKey
    );
    console.log(
        provider.wallet.publicKey.toString(),
        env,
        'SOL balance:',
        lamportsBalance / 10 ** 9
    );

    // Misc. other things to set up
    const usdcTokenAddress = await getTokenAddress(
        sdkConfig.USDC_MINT_ADDRESS,
        provider.wallet.publicKey.toString()
    );

    // Set up the Drift Client
    const driftPublicKey = new PublicKey(sdkConfig.DRIFT_PROGRAM_ID);
    const bulkAccountLoader = new BulkAccountLoader(
        provider.connection,
        'confirmed',
        1000
    );
    const driftClient = new DriftClient({
        connection: provider.connection,
        wallet: provider.wallet,
        programID: driftPublicKey,
        accountSubscription: {
            type: 'polling',
            accountLoader: bulkAccountLoader,
        },
    });
    await driftClient.subscribe();

    console.log('subscribed to driftClient');

    // Set up user client
    const user = new User({
        driftClient: driftClient,
        userAccountPublicKey: await driftClient.getUserAccountPublicKey(),
        accountSubscription: {
            type: 'polling',
            accountLoader: bulkAccountLoader,
        },
    });

    //// Check if user account exists for the current wallet
    const userAccountExists = await user.exists();

    if (!userAccountExists) {
        console.log(
            'initializing to',
            env,
            ' drift account for',
            provider.wallet.publicKey.toString()
        );

        //// Create a Drift V2 account by Depositing some USDC ($10,000 in this case)
        const depositAmount = new BN(10000).mul(QUOTE_PRECISION);
        await driftClient.initializeUserAccountAndDepositCollateral(
            depositAmount,
            await getTokenAddress(
                usdcTokenAddress.toString(),
                provider.wallet.publicKey.toString()
            )
        );
    }

    await user.subscribe();

    // Get current price
    const solMarketInfo = PerpMarkets[env].find(
        (market) => market.baseAssetSymbol === 'SOL'
    );

    const marketIndex = solMarketInfo.marketIndex;

    // Get vAMM bid and ask price
    const [bid, ask] = calculateBidAskPrice(
        driftClient.getPerpMarketAccount(marketIndex).amm,
        driftClient.getOracleDataForPerpMarket(marketIndex)
    );

    const formattedBidPrice = convertToNumber(bid, PRICE_PRECISION);
    const formattedAskPrice = convertToNumber(ask, PRICE_PRECISION);

    console.log(
        env,
        `vAMM bid: $${formattedBidPrice} and ask: $${formattedAskPrice}`
    );

    const solMarketAccount = driftClient.getPerpMarketAccount(
        solMarketInfo.marketIndex
    );
    console.log(env, `Placing a 1 SOL-PERP LONG order`);

    const txSig = await driftClient.placePerpOrder(
        getMarketOrderParams({
            baseAssetAmount: new BN(1).mul(BASE_PRECISION),
            direction: PositionDirection.LONG,
            marketIndex: solMarketAccount.marketIndex,
        })
    );
    console.log(
        env,
        `Placed a 1 SOL-PERP LONG order. Tranaction signature: ${txSig}`
    );
};

main();

License

Drift Protocol v2 is licensed under Apache 2.0.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Drift SDK by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

Features

Fixes

Breaking

[2.124.0] - 2025-06-18

Features

  • program: perp market amm oracle delay override (#1679)
  • program: sanitize long tail perp market orders less frequently (#1641)
  • program: programmatic rebalance between protocol owned if holdings (#1653)

Fixes

Breaking

[2.123.0] - 2025-06-13

Features

  • program: simplify user can skip duration (#1668)
  • program: allow limit orders without auctions in swift (#1661)
  • program: add taker_speed_bump_override and amm_spread_adjustment (#1665)

Fixes

Breaking

[2.122.0] - 2025-06-05

Features

  • program: add existing position fields to order records (#1614)

Fixes

  • sdk: fix to getMaxTradeSizeUSDCForPerp which was previously overshooting max allowed size due to IMF factor
  • program: check limit price after applying buffer in trigger limit order (#1648)
  • program: check limit price when setting auction for limit order (#1650)

Breaking

[2.121.0] - 2025-05-29

Features

  • program: multi piecewise interest rate curve (#1560)
  • sdk: fees and max perp trade size calculation functions allow an optional parameter for a user using bitFlags to enter high leverage mode

Fixes

  • program: safely use saturating sub number_of_users fields per market (#1616)

Breaking

[2.120.0] - 2025-04-29

Features

  • program: add admin_deposit (#1591)

Fixes

Breaking

[2.119.0] - 2025-04-21

Features

  • program: place perp order can update high leverage mode (#1573)
  • sdk: generalized getSpotAssetValue and getSpotLiabilityValue to be able to be called without a user account (#1577)

Fixes

Breaking

[2.118.0] - 2025-04-10

Features

  • program: make Pyra accounts exempt from force_delete_user (#1569)
  • sdk: deprecate getPostSwitchboardOnDemandUpdateAtomicIx (#1567)
  • program: maker trigger market oracle offset and fill with amm faster (#1564)
  • program: sanitize signed msg orders with wider thresholds (#1554)

Fixes

  • program: add crossing start buffer auction to end price (#1568)

Breaking

[2.117.0] - 2025-03-31

Features

  • program: more lenient pool id check to allow users with referrer rewards to withdraw (#1553)
  • program: add bitflags to order aciton records (#1550)

Fixes

  • program: fix user stats check for transfer_perp_position (#1557)

Breaking

[2.116.0] - 2025-03-21

Features

Fixes

  • program: program: fix order status checks (#1549)

Breaking

[2.115.0] - 2025-03-20

Features

  • program: force lst pool oracle updates into same slot for liquidations (#1537)
  • program: init dynamic offset for pmm (#1524)
  • program: new order status logic to make tracking fills easier (#1512)
  • program: make initting signedmsguserorder accounts permissionless (#1533)
  • program: allow transfer perp position between two delegates (#1538)
  • program: relax user-skip-auction-duration (#1545)

Fixes

  • program: fix reference price offset reserves (#1516)
  • sdk: account for authority when useMarketLastSlotCache (#1541)
  • program: delegate wallets sign taker pubkey into message (#1546)

Breaking

[2.114.0] - 2025-03-13

Features

Fixes

  • program: add liq fees to calculate_perp_market_amm_summary_stats (#1531)

Breaking

[2.113.0] - 2025-03-06

Features

  • program: add transfer_perp_position ix (#1514)
  • program: add signed_msg ws delegate account (#1515)

Fixes

Breaking

[2.112.0] - 2025-03-03

Features

  • program: use custom margin ratio if oracle too stale for margin (#1505)
  • program: enable limit orders with auctions in fastlane (#1502)
  • program: set is_signed_msg bitflag on orders (#1504)

Fixes

Breaking

[2.111.0] - 2025-02-25

Features

Fixes

  • program: place signed order after tp/sl (#1496)
  • program: rm oracle conf max 1 in validity checker (#1497)

Breaking

[2.110.0] - 2025-02-19

Features

  • program: add update oracle source invariant checks and logs (#1480)
  • program: add transfer_pools ix (#1472)
  • program: updated borrow thresholds for (#1483)

Fixes

  • program: change ordering of SL/TP order placement within signed msg orders (#1495)

Breaking

[2.109.0] - 2025-02-06

Features

  • program: add posted slot tail to order struct, use it to determine vamm availability for high volume users (#1459)
  • program: add pyth lazer stable coin oracle type (#1463)
  • program: removes devnet panics for swift and slightly changes sig verification (#1464)
  • program: allow hot wallet admin to init market if not active (#1454)
  • program: round down 1 for calculate_max_withdrawable (#1461)
  • program: add fuel overflow account (#1449)
  • program: add delegates to swift (#1474)

Fixes

  • program: fix hlm liq fee (#1465)

Breaking

[2.108.0] - 2025-01-30

Features

  • program: add separate liquidator fee for high leverage mode (#1451)
  • program: update pyth lazer verification (#1441)

Fixes

  • program: apply liq buffer to negative pnl (#1445)
  • program: update get fuel bonus numerator ts (#1446)

Breaking

[2.107.0] - 2025-01-20

Features

  • program: apply 10bps to protected market maker limit orders (#1417)
  • program: allow lighthouse at end of swap (#1429)

Fixes

Breaking

[2.106.0] - 2025-01-08

Features

  • program: liquidate spot with swap (#1402)

Fixes

  • program: account for fuel in swaps (#1411)
  • program: account for fuel when there is full withdraw (#1413)

Breaking

[2.105.0] - 2025-01-02

Features

  • program: add ix to pause deposits/withdraws if vault invariant broken (#1387)

Fixes

  • program: fix spot swap fuel bonus (#1411)
  • program: skip liq perp oracle twap check if market is in settlement (#1406)

Breaking

[2.104.0] - 2024-12-23

Features

  • program: pyth lazer integration (#1361)
  • program: add ix to log user balances (#1366)

Fixes

  • program: fix force delete user for token 2022 (#1358)
  • program: fix liquidating dust prediction mkt position (#1397)
  • program: spot market decimals under 6 precision fixes (#1399)

Breaking

[2.103.0] - 2024-12-04

Features

  • program: add spot market pool ids (#1250)
  • program: make oracle map work with different sources (#1346)
  • program: allow read only ix after swap (#1356)

Fixes

  • program: fix force delete user for token 2022 (#1358)

Breaking

  • program: make ModifyOrderParams a bit flag and add ExcludePreviousFill (#1357)

[2.102.0] - 2024-11-21

Features

  • program: force delete user init (#1341)
  • program: rm withdraw fee (#1334)

Fixes

  • program: can update k looks at min order size (#1338)
  • program: skip validate_post_only_order if amm paused (#1202)

Breaking

[2.101.0] - 2024-11-15

Features

  • program: upgrade switchboard on demand oracles (#1329)

Fixes

Breaking

[2.100.0] - 2024-11-14

Features

  • program: add auction_duration_percentage to place and take (#1320)
  • program: more lenient w invalid deposit oracles (#1324)
  • program: rm usdc staking fee discount (#1316)
  • program: allow hot admin wallet to init pyth oracle (#1327)
  • program: update hlm fees (#1317)
  • program: update hlm disable (#1318)

Fixes

  • sdk: getBestBids/Asks only considers price/time priority (#1322)

Breaking

[2.99.0] - 2024-11-04

Features

Fixes

  • program: add update_user_stats_referrer_status to lib

Breaking

[2.98.0] - 2024-11-04

Features

  • sdk: init referrerMap (#1295)
  • program: allow disable high leverage mode after 1 hour (#1289)
  • sdk: driftClient unsub from delisted markets by default (#1298)
  • program: allow amm to fill immediately (#1258)
  • program: high leverage users pay higher fee (#1287)

Fixes

  • program: admin can sign everywhere hot wallet can (#1290)

Breaking

[2.97.0] - 2024-10-23

Features

  • program: high leverage mode (#1240)
  • program: add flag for is_referred and is_referrer (#1256 )
  • program/sdk: rfq for devnet (#1254)
  • program: let oracle offset orders have auctions (#1273)

Fixes

Breaking

[2.96.0] - 2024-10-10

Features

  • program: reusue unused maker order id as success condition for place and take perp order (#1218)
  • program/sdk: swift for devnet (#1195)
  • sdk: EventSubscriber: support events server (#1222)
  • sdk: add new DelistMarketSetting to handle delisted markets (#1229)
  • program: add update-user-fuel-bonus ix (#1247)

Fixes

  • program: remove trigger limit resting limit order hook (#1233)
  • program: fix max liquidation fee overflow (#1232)

Breaking

[2.95.0] - 2024-09-16

Features

  • program: update settle market guards (#1216)
  • sdk:: cache toStringing oracle for drift client account subscribers (#1220)

Fixes

  • program: return early in update_perp_bid_ask_twap for prediction market with no bid/asks (#1223)
  • sdk: avoid spamming getAccountInfo in drift client ws sub (#1219)

Breaking

[2.93.0] - 2024-08-29

Features

Fixes

  • program: remove redundant clones (#1199)
  • program: fix spot market map in force_cancel_orders (#1209)

Breaking

[2.93.0] - 2024-08-22

Features

  • program: dynamic liquidation fee for liq_perp_with_fill (#1185)
  • program: calculate_accumulated_interest return early based on ts (#1192)
  • program: add logging to pyth pull updates (#1189)

Fixes

Breaking

[2.92.0] - 2024-08-12

Features

  • program: init prediction markets (#1152)

Fixes

  • program: make updateUserQuoteAssetInsuranceStake permissionless (#1187)
  • program: fix openbook v2 oom issue (#1186)

Breaking

[2.91.0] - 2024-08-07

Features

Fixes

  • program: look at drift stake to determine fee tier (#1172)

Breaking

[2.90.0] - 2024-08-03

Features

Fixes

  • program: account for direction when looking at max borrow cap (#1169)

Breaking

[2.89.0] - 2024-08-02

Features

Fixes

  • program: call get_token_interface in begin_swap

Breaking

[2.88.0] - 2024-08-01

Features

Fixes

  • program: advance iter in get_token_interface and get_token_mint

Breaking

[2.87.0] - 2024-07-30

Features

  • program: add deposit into spot market vault (#1159)
  • program: add liquidation via fill (#1106)
  • program: add switchboard on demand integration (#1154)
  • program: add support for token 2022 (#1125)

Fixes

Breaking

[2.86.0] - 2024-07-22

Features

  • program: track fuel (#1048)
  • program: add post multi pyth oracle updates atomic (#1133)
  • program: track fuel for if staking (#1127)
  • program: validate fee structure (#1075)
  • program: check 5 min oracle twap divergence in trigger order (#1116)
  • program: openbook v2 integration (#1112)
  • program: spot fill checks if withdraws are paused (#881)

Fixes

  • program: more oracle validation in admin fn (#1082)
  • program: account for serum already having open order account (#1077)
  • program: avoid truncated cast (#1078)
  • program: check whitelist token amount (#1076)
  • program: program: only let referrer set if number_of_sub_accounts_created is 0 (#1083)
  • program: update increment_total_referrer_reward corner-case logic (#1156)

Breaking

[2.85.0] - 2024-07-02

Features

  • program: add tx optimized pyth pull (#1111)
  • program: migrate all integration tests to bankrun (#1090)

Fixes

Breaking

[2.84.0] - 2024-06-23

Features

  • program: check FillOrderAmm for amm is available (#1107)
  • program: add spot borrow insurance limits (#1080)
  • program: maker can be rewarded filler returns when amm gets fill (#1093)
  • program: avoid overwriting 0 duration auction (#1097)
  • program: add pyth pull oracles (#1067)

Fixes

Breaking

  • program: upgrade to anchor 0.29.0 and solana 1.16

[2.83.0] - 2024-06-06

Features

  • program: settle pnl block looks at oracle vs oracle 5min twap (#1072)
  • program: add settle pnl mode (#1030)
  • program: use strict price for maintenance margin check in settle pnl (#1045)
  • program: order w ioc can still get auction (#1074)

Fixes

  • program: update_perp_auction_params_limit_orders unwraps oracle_price_offset
  • ts-sdk: add market index to logging settle pnl error (#1068)
  • program: enforce min price for oracle offsets (#874)

Breaking

[2.82.0] - 2024-05-23

Features

  • program: TransferProtocolIfShares constraint (#1055)
  • program: sanitize extreme auction end prices (#1031)
  • program: add comprehensive admin function logging (#1038)

Fixes

Breaking

  • ts-sdk: upgrade to node 18 and solana version 1.91.7 (#1036)

[2.81.0] - 2024-04-22

Features

Fixes

  • program: fix tracking unsettled quote for lp (#1026)

Breaking

[2.80.0] - 2024-04-20

Features

  • program: add ability to pause if operations (#989)
  • program: update auction end price in derive_market_order_auction_params (#1022)
  • program: admin amm summary stats update and/or reset (#912)

Fixes

Breaking

[2.79.0] - 2024-04-18

Features

Fixes

  • program: program: let user with positive pnl be settled if being liquidated (#1020)
  • program: fix should_expire_order_before_fill (#1021)

Breaking

[2.78.0] - 2024-04-15

Features

Fixes

  • program: set default ContractTier to HighlySpeculative (#1013)
  • program: avoid dust borrows not being transferred

Breaking

[2.77.0] - 2024-04-13

Features

  • program: lax funding rate update oracle validity criteria (#1009)

Fixes

  • program: fix div by 0 in calculate_liability_transfer_to_cover_margin_shortage

Breaking

[2.76.0] - 2024-04-09

Features

  • program: rm admins ability to withdraw from if (#990)
  • program: add add ability to delete initialized spot market (#998)
  • program: more reliable oracle updates (#1000)

Fixes

  • program: avoid underflow in update pnl (#1002)

Breaking

[2.75.0] - 2024-04-01

Features

  • program: add fee adjustment to spot market (#987)
  • program: allow multiple makers to be passed into for spot fills (#946)
  • ts-sdk: add fn to get admin ix (#980)
  • program: add invariant check boolean for attempt settle revenue to insurance (#937)
  • program: improve best bid/ask estimate in mark twap update (#975)
  • program: add optional margin calculations for drift-rs (#978)

Fixes

Breaking

[2.74.0] - 2024-03-25

Features

  • program: add 'highly speculative' contract tier enum 4 (#968)
  • program: expand initialize market parameters (#969)

Fixes

  • program: fix checking isolated tier in add_perp_lp_shares (#965)

Breaking

[2.73.0] - 2024-03-15

Features

Fixes

  • program: fix checking isolated tier in validate spot margin trading

Breaking

[2.72.0] - 2024-03-14

Features

  • program: skip isolated tier for auction start/end sanitize (#958)

  • program: check isolated perp market in validate spot margin trading (#957)

  • program: improve update prelaunch oracles and add ability to delete (#956)
  • program: allow user to settle realized pnl in reduce only market status (#954)
  • sdk: add function for toggling user account to reduceOnly (#966)

Fixes

  • program: update spot index twap ts (#948)

Breaking

[2.71.0] - 2024-03-11

Features

  • program: add back switchboard without cargo dependency (#943)
  • program: add admin fn to update funding period
  • program: add prelaunch oracles (#910)
  • program: make isolated perp contract tier more ergonomic (#913)
  • program: add per market tier confidence interval guard (#945)

Fixes

Breaking

  • sdk: account for max confidence in isOracleValid (#949)

[2.70.0] - 2024-03-07

Features

Fixes

  • program: fix allowing settle pnl on oracle delays when price is stable (#940)

Breaking

[2.69.0] - 2024-03-06

Features

  • program: allow settle pnl on oracle delays when price is stable (#929)
  • program: cache validity in oracle map

Fixes

Breaking

  • program: revert switchboard (#935)

[2.68.0] - 2024-03-05

Features

  • program: apply auction sanitizer to all contract tiers (#932)

Fixes

  • program: fix flipping funding rates (#931)

Breaking

[2.67.0] - 2024-03-05

Features

Fixes

  • program: add switchboard (#878)
  • sdk: handle oracle failover when oracle is changed (#875)

Breaking

[2.66.0] - 2024-02-28

Features

Fixes

  • program: don't block oracle order prices when theres solely InsufficientDataPoints (#919)

Breaking

[2.65.0] - 2024-02-26

Features

  • program: add pause operation for liquidation (#880)

Fixes

  • program: fix entry/breakeven price calculations for lp remainders (#864)
  • program: handle derisk lp when orders array full (#899)
  • program: invalid borrow in get_referrer_info when maker is refferer (#900)

Breaking

[2.64.0] - 2024-02-20

Features

  • program: make derived auction start more passive (#890)

Fixes

Breaking

[2.63.0] - 2024-02-16

Features

  • program: longer derived auction durations for contract tier B and safer (#889)
  • program: always try update market order auction durations (#882)
  • program: amm drawdown check (#865)
  • program: relax oracle guardrail validity check for init margin calc for positive pnl (#876)
  • program: add more max spread baselines (#858)

Fixes

  • sdk: fix bug in changeWallet that doesn't reset the user stats account if switching from a wallet with drift account to one without

Breaking

[2.62.0] - 2024-02-14

Features

  • program: more continuous calculation for calculate_jit_amount (#882)

Fixes

Breaking

[2.61.0] - 2024-02-09

Features

  • program: better derivation of perp auction params when missing and for triggers (#869)
  • program: calculate whether oracle's num quoters sufficient (#860)

Fixes

  • program: include derisk lp order action explanation

Breaking

[2.60.0] - 2024-02-07

Features

  • program: sanitize perp auction params (#859)
  • program: add repay borrow explanation (#862)
  • program: derisk lp more granularly (#849)

Fixes

Breaking

[2.59.0] - 2024-01-30

Features

  • program: separate out paused operations from market status (#839)
  • program: use decayed last_oracle_conf_pct as lower bound for update (#840)

Fixes

Breaking

[2.58.0] - 2024-01-27

Features

Fixes

  • program: AmmPaused doesnt block all fills

Breaking

[2.57.0] - 2024-01-25

Features

  • program: add recenter amm ix (#836)

Fixes

Breaking

[2.56.0] - 2024-01-24

Features

Fixes

  • program: enable jit maker to fill same slot as taker placed (#835)

Breaking

[2.55.0] - 2024-01-18

Features

Fixes

  • program: standardize lp shares in attempt_burn_user_lp_shares_for_risk_reduction (#826)

Breaking

[2.54.0] - 2024-01-15

Features

  • sdk: move bracket orders into single instruction
  • sdk: add ability to do placeAndTake order with bracket orders attached
  • sdk: add option to cancel existing orders in market for place and take order
  • sdk: add option to get signed settlePnl tx back from a market order
  • program: auto derisk lp positions in settle pnl (#766)
  • program: increase full perp liquidation threshold (#807)
  • program: remove spot fee pool transfer (#800)
  • program: increase insurance tier max (#784)
  • sdk: can specify max custom margin ratio to initialize a new account with

Fixes

  • ts-sdk: contract tier funding rate clamp (#785)
  • ts-sdk: fix oracle is valid (#806)

Breaking

[2.53.0] - 2023-12-31

Features

Fixes

  • program: standardize limit auction prices (#790)
  • program: improve get_fallback_price(#797)
  • program: derive auction for crossing limit with no duration (#802)
  • sdk: use tx params passed into deposit and withdraw functions

Breaking

[2.52.0] - 2023-12-22

Features

  • program: add ability to reclaim rent without deleting account (#763)
  • program: add borrow explanation to DepositRecords (#772)
  • sdk: OrderSubscriber has resync option (#780)
  • program: only consider recent last_active_slot in qualifies_for_withdraw_feen (#756)
  • program: amm can use reference price offset from oracle price based on clamped inventory and persist market premiums (#681)

Fixes

  • program: handle underflow in calculate_liability_transfer_to_cover_margin_shortage (#774)
  • program: flip auction flag when trigger order adds auction (#775)
  • program: don't perform funding rate updates when slots_since_amm_update is stale (#757)
  • program: add update last slot for filler in pay_keeper_flat_reward_for_spot

Breaking

[2.51.0] - 2023-12-09

Features

Fixes

  • program: consistent user of fee budget in calculate_optimal_peg_and_budget (#754)

Breaking

[2.50.0] - 2023-12-09

Features

Fixes

  • program: better account for liquidation fees in calculate_optimal_peg_and_budget (#754)

Breaking

[2.49.0] - 2023-12-08

[Unreleased]

Features

  • program: add init user fee (#752)
  • program: vamm gives maker rebate (#653)

Fixes

Breaking

[2.48.0] - 2023-12-01

Features

Fixes

  • program: account for step size when canceling reduce only orders

Breaking

  • sdk: UserStatsMap use bulkAccountLoader (UserStatsMap.subscribe and UserStatsMap.sync now requires list of authorities) (#716)

[2.47.0] - 2023-11-26

Features

  • program: accelerated idle update for users with <$1000 equity

Fixes

  • ts-sdk: fix to modify order booleans

Breaking

[2.46.0] - 2023-11-24

Features

  • program: fill asset weight between init and maintenance (#713)
  • program: if order reduces maker position, check maintenance margin requirement (#714)

Fixes

Breaking

[2.45.0] - 2023-11-22

Features

  • program: trigger limits cant make if limit crosses trigger (#707)

Fixes

  • sdk: fix vamm L2asks by using askAmm (#708)
  • program: add max_number_of_sub_accounts onto state account (#710)

Breaking

[2.44.0] - 2023-11-17

Features

Fixes

  • program: exhaustively search for referrer account on fill (#702)

[2.43.0] - 2023-11-16

Features

  • program: accelerate liquidations for tiny accounts (#698)
  • program: boost max sub accounts to 20k

Fixes

  • program: allow amm to fill step size (#672)
  • program: add add update_liquidation_margin_buffer_ratio (#695)
  • program: account for fee pool when settling positive pnl (#687)
  • sdk: fix bug which incorrectly calculated leverage after trade for a market with no position but short orders open
  • sdk: fix bug in modifying an order that previously had auction params to a non-auction order
  • sdk: add delta to calculateDepositRate function

Breaking

[2.42.0] - 2023-10-26

Features

  • program: add accelerated user update idle (#669)
  • program: make user status a bit flag (#619)
  • program: place and take uses auction end price for market orders (#650)
  • program: reduce cus for place_spot_order (#662)
  • program: bump max sub accounts to 15k
  • program: user custom margin ratio works with spot (#633)
  • program: add swap price bands (#611)
  • program: add 5min twap price bands to liquidate_perp and liquidate_spot (#570)
  • program: add positive perp funding rate offset (#576)

Fixes

  • program: add validation check in update max imbalances (#667)

Breaking

  • sdk: remove getMakerLimitBids/Asks from DLOB
  • sdk: updateUserMarginEnabled and updateUserCustomMarginRatio now take in an array of params to allow multiple subaccounts to be update in a single tx

[2.41.0] - 2023-10-05

Features

  • program: order_breaches_maker_oracle_price_bands only uses init margin ratio (#636)
  • program: add fee_adjustment to perp market (#629)
  • program: add buffer to calculating max perp if fee (#635)
  • sdk: remove getMakerLimitBids/Asks (#632)
  • program: add ix to transfer protocol if shares (#612)

Fixes

  • program: fix if staking rounding for fee tier selection (#643)

Breaking

[2.40.0] - 2023-09-28

Features

  • program: add dynamic liquidation fee (#601)
  • sdk: add deriveOracleAuctionParams
  • program: update to anchor 0.27.0 (#617)

Fixes

Breaking

[2.39.0] - 2023-09-07

Features

  • sdk: updated anchor to 0.28.1-beta.2
  • sdk: add priorityFeeSubscriber
  • program: allow up to 12500 users
  • program: scale initial asset weight for spot markets based on total deposits (#575)

Fixes

  • program: let auction start/end be the same (#597)
  • program: account for reduce only when checking margin in trigger order (#583)
  • program: use per_lp_base_unit for calculating base imbalance for lp jit (#604)

Breaking

[2.38.0] - 2023-08-25

Features

  • program: add reduce only user status (#560)
  • program: add conditionally smaller conf_component logic for amm spread (#577)
  • program: add per_lp_base on market/position (#568)

Fixes

  • program: add update_lp_market_position test for big k (#565)
  • sdk: fixed divide by 0 bug in withdraw amount when asset weight is 0 (#572)

Breaking

[2.37.0] - 2023-08-02

Features

  • program: add deposit_into_spot_market_revenue_pool (#520)
  • program: make users w excessive withdraws pay fees (#547)
  • program: allow settle pnl and spot fills via match when utilization is 100% (#525)
  • program: new update_perp_bid_ask_twap ix (#548)
  • program: dont check price bands for place order (#556)

Fixes

Breaking

[2.36.0] - 2023-07-26

Features

  • program: usdt oracle uses pyth stablecoin oracle source

Fixes

  • program: add buffer before limit tif can be expired (#551)
  • ts-sdk: fix abs for dustBaseAssetValue in getPerpPositionWithLPSettle (#543)
  • program: add a fixed buffer margin requirement for lp_shares (#546)
  • program: use fill margin type in fulfill_spot_order
  • ts-sdk: add buffer to max leverage for LP contributions

Breaking

  • ts-sdk: account for lp shares in liq price (#522)
  • ts-sdk: getPerpPositionWithLPSettle has flag to account for burn lp share (#522)

[2.35.0] - 2023-07-18

Features

  • program: add cancel orders by ids (#540)
  • program: add post only slide for perps (#541)
  • program: allow up to 10000 users

Fixes

  • program: if taker increases free colalteral, check maintenance health (#538)
  • program: improve bid/ask twap update for infrequent trading (#529)
  • sdk: simplify, mirror contract, and write tests for predicting funding rate function (#529)

Breaking

[2.34.0] - 2023-07-11

Features

Fixes

  • program: include amm jit in base used to calculate price band ((#536))

Breaking

[2.34.0] - 2023-07-11

Features

  • program: safety improvements for swaps ((#528))
  • program: track total_fee_earned_per_lp on amm ((#526))
  • program: add additional withdraw/borrow guards around fast utilization changes ((#517))
  • program: new margin type for when orders are being filled ((#518))
  • program: new fill price bands ((#516))

Fixes

  • program: use emit_stack for place orders ((#533))
  • program: tweaks for setting init asset weight to 0 ((#523))
  • program: add vault invariant to update_spot_market_cumulative_interest ix ((#524))
  • program: check oracles valid in meets_withdraw_margin_requirement if number_of_liabilities > 0
  • program: only get quote spot market if user has quote position in validate_spot_margin_trading
  • program: fix decrement_open_orders for makers

Breaking

[2.33.0] - 2023-06-30

Features

Fixes

  • program: fix margin calculation of unrealized funding pnl for lps ((#513))

Breaking

[2.32.0] - 2023-06-23

Features

  • ts-sdk: add getMaxSwapAmount ((#488))
  • program: add bulk place orders ix ((#499))
  • ts-sdk: add stakeForMSOL to driftClient ((#500))
  • ts-sdk: driftClient accepts default txParams ((#496))
  • ts-sdk: add method to force inclusion of markets in ix remaining accounts ((#503))

Fixes

  • program: emit lp records in liquidate_perp ((#498))
  • program: check margin enabled in swaps ((#501))

Breaking

  • ts-sdk: remove user.getSpotTokenAmount as its a duplicate
  • ts-sdk: remove RetrySender dependency on Provider ((#497))

[2.31.0] - 2023-06-06

Features

  • program: store if use has open orders/auctions on user account ((#480))
  • program: add user perp lp jit liquidity toward a target base ((#448))
  • ts-sdk: drift client will query rpc to find all markets/oracles if they're not explicitly specified ((#469))
  • ts-sdk: fix client borrow interest rate calculation ((#479))

Fixes

  • program: fix settle lp position math error for large step sizes ((#473))

Breaking

  • ts-sdk: user map default excludes idle users ((#471))

[2.30.0] - 2023-05-18

Features

  • program: allow up to 7500 subaccounts
  • program: allow users to swap on jupiter inside of drift account (#462)
  • ts-sdk: add mSOL spot market (#467)

Fixes

Breaking

[2.29.0] - 2023-05-12

Features

  • sdk: expose method in account subscriber to change polling frequency

Fixes

Breaking

  • program: modify_order and modify_order_by_id now expect a ModifyOrderPolicy (#461)
  • program: cancel_order does not fail if order does not exist (#461)

[2.28.0] - 2023-05-11

Features

  • program: add precision docs to the state accounts (#452)

Fixes

Breaking

  • ts-sdk: driftClient.getTokenAmount now returns negative for borrows (#452)
  • ts-sdk: txSender.sendVersionedTransaction now expects VersionedTransaction (#452)

[2.27.0] - 2023-05-02

Features

  • ts-sdk: add SUI perp market (#453)

Fixes

Breaking

[2.26.0] - 2023-05-02

Features

  • program: use forked version of anchor 0.26.0 that supports large idls (#451)
  • program: add security.txt (#450)
  • program: add L2 and L3 view of DLOB (#445)
  • ts-sdk: new DLOBSubscriber class to keep updated DLOB (#439)
  • program: add support for phoenix spot markets (#437)
  • sdk: ability to add stake from subaccount
  • ts-sdk: Add phoenix subscriber (#444)
  • sdk: driftClient allows subscription to delegate accounts; pass includeDelegates or authoritySubaccountMap to constructor/updateWallet (#432)

Fixes

  • program: check max_token_deposits at the end of fill_spot_order (#441)
  • program: force_cancel_orders only skips position reducing orders
  • program: allow amm to pull up to FEE_POOL_TO_REVENUE_POOL_THRESHOLD into fee pool (#436)
  • program: fix modify order trigger condition
  • sdk: fix removing unstaked sol
  • program: fix math error in settle_revenue_to_insurance_fund for large sizes (#443)
  • program: fix revenue pool corner case for updating last_revenue_withdraw_ts (#447)

Breaking

[2.25.0] - 2023-04-13

Features

  • sdk: add BNB perp market
  • program: update to anchor 0.26.0 (#428)
  • program: add modify_order ix (#422)
  • sdk: more accurate calculation of insurance stake value during unstake request (#426)

Fixes

  • sdk: fix isOracleValid confidenceTooLarge calc (#425)

  • sdk: Remove redundant fetchAccounts in userMap.ts

Breaking

[2.24.0] - 2023-04-03

Features

  • program: ability to delete a market that was just initialized (#413)
  • program: revenue pool wont settle to IF if utilization unhealthy (#402)

Fixes

  • program: add ctx.accounts.insurance_fund_vault.reload()? after vault updates (#402)

Breaking

[2.23.0] - 2023-04-03

Features

  • program: include usdc oracle (#397)
  • ts-sdk: add addAllUsers to DriftClient
  • program: program: when checking if user is idle, let balanceType be borrow if scaled balance is 0 (#397)

Fixes

Breaking

[2.22.0] - 2023-03-23

Features

  • sdk: add isUserBankrupt (#399)
  • program: update revenue pool fund settlement logic (#398)

Fixes

  • sdk: fix claimable pnl (#384)
  • program: borrow liquidity check accounts for if user has borrow or deposit (#400)
  • program: slightly relax withdraw limits (#400)
  • sdk: filter undefined accounts (#406)

Breaking

[2.21.0] - 2023-03-19

Features

  • program: account for openbook referrer rebate being greater than quote sold (#394)
  • sdk: add sync to UserMap and UserStatsMap (#395)
  • program: revert fill ix (#391)
  • program: flag users as idle on-chain (#386)

Fixes

Breaking

[2.20.0] - 2023-03-10

Features

  • program: add referrer name account to enforce unique referrer names (#357)
  • program: only let amm fill up to tick above/below user limit price (#381)
  • program: allow multiple makers in fill_perp_order (#341)
  • sdk: add getPerpMarketExtendedInfo to drift client

Fixes

Breaking

[2.19.0] - 2023-03-01

Features

  • program: allow post only to match older taker limit orders (#378)
  • ts-sdk: serum subscriber supports websockets (#365)
  • program: max number of subaccounts to 3000
  • program: amm spread logic more consistent across market by using liquidity ratio rather than base asset amount for inventory spread scaling(#374)
  • program: add pyth1M/pyth1K as OracleSource (#375)

Fixes

Breaking

[2.18.0] - 2023-02-24

Features

  • program: account for contract tier in liquidate_perp_pnl_for_deposit (#368)
  • program: simplifications for order fills (#370)
  • program: block atomic fills (#369)
  • program: allow limit orders to go through auction (#355)
  • program: improve conditions for withdraw/borrow guard (#354)

Fixes

  • ts-sdk: fix resolvePerpBankrupcty to work with all perp market indexes
  • ts-sdk: getTokenAmount uses divCeil (#371)
  • program: allow limit orders to have explicit zero auction duration passed in params (#373)

Breaking

[2.17.0] - 2023-02-17

Features

  • program: order params utilize post only enum (#361)

Fixes

  • program: twap tweaks, update only on new cluster time (#362)

Breaking

[2.16.0] - 2023-02-14

Features

  • sdk: add support for market lookup table (#359)
  • program: tweak calculate_size_premium_liability_weight to have smaller effect on initial margin (#350)
  • ts-sdk: updates for accounting for spot leverage (#295)
  • ts-sdk: added new methods for modifying orders to include spot and more params (#353)
  • ts-sdk: flagged old modifyPerpOrder and modifyPerpOrderByUserOrderId as deprecated

Fixes

  • ts-sdk: DLOB matching logic accounts for zero-price spot market orders not matching resting limit orders
  • ts-sdk: new squareRootBN implementation using bit shifting (2x speed improvement)
  • program: fix overflow in calculate_long_short_vol_spread (#352)
  • program: dont let users disable margin trading if they have margin orders open
  • program: tweaks to fix max leverage order param flag with imf factor (#351)
  • program: improve bid/ask twap calculation for funding rate stability (#345)
  • ts-sdk: fix borrow limit calc (#356)

Breaking

[2.15.0] - 2023-02-07

Features

  • ts-sdk: add aptos

Fixes

Breaking

[2.14.0] - 2023-02-06

Features

  • program: flag to set max leverage for orders (#346)
  • program: do imf size discount for maintainance spot asset weight (#343)
  • ts-sdk: new liquidation price to account for delta neutral strategies (#340)
  • ts-sdk: add txParams to all instructions, bump @solana/web3.js (#344)

Fixes

  • program: extend time before limit order is considered resting (#349)
  • ts-sdk: improve funding rate prediction
  • program: block jit maker orders from cross vamm
  • program: cancel_order_by_user_order_id fails if order is not found

Breaking

[2.13.0] - 2023-01-31

Features

  • program: perp bankruptcies pay from fee pool before being socialized (#332)
  • ts-sdk: add calculateAvailablePerpLiquidity
  • program: enforce min order size when trading against amm (#334)

Fixes

  • ts-sdk: fix the getBuyingPower calculation
  • ts-sdk: improved perp estimated liq price formula (#338)
  • ts-sdk: update methods to account for new leverage formula (#339)

Breaking

[2.12.0] - 2023-01-22

Features

  • program: allow for 2000 users
  • program: add resting limit order logic (#328)
  • ts-sdk: add calculateEstimatedSpotEntryPrice
  • ts-sdk: add ability to add priority fees (#331)
  • ts-sdk: new calculateEstimatedPerpEntryPrice that accounts for dlob & vamm (#326)

Fixes

  • program: better rounding for openbook limit price
  • program: fix paying fee_pool_delta when filling with open book
  • program: bitflags for exchange status (#330)
  • program: update fee calculation for filling against openbook
  • program: relax conditions for valid oracle price in fulfill_perp_order
  • program: handle fallback price when amm has no liquidity (#324)
  • sdk: add getRestingLimitBids/Asks to DLOB (#325)
  • program: tweak oracle price used for determine_perp_fulfillment_methods

Breaking

[2.11.0] - 2023-01-11

Features

  • program: remove canceling market orders with limit price after first fill
  • program: try to match against multiple of makers orders (#315)
  • program: limit number of users to 1500
  • program: more rigorous risk decreasing check in place_perp_order/place_stop_order

Fixes

  • program: avoid overflow when calculating overflow (#322)
  • ts-sdk: fix user.getUnrealizedPnl to account for lp position
  • program: cancel market order for not satisfying limit price only if there was some base asset amount filled

Breaking

[2.10.0] - 2023-01-03

Features

  • program: place order returns early if max ts breached (#317)
  • ts-sdk: batch getMultipleAccount calls in bulkAccountLoader (#315)
  • program: add clippy deny for panic, expect and unwrap
  • program: add market index offset trait (#287)
  • program: add size trait to accounts and events (#286)

Fixes

  • program: add access control for spot market updates similar to perp market (#284)
  • ts-sdk: allow websocket subscriber to skip getAccount call to rpc (#313)
  • ts-sdk: always add market account for cancelOrders if market index included
  • anchor tests: make deterministic to run in ci (#289)
  • ts-sdk: fix deprecated calls to @solana/web3.js (#299)
  • ts-sdk: fix calculateAssetWeight for Maintenance Margin (#308)
  • ts-sdk: fix UserMap for websocket usage (#308)

Breaking

[2.9.0] - 2022-12-23

Features

  • program: use vamm price to guard against bad fills for limit orders (#304)

Fixes

  • ts-sdk: expect signTransaction from wallet adapters to return a copy (#299)

Breaking

[2.8.0] - 2022-12-22

Features

  • program: add force_cancel_orders to cancel risk-increasing orders for users with excessive leverage (#298)

Fixes

  • program: fix calculate_availability_borrow_liquidity (#301)
  • program: fix casting in fulfill_spot_order_with_match to handle implied max_base_asset_amounts
  • sdk: fix BulkAccountLoader starvation (#300)

Breaking

[2.7.0] - 2022-12-19

Features

Fixes

program: more leniency in allowing risk decreasing trades for perps (#297) program: fix is_user_being_liquidated in deposit

Breaking

[2.6.0] - 2022-12-16

Features

program: allow keeper to switch user status to active by calling liquidate perp (#296)

Fixes

  • program: more precise update k in prepeg (#294)
  • program: allow duplicative reduce only orders (#293)
  • program: fix should_cancel_reduce_only_order
  • ts-sdk: add Oracle OrderType to dlob idl

Breaking

[2.5.0] - 2022-12-13

Features

Fixes

  • program: disable lower bound check for update amm once it's already been breached (#292)
  • ts-sdk: fix DLOB.updateOrder (#290)
  • ts-sdk: make calculateClaimablePnl mirror on-chain logic (#291)
  • ts-sdk: add margin trading toggle field to user accounts, update toggle margin trading function to add ability to toggle for any subaccount rather than just the active (#285)

Breaking

[2.4.0] - 2022-12-09

Features

  • program: check if place_perp_order can lead to breach in max oi (#283)
  • program: find fallback maker order if passed order id doesnt exist (#281)

Fixes

  • program: fix amm-jit so makers can fill the full size of their order after amm-jit occurs (#280)

Breaking

[2.3.0] - 2022-12-07

Features

Fixes

  • program: update the amm min/max_base_asset_reserve upon k decreases within update_amm (#282)
  • program: fix amm-jit erroring out when bids/asks are zero (#279)
  • ts-sdk: fix overflow in inventorySpreadScale

Breaking

[2.2.0] - 2022-12-06

Features

  • ts-sdk: add btc/eth perp market configs for mainnet (#277)
  • program: reduce if stake requirement for better fee tier (#275)
  • program: new oracle order where auction price is oracle price offset (#269).
  • program: block negative pnl settles which would lead to more borrows when quote spot utilization is high (#273).

Fixes

  • ts-sdk: fix bugs in calculateSpreadBN
  • ts-sdk: fix additional bug in calculateSpreadBN (negative nums)

Breaking