6min

SDK FAQ

What are the precisions for data on Drift?

The Drift SDK uses BigNum (BN), using this package, to represent numerical values. 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.

These available as constants to import from the SDK.

Precision Name

Value

AMM_RESERVE_PRECISION

1e13

MARK_PRICE_PRECISION

1e10

QUOTE_PRECISION

1e6

MARGIN_PRECISION

1e4

FUNDING_PAYMENT_PRECISION

1e4

PEG_PRECISION

1e3

How can I stream account/position updates?

How can i calculate funding rate in the contract? What about %? What about % APR?

to convert FundingRateRecord . fundingRate to APR %

funding rate is in 10e14, the unit is quote amount (USDC) owned for each single base asset amount to convert to APR % you need to divide by the oracle_twap (1e10) and then multiply 365.25*24

example: so if BTC funding = 6.2 thats 6.2 usdc per BTC 6.2/44000 365.25 24 = % APR

is there a way to debug what the custom program errors mean? (i'm getting custom program error: 0x1774 when trying to liquidate)

convert 0x1774 to decimal (= 6004)

check idl (clearing_house.json) in repo: https://github.com/drift-labs/protocol-v1/blob/master/sdk/src/idl/clearing_house.json { "code": 6004, "name": "SufficientCollateral", "msg": "Sufficient collateral" }

so the user has sufficient collateral to not be liquidated. its most likely that another liquidator already (partially/fully) liquidated them



Updated 23 Mar 2022
Did this page help?
Yes
No