@drift-labs/sdk 2.24.0 → 2.25.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/accounts/fetch.d.ts +1 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingOracleAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +1 -1
- package/lib/addresses/pda.d.ts +1 -2
- package/lib/addresses/pda.js +1 -1
- package/lib/adminClient.d.ts +1 -2
- package/lib/adminClient.js +2 -2
- package/lib/constants/numericConstants.d.ts +59 -61
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/constants/spotMarkets.d.ts +0 -1
- package/lib/dlob/DLOB.d.ts +0 -1
- package/lib/dlob/DLOBNode.d.ts +0 -1
- package/lib/dlob/DLOBOrders.d.ts +1 -1
- package/lib/dlob/DLOBOrders.js +1 -1
- package/lib/dlob/NodeList.d.ts +0 -1
- package/lib/driftClient.d.ts +38 -23
- package/lib/driftClient.js +85 -131
- package/lib/events/eventSubscriber.d.ts +1 -1
- package/lib/events/eventSubscriber.js +3 -2
- package/lib/events/fetchLogs.d.ts +1 -1
- package/lib/events/fetchLogs.js +3 -2
- package/lib/examples/loadDlob.js +1 -1
- package/lib/examples/makeTradeExample.js +1 -1
- package/lib/factory/bigNum.d.ts +8 -9
- package/lib/factory/bigNum.js +1 -1
- package/lib/factory/oracleClient.js +1 -1
- package/lib/idl/drift.json +181 -14
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/math/amm.d.ts +2 -3
- package/lib/math/amm.js +1 -1
- package/lib/math/auction.d.ts +0 -1
- package/lib/math/conversion.d.ts +1 -2
- package/lib/math/funding.d.ts +1 -2
- package/lib/math/funding.js +1 -1
- package/lib/math/insurance.d.ts +1 -1
- package/lib/math/insurance.js +17 -1
- package/lib/math/margin.d.ts +1 -2
- package/lib/math/margin.js +1 -1
- package/lib/math/market.d.ts +1 -2
- package/lib/math/market.js +1 -1
- package/lib/math/oracles.d.ts +0 -1
- package/lib/math/oracles.js +2 -3
- package/lib/math/orders.d.ts +1 -2
- package/lib/math/orders.js +1 -1
- package/lib/math/position.d.ts +0 -1
- package/lib/math/repeg.d.ts +1 -2
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.d.ts +1 -2
- package/lib/math/spotBalance.js +1 -1
- package/lib/math/spotMarket.d.ts +1 -2
- package/lib/math/spotMarket.js +1 -1
- package/lib/math/spotPosition.d.ts +1 -2
- package/lib/math/trade.d.ts +1 -2
- package/lib/math/trade.js +1 -1
- package/lib/math/utils.d.ts +0 -1
- package/lib/oracles/pythClient.d.ts +2 -3
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/types.d.ts +1 -2
- package/lib/orderParams.d.ts +1 -2
- package/lib/serum/serumSubscriber.d.ts +1 -2
- package/lib/serum/serumSubscriber.js +1 -1
- package/lib/tokenFaucet.d.ts +2 -3
- package/lib/tokenFaucet.js +2 -2
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +8 -3
- package/lib/types.js +2 -1
- package/lib/user.d.ts +0 -1
- package/package.json +2 -2
- package/src/accounts/fetch.ts +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/pollingOracleAccountSubscriber.ts +1 -1
- package/src/accounts/pollingTokenAccountSubscriber.ts +1 -1
- package/src/accounts/pollingUserAccountSubscriber.ts +1 -1
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketUserAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +1 -1
- package/src/addresses/pda.ts +2 -2
- package/src/adminClient.ts +2 -2
- package/src/constants/perpMarkets.ts +10 -0
- package/src/dlob/DLOBOrders.ts +2 -2
- package/src/driftClient.ts +136 -153
- package/src/events/eventSubscriber.ts +7 -3
- package/src/events/fetchLogs.ts +7 -3
- package/src/examples/loadDlob.ts +1 -1
- package/src/examples/makeTradeExample.ts +1 -1
- package/src/factory/bigNum.ts +1 -1
- package/src/factory/oracleClient.ts +1 -1
- package/src/idl/drift.json +181 -14
- package/src/index.ts +1 -1
- package/src/math/amm.ts +1 -1
- package/src/math/funding.ts +1 -1
- package/src/math/insurance.ts +29 -0
- package/src/math/margin.ts +1 -1
- package/src/math/market.ts +1 -1
- package/src/math/oracles.ts +2 -3
- package/src/math/orders.ts +1 -1
- package/src/math/repeg.ts +1 -1
- package/src/math/spotBalance.ts +1 -1
- package/src/math/spotMarket.ts +1 -1
- package/src/math/spotPosition.ts +1 -1
- package/src/math/trade.ts +1 -1
- package/src/oracles/pythClient.ts +1 -1
- package/src/oracles/quoteAssetOracleClient.ts +1 -1
- package/src/oracles/types.ts +1 -1
- package/src/orderParams.ts +1 -1
- package/src/serum/serumSubscriber.ts +1 -1
- package/src/tokenFaucet.ts +2 -2
- package/src/tx/retryTxSender.ts +1 -1
- package/src/tx/types.ts +1 -1
- package/src/types.ts +6 -1
- package/src/userMap/userStatsMap.ts +1 -1
package/lib/math/amm.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { BN } from '@project-serum/anchor';
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
2
|
import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
4
3
|
import { OraclePriceData } from '../oracles/types';
|
|
5
4
|
export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
|
|
@@ -87,7 +86,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
|
|
|
87
86
|
* @param market
|
|
88
87
|
* @returns cost : Precision PRICE_PRECISION
|
|
89
88
|
*/
|
|
90
|
-
export declare function calculateTerminalPrice(market: PerpMarketAccount):
|
|
89
|
+
export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
|
|
91
90
|
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
|
|
92
91
|
export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
|
|
93
92
|
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
|
package/lib/math/amm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateVolSpreadBN = exports.calculateMaxSpread = exports.calculateEffectiveLeverage = exports.calculateInventoryScale = exports.calculateMarketOpenBidAsk = exports.calculateAmmReservesAfterSwap = exports.calculatePrice = exports.calculateBidAskPrice = exports.calculateUpdatedAMMSpreadReserves = exports.calculateUpdatedAMM = exports.calculateNewAmm = exports.calculateOptimalPegAndBudget = exports.calculatePegFromTargetPrice = void 0;
|
|
4
|
-
const anchor_1 = require("@
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
const assert_1 = require("../assert/assert");
|
package/lib/math/auction.d.ts
CHANGED
package/lib/math/conversion.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
|
|
1
|
+
export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
|
package/lib/math/funding.d.ts
CHANGED
package/lib/math/funding.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateFundingPool = exports.calculateLongShortFundingRateAndLiveTwaps = exports.calculateLongShortFundingRate = exports.calculateEstimatedFundingRate = exports.calculateAllEstimatedFundingRate = void 0;
|
|
4
|
-
const anchor_1 = require("@
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
const amm_1 = require("./amm");
|
package/lib/math/insurance.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BN } from '../index';
|
|
3
2
|
export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
4
3
|
export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
4
|
+
export declare function unstakeSharesToAmountWithOpenRequest(nShares: BN, withdrawRequestShares: BN, withdrawRequestAmount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
package/lib/math/insurance.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
|
|
3
|
+
exports.unstakeSharesToAmountWithOpenRequest = exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
|
|
4
4
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
5
5
|
const index_1 = require("../index");
|
|
6
6
|
function stakeAmountToShares(amount, totalIfShares, insuranceFundVaultBalance) {
|
|
@@ -25,3 +25,19 @@ function unstakeSharesToAmount(nShares, totalIfShares, insuranceFundVaultBalance
|
|
|
25
25
|
return amount;
|
|
26
26
|
}
|
|
27
27
|
exports.unstakeSharesToAmount = unstakeSharesToAmount;
|
|
28
|
+
function unstakeSharesToAmountWithOpenRequest(nShares, withdrawRequestShares, withdrawRequestAmount, totalIfShares, insuranceFundVaultBalance) {
|
|
29
|
+
let stakedAmount;
|
|
30
|
+
if (totalIfShares.gt(numericConstants_1.ZERO)) {
|
|
31
|
+
stakedAmount = index_1.BN.max(numericConstants_1.ZERO, nShares
|
|
32
|
+
.sub(withdrawRequestShares)
|
|
33
|
+
.mul(insuranceFundVaultBalance)
|
|
34
|
+
.div(totalIfShares));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
stakedAmount = numericConstants_1.ZERO;
|
|
38
|
+
}
|
|
39
|
+
const withdrawAmount = index_1.BN.min(withdrawRequestAmount, withdrawRequestShares.mul(insuranceFundVaultBalance).div(totalIfShares));
|
|
40
|
+
const amount = withdrawAmount.add(stakedAmount);
|
|
41
|
+
return amount;
|
|
42
|
+
}
|
|
43
|
+
exports.unstakeSharesToAmountWithOpenRequest = unstakeSharesToAmountWithOpenRequest;
|
package/lib/math/margin.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { BN } from '@project-serum/anchor';
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
2
|
import { OraclePriceData } from '../oracles/types';
|
|
4
3
|
import { PerpMarketAccount, PerpPosition } from '..';
|
|
5
4
|
export declare function calculateSizePremiumLiabilityWeight(size: BN, // AMM_RESERVE_PRECISION
|
package/lib/math/margin.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateOraclePriceForPerpMargin = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
-
const anchor_1 = require("@
|
|
6
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const assert_1 = require("../assert/assert");
|
|
9
9
|
function calculateSizePremiumLiabilityWeight(size, // AMM_RESERVE_PRECISION
|
package/lib/math/market.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { BN } from '@project-serum/anchor';
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
2
|
import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
|
|
4
3
|
import { OraclePriceData } from '../oracles/types';
|
|
5
4
|
import { DLOB } from '../dlob/DLOB';
|
package/lib/math/market.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateAvailablePerpLiquidity = exports.calculateNetUserPnlImbalance = exports.calculateNetUserPnl = exports.calculateMarketMaxAvailableInsurance = exports.calculateMarketAvailablePNL = exports.calculateUnrealizedAssetWeight = exports.calculateMarketMarginRatio = exports.calculateOracleSpread = exports.calculateOracleReserveSpread = exports.calculateNewMarketAfterTrade = exports.calculateAskPrice = exports.calculateBidPrice = exports.calculateReservePrice = void 0;
|
|
4
|
-
const anchor_1 = require("@
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const amm_1 = require("./amm");
|
|
7
7
|
const margin_1 = require("./margin");
|
package/lib/math/oracles.d.ts
CHANGED
package/lib/math/oracles.js
CHANGED
|
@@ -21,11 +21,10 @@ function isOracleValid(amm, oraclePriceData, oracleGuardRails, slot) {
|
|
|
21
21
|
amm.historicalOracleData.lastOraclePriceTwap
|
|
22
22
|
.div(index_1.BN.max(numericConstants_1.ONE, oraclePriceData.price))
|
|
23
23
|
.gt(oracleGuardRails.validity.tooVolatileRatio);
|
|
24
|
-
const isConfidenceTooLarge =
|
|
25
|
-
.add(index_1.BN.max(numericConstants_1.ONE, oraclePriceData.confidence))
|
|
24
|
+
const isConfidenceTooLarge = index_1.BN.max(numericConstants_1.ONE, oraclePriceData.confidence)
|
|
26
25
|
.mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
|
|
27
26
|
.div(oraclePriceData.price)
|
|
28
|
-
.gt(
|
|
27
|
+
.gt(oracleGuardRails.validity.confidenceIntervalMaxSize);
|
|
29
28
|
const oracleIsStale = oraclePriceData.slot
|
|
30
29
|
.sub(new index_1.BN(slot))
|
|
31
30
|
.gt(oracleGuardRails.validity.slotsBeforeStaleForAmm);
|
package/lib/math/orders.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { User } from '../user';
|
|
3
2
|
import { PerpMarketAccount, AMM, Order } from '../types';
|
|
4
|
-
import { BN } from '@
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
5
4
|
import { OraclePriceData } from '../oracles/types';
|
|
6
5
|
export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
|
|
7
6
|
export declare function isOrderRiskIncreasingInSameDirection(user: User, order: Order): boolean;
|
package/lib/math/orders.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
-
const anchor_1 = require("@
|
|
6
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
7
|
const auction_1 = require("./auction");
|
|
8
8
|
const amm_1 = require("./amm");
|
|
9
9
|
function isOrderRiskIncreasing(user, order) {
|
package/lib/math/position.d.ts
CHANGED
package/lib/math/repeg.d.ts
CHANGED
package/lib/math/repeg.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateBudgetedPeg = exports.calculateBudgetedK = exports.calculateBudgetedKBN = exports.calculateRepegCost = exports.calculateAdjustKCost = void 0;
|
|
4
|
-
const anchor_1 = require("@
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
5
|
const assert_1 = require("../assert/assert");
|
|
6
6
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
7
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
import { OraclePriceData } from '../oracles/types';
|
|
5
4
|
export declare function getBalance(tokenAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
|
|
6
5
|
export declare function getTokenAmount(balanceAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
|
package/lib/math/spotBalance.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateWithdrawLimit = exports.calculateInterestAccumulated = exports.calculateBorrowRate = exports.calculateDepositRate = exports.calculateInterestRate = exports.calculateUtilization = exports.calculateLiabilityWeight = exports.calculateAssetWeight = exports.getTokenValue = exports.getStrictTokenValue = exports.getSignedTokenAmount = exports.getTokenAmount = exports.getBalance = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
const anchor_1 = require("@
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
6
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
7
|
const margin_1 = require("./margin");
|
|
8
8
|
const numericConstants_2 = require("../constants/numericConstants");
|
package/lib/math/spotMarket.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { BN } from '@project-serum/anchor';
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
2
|
import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
|
|
4
3
|
export declare function castNumberToSpotPrecision(value: number, spotMarket: SpotMarketAccount): BN;
|
|
5
4
|
export declare function calculateSpotMarketMarginRatio(market: SpotMarketAccount, marginCategory: MarginCategory, size: BN, balanceType: SpotBalanceType): number;
|
package/lib/math/spotMarket.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateSpotMarketMarginRatio = exports.castNumberToSpotPrecision = void 0;
|
|
4
|
-
const anchor_1 = require("@
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const spotBalance_1 = require("./spotBalance");
|
|
7
7
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { SpotMarketAccount, SpotPosition } from '../types';
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
import { OraclePriceData } from '../oracles/types';
|
|
5
4
|
export declare function isSpotPositionAvailable(position: SpotPosition): boolean;
|
|
6
5
|
export declare function getWorstCaseTokenAmounts(spotPosition: SpotPosition, spotMarketAccount: SpotMarketAccount, oraclePriceData: OraclePriceData): [BN, BN];
|
package/lib/math/trade.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PerpMarketAccount, PositionDirection, SpotMarketAccount } from '../types';
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
import { AssetType } from './amm';
|
|
5
4
|
import { OraclePriceData } from '../oracles/types';
|
|
6
5
|
import { DLOB } from '../dlob/DLOB';
|
package/lib/math/trade.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateEstimatedSpotEntryPrice = exports.calculateEstimatedPerpEntryPrice = exports.calculateTargetPriceTrade = exports.calculateTradeAcquiredAmounts = exports.calculateTradeSlippage = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
const anchor_1 = require("@
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
6
|
const assert_1 = require("../assert/assert");
|
|
7
7
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
8
8
|
const market_1 = require("./market");
|
package/lib/math/utils.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
2
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
3
|
import { OracleClient, OraclePriceData } from './types';
|
|
5
|
-
import { BN } from '@
|
|
4
|
+
import { BN } from '@coral-xyz/anchor';
|
|
6
5
|
export declare class PythClient implements OracleClient {
|
|
7
6
|
private connection;
|
|
8
7
|
private multiple;
|
|
9
8
|
private stableCoin;
|
|
10
|
-
constructor(connection: Connection, multiple?:
|
|
9
|
+
constructor(connection: Connection, multiple?: any, stableCoin?: boolean);
|
|
11
10
|
getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
|
|
12
11
|
getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
|
|
13
12
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertPythPrice = exports.PythClient = void 0;
|
|
4
4
|
const client_1 = require("@pythnetwork/client");
|
|
5
|
-
const anchor_1 = require("@
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
6
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
7
|
class PythClient {
|
|
8
8
|
constructor(connection, multiple = numericConstants_1.ONE, stableCoin = false) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuoteAssetOracleClient = exports.QUOTE_ORACLE_PRICE_DATA = void 0;
|
|
4
|
-
const anchor_1 = require("@
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
exports.QUOTE_ORACLE_PRICE_DATA = {
|
|
7
7
|
price: numericConstants_1.PRICE_PRECISION,
|
package/lib/oracles/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
import { PublicKey } from '@solana/web3.js';
|
|
5
4
|
import { OracleSource } from '../types';
|
|
6
5
|
export type OraclePriceData = {
|
package/lib/orderParams.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { OptionalOrderParams, OrderTriggerCondition } from './types';
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
|
|
5
4
|
price: BN;
|
|
6
5
|
}): OptionalOrderParams;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
2
|
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
3
|
import { Market, Orderbook } from '@project-serum/serum';
|
|
5
4
|
import { SerumMarketSubscriberConfig } from './types';
|
|
6
|
-
import { BN } from '@
|
|
5
|
+
import { BN } from '@coral-xyz/anchor';
|
|
7
6
|
export declare class SerumSubscriber {
|
|
8
7
|
connection: Connection;
|
|
9
8
|
programId: PublicKey;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SerumSubscriber = void 0;
|
|
4
4
|
const serum_1 = require("@project-serum/serum");
|
|
5
|
-
const anchor_1 = require("@
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
6
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
7
|
class SerumSubscriber {
|
|
8
8
|
constructor(config) {
|
package/lib/tokenFaucet.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { AnchorProvider, Program } from '@project-serum/anchor';
|
|
1
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
2
|
+
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
4
3
|
import { AccountInfo } from '@solana/spl-token';
|
|
5
4
|
import { ConfirmOptions, Connection, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
6
5
|
import { BN } from '.';
|
package/lib/tokenFaucet.js
CHANGED
|
@@ -27,8 +27,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.TokenFaucet = void 0;
|
|
30
|
-
const anchor = __importStar(require("@
|
|
31
|
-
const anchor_1 = require("@
|
|
30
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
31
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
32
32
|
const spl_token_1 = require("@solana/spl-token");
|
|
33
33
|
const web3_js_1 = require("@solana/web3.js");
|
|
34
34
|
const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { TxSender, TxSigAndSlot } from './types';
|
|
3
3
|
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
4
|
-
import { AnchorProvider } from '@
|
|
4
|
+
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
5
5
|
type ResolveReference = {
|
|
6
6
|
resolve?: () => void;
|
|
7
7
|
};
|
package/lib/tx/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider } from '@
|
|
1
|
+
import { Provider } from '@coral-xyz/anchor';
|
|
2
2
|
import { AddressLookupTableAccount, ConfirmOptions, Signer, Transaction, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
3
3
|
export type TxSigAndSlot = {
|
|
4
4
|
txSig: TransactionSignature;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
3
2
|
import { BN } from '.';
|
|
4
3
|
export declare enum ExchangeStatus {
|
|
@@ -253,8 +252,11 @@ export declare class OrderTriggerCondition {
|
|
|
253
252
|
};
|
|
254
253
|
}
|
|
255
254
|
export declare class SpotFulfillmentType {
|
|
256
|
-
static readonly
|
|
257
|
-
|
|
255
|
+
static readonly EXTERNAL: {
|
|
256
|
+
external: {};
|
|
257
|
+
};
|
|
258
|
+
static readonly MATCH: {
|
|
259
|
+
match: {};
|
|
258
260
|
};
|
|
259
261
|
}
|
|
260
262
|
export declare class SpotFulfillmentStatus {
|
|
@@ -928,6 +930,9 @@ export type NecessaryOrderParams = {
|
|
|
928
930
|
export type OptionalOrderParams = {
|
|
929
931
|
[Property in keyof OrderParams]?: OrderParams[Property];
|
|
930
932
|
} & NecessaryOrderParams;
|
|
933
|
+
export type ModifyOrderParams = {
|
|
934
|
+
[Property in keyof OrderParams]?: OrderParams[Property] | null;
|
|
935
|
+
};
|
|
931
936
|
export declare const DefaultOrderParams: OrderParams;
|
|
932
937
|
export type MakerInfo = {
|
|
933
938
|
maker: PublicKey;
|
package/lib/types.js
CHANGED
|
@@ -162,7 +162,8 @@ OrderTriggerCondition.TRIGGERED_BELOW = { triggeredBelow: {} }; // below conditi
|
|
|
162
162
|
class SpotFulfillmentType {
|
|
163
163
|
}
|
|
164
164
|
exports.SpotFulfillmentType = SpotFulfillmentType;
|
|
165
|
-
SpotFulfillmentType.
|
|
165
|
+
SpotFulfillmentType.EXTERNAL = { external: {} };
|
|
166
|
+
SpotFulfillmentType.MATCH = { match: {} };
|
|
166
167
|
class SpotFulfillmentStatus {
|
|
167
168
|
}
|
|
168
169
|
exports.SpotFulfillmentStatus = SpotFulfillmentStatus;
|
package/lib/user.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.0-beta.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
36
|
+
"@coral-xyz/anchor": "0.26.0",
|
|
37
37
|
"@project-serum/serum": "^0.13.38",
|
|
38
38
|
"@pythnetwork/client": "2.5.3",
|
|
39
39
|
"@solana/spl-token": "^0.1.6",
|
package/src/accounts/fetch.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
NotSubscribedError,
|
|
7
7
|
OraclesToPoll,
|
|
8
8
|
} from './types';
|
|
9
|
-
import { Program } from '@
|
|
9
|
+
import { Program } from '@coral-xyz/anchor';
|
|
10
10
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
12
12
|
import {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
OracleEvents,
|
|
5
5
|
OracleAccountSubscriber,
|
|
6
6
|
} from './types';
|
|
7
|
-
import { Program } from '@
|
|
7
|
+
import { Program } from '@coral-xyz/anchor';
|
|
8
8
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
9
9
|
import { EventEmitter } from 'events';
|
|
10
10
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
TokenAccountEvents,
|
|
5
5
|
TokenAccountSubscriber,
|
|
6
6
|
} from './types';
|
|
7
|
-
import { Program } from '@
|
|
7
|
+
import { Program } from '@coral-xyz/anchor';
|
|
8
8
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
9
9
|
import { EventEmitter } from 'events';
|
|
10
10
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
UserAccountEvents,
|
|
6
6
|
UserAccountSubscriber,
|
|
7
7
|
} from './types';
|
|
8
|
-
import { Program } from '@
|
|
8
|
+
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
UserStatsAccountSubscriber,
|
|
6
6
|
UserStatsAccountEvents,
|
|
7
7
|
} from './types';
|
|
8
|
-
import { Program } from '@
|
|
8
|
+
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
|
|
2
|
-
import { AnchorProvider, Program } from '@
|
|
2
|
+
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
3
3
|
import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { capitalize } from './utils';
|
|
5
5
|
import * as Buffer from 'buffer';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from './types';
|
|
6
6
|
import { AccountSubscriber, NotSubscribedError } from './types';
|
|
7
7
|
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
8
|
-
import { Program } from '@
|
|
8
|
+
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import {
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
UserAccountEvents,
|
|
6
6
|
UserAccountSubscriber,
|
|
7
7
|
} from './types';
|
|
8
|
-
import { Program } from '@
|
|
8
|
+
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
UserStatsAccountSubscriber,
|
|
6
6
|
UserStatsAccountEvents,
|
|
7
7
|
} from './types';
|
|
8
|
-
import { Program } from '@
|
|
8
|
+
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import { PublicKey } from '@solana/web3.js';
|
package/src/addresses/pda.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import * as anchor from '@
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
4
|
|
|
5
5
|
export async function getDriftStateAccountPublicKeyAndNonce(
|
|
6
6
|
programId: PublicKey
|
package/src/adminClient.ts
CHANGED
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
SpotFulfillmentConfigStatus,
|
|
15
15
|
} from './types';
|
|
16
16
|
import { DEFAULT_MARKET_NAME, encodeName } from './userName';
|
|
17
|
-
import { BN } from '@
|
|
18
|
-
import * as anchor from '@
|
|
17
|
+
import { BN } from '@coral-xyz/anchor';
|
|
18
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
19
19
|
import {
|
|
20
20
|
getDriftStateAccountPublicKeyAndNonce,
|
|
21
21
|
getSpotMarketPublicKey,
|
|
@@ -94,6 +94,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
94
94
|
launchTs: 1680808053000,
|
|
95
95
|
oracleSource: OracleSource.PYTH,
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
fullName: 'Binance Coin',
|
|
99
|
+
category: ['Exchange'],
|
|
100
|
+
symbol: 'BNB-PERP',
|
|
101
|
+
baseAssetSymbol: 'BNB',
|
|
102
|
+
marketIndex: 8,
|
|
103
|
+
oracle: new PublicKey('GwzBgrXb4PG59zjce24SF2b9JXbLEjJJTBkmytuEZj1b'),
|
|
104
|
+
launchTs: 1680808053000,
|
|
105
|
+
oracleSource: OracleSource.PYTH,
|
|
106
|
+
},
|
|
97
107
|
];
|
|
98
108
|
|
|
99
109
|
export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
package/src/dlob/DLOBOrders.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { Idl } from '@
|
|
3
|
-
import { IdlCoder } from '@
|
|
2
|
+
import { Idl } from '@coral-xyz/anchor';
|
|
3
|
+
import { IdlCoder } from '@coral-xyz/anchor/dist/cjs/coder/borsh/idl';
|
|
4
4
|
import dlobIDL from './dlobIdl.json';
|
|
5
5
|
import { Order } from '../types';
|
|
6
6
|
|