@drift-labs/sdk 2.42.0-beta.1 → 2.42.0-beta.10
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/VERSION +1 -1
- package/bun.lockb +0 -0
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/adminClient.d.ts +1 -0
- package/lib/constants/numericConstants.d.ts +62 -59
- package/lib/constants/numericConstants.js +2 -1
- package/lib/constants/spotMarkets.d.ts +1 -0
- package/lib/dlob/DLOB.d.ts +10 -16
- package/lib/dlob/DLOB.js +9 -39
- package/lib/dlob/DLOBNode.d.ts +1 -0
- package/lib/dlob/NodeList.d.ts +1 -0
- package/lib/dlob/orderBookLevels.d.ts +2 -1
- package/lib/driftClient.d.ts +12 -4
- package/lib/driftClient.js +51 -38
- package/lib/factory/bigNum.d.ts +8 -7
- package/lib/jupiter/jupiterClient.d.ts +1 -0
- package/lib/marinade/index.d.ts +1 -0
- package/lib/math/amm.d.ts +2 -1
- package/lib/math/auction.d.ts +1 -0
- package/lib/math/conversion.d.ts +2 -1
- package/lib/math/funding.d.ts +1 -0
- package/lib/math/funding.js +2 -1
- package/lib/math/insurance.d.ts +1 -0
- package/lib/math/margin.d.ts +1 -0
- package/lib/math/market.d.ts +2 -1
- package/lib/math/market.js +3 -2
- package/lib/math/oracles.d.ts +1 -0
- package/lib/math/orders.d.ts +1 -0
- package/lib/math/position.d.ts +1 -0
- package/lib/math/repeg.d.ts +1 -0
- package/lib/math/spotBalance.d.ts +3 -2
- package/lib/math/spotMarket.d.ts +2 -1
- package/lib/math/spotMarket.js +9 -3
- package/lib/math/spotPosition.d.ts +4 -3
- package/lib/math/spotPosition.js +18 -7
- package/lib/math/superStake.d.ts +1 -0
- package/lib/math/trade.d.ts +1 -0
- package/lib/math/utils.d.ts +1 -0
- package/lib/oracles/pythClient.d.ts +2 -1
- package/lib/oracles/strictOraclePrice.d.ts +1 -0
- package/lib/oracles/types.d.ts +1 -0
- package/lib/orderParams.d.ts +1 -0
- package/lib/phoenix/phoenixSubscriber.d.ts +1 -0
- package/lib/serum/serumSubscriber.d.ts +1 -0
- package/lib/tokenFaucet.d.ts +1 -0
- package/lib/types.d.ts +7 -0
- package/lib/types.js +2 -0
- package/lib/user.d.ts +3 -2
- package/lib/user.js +29 -26
- package/package.json +2 -1
- package/src/constants/numericConstants.ts +1 -0
- package/src/dlob/DLOB.ts +23 -67
- package/src/driftClient.ts +79 -53
- package/src/math/funding.ts +6 -1
- package/src/math/market.ts +12 -7
- package/src/math/spotMarket.ts +13 -3
- package/src/math/spotPosition.ts +29 -7
- package/src/types.ts +2 -0
- package/src/user.ts +64 -31
- package/tests/amm/test.ts +7 -5
- package/tests/auctions/test.ts +22 -11
- package/tests/dlob/helpers.ts +15 -13
- package/tests/tx/priorityFeeCalculator.ts +1 -1
- package/tests/user/test.ts +171 -24
package/src/user.ts
CHANGED
|
@@ -78,7 +78,6 @@ import {
|
|
|
78
78
|
getWorstCaseTokenAmounts,
|
|
79
79
|
isSpotPositionAvailable,
|
|
80
80
|
} from './math/spotPosition';
|
|
81
|
-
|
|
82
81
|
import { calculateLiveOracleTwap } from './math/oracles';
|
|
83
82
|
import { getPerpMarketTierNumber, getSpotMarketTierNumber } from './math/tiers';
|
|
84
83
|
import { StrictOraclePrice } from './oracles/strictOraclePrice';
|
|
@@ -632,7 +631,8 @@ export class User {
|
|
|
632
631
|
const marginRatio = calculateMarketMarginRatio(
|
|
633
632
|
this.driftClient.getPerpMarketAccount(marketIndex),
|
|
634
633
|
baseAssetAmount,
|
|
635
|
-
'Initial'
|
|
634
|
+
'Initial',
|
|
635
|
+
this.getUserAccount().maxMarginRatio
|
|
636
636
|
);
|
|
637
637
|
|
|
638
638
|
return freeCollateral.mul(MARGIN_PRECISION).div(new BN(marginRatio));
|
|
@@ -968,7 +968,8 @@ export class User {
|
|
|
968
968
|
spotPosition,
|
|
969
969
|
spotMarketAccount,
|
|
970
970
|
strictOraclePrice,
|
|
971
|
-
marginCategory
|
|
971
|
+
marginCategory,
|
|
972
|
+
this.getUserAccount().maxMarginRatio
|
|
972
973
|
);
|
|
973
974
|
|
|
974
975
|
if (worstCaseTokenAmount.gt(ZERO) && countForBase) {
|
|
@@ -1067,8 +1068,16 @@ export class User {
|
|
|
1067
1068
|
marginCategory
|
|
1068
1069
|
);
|
|
1069
1070
|
|
|
1070
|
-
if (
|
|
1071
|
-
|
|
1071
|
+
if (
|
|
1072
|
+
marginCategory === 'Initial' &&
|
|
1073
|
+
spotMarketAccount.marketIndex !== QUOTE_SPOT_MARKET_INDEX
|
|
1074
|
+
) {
|
|
1075
|
+
weight = BN.max(
|
|
1076
|
+
weight,
|
|
1077
|
+
SPOT_MARKET_WEIGHT_PRECISION.addn(
|
|
1078
|
+
this.getUserAccount().maxMarginRatio
|
|
1079
|
+
)
|
|
1080
|
+
);
|
|
1072
1081
|
}
|
|
1073
1082
|
|
|
1074
1083
|
if (liquidationBuffer !== undefined) {
|
|
@@ -1114,13 +1123,26 @@ export class User {
|
|
|
1114
1123
|
);
|
|
1115
1124
|
|
|
1116
1125
|
if (marginCategory !== undefined) {
|
|
1117
|
-
|
|
1126
|
+
let weight = calculateAssetWeight(
|
|
1118
1127
|
tokenAmount,
|
|
1119
1128
|
strictOraclePrice.current,
|
|
1120
1129
|
spotMarketAccount,
|
|
1121
1130
|
marginCategory
|
|
1122
1131
|
);
|
|
1123
1132
|
|
|
1133
|
+
if (
|
|
1134
|
+
marginCategory === 'Initial' &&
|
|
1135
|
+
spotMarketAccount.marketIndex !== QUOTE_SPOT_MARKET_INDEX
|
|
1136
|
+
) {
|
|
1137
|
+
const userCustomAssetWeight = BN.max(
|
|
1138
|
+
ZERO,
|
|
1139
|
+
SPOT_MARKET_WEIGHT_PRECISION.subn(
|
|
1140
|
+
this.getUserAccount().maxMarginRatio
|
|
1141
|
+
)
|
|
1142
|
+
);
|
|
1143
|
+
weight = BN.min(weight, userCustomAssetWeight);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1124
1146
|
assetValue = assetValue.mul(weight).div(SPOT_MARKET_WEIGHT_PRECISION);
|
|
1125
1147
|
}
|
|
1126
1148
|
|
|
@@ -1254,17 +1276,11 @@ export class User {
|
|
|
1254
1276
|
calculateMarketMarginRatio(
|
|
1255
1277
|
market,
|
|
1256
1278
|
baseAssetAmount.abs(),
|
|
1257
|
-
marginCategory
|
|
1279
|
+
marginCategory,
|
|
1280
|
+
this.getUserAccount().maxMarginRatio
|
|
1258
1281
|
)
|
|
1259
1282
|
);
|
|
1260
1283
|
|
|
1261
|
-
if (marginCategory === 'Initial') {
|
|
1262
|
-
marginRatio = BN.max(
|
|
1263
|
-
marginRatio,
|
|
1264
|
-
new BN(this.getUserAccount().maxMarginRatio)
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
1284
|
if (liquidationBuffer !== undefined) {
|
|
1269
1285
|
marginRatio = marginRatio.add(liquidationBuffer);
|
|
1270
1286
|
}
|
|
@@ -1494,25 +1510,28 @@ export class User {
|
|
|
1494
1510
|
return totalLiabilityValue.mul(TEN_THOUSAND).div(netAssetValue);
|
|
1495
1511
|
}
|
|
1496
1512
|
|
|
1497
|
-
getLeverageComponents(
|
|
1513
|
+
getLeverageComponents(
|
|
1514
|
+
includeOpenOrders = true,
|
|
1515
|
+
marginCategory: MarginCategory = undefined
|
|
1516
|
+
): {
|
|
1498
1517
|
perpLiabilityValue: BN;
|
|
1499
1518
|
perpPnl: BN;
|
|
1500
1519
|
spotAssetValue: BN;
|
|
1501
1520
|
spotLiabilityValue: BN;
|
|
1502
1521
|
} {
|
|
1503
1522
|
const perpLiability = this.getTotalPerpPositionValue(
|
|
1504
|
-
|
|
1523
|
+
marginCategory,
|
|
1505
1524
|
undefined,
|
|
1506
1525
|
includeOpenOrders
|
|
1507
1526
|
);
|
|
1508
|
-
const perpPnl = this.getUnrealizedPNL(true);
|
|
1527
|
+
const perpPnl = this.getUnrealizedPNL(true, undefined, marginCategory);
|
|
1509
1528
|
|
|
1510
1529
|
const {
|
|
1511
1530
|
totalAssetValue: spotAssetValue,
|
|
1512
1531
|
totalLiabilityValue: spotLiabilityValue,
|
|
1513
1532
|
} = this.getSpotMarketAssetAndLiabilityValue(
|
|
1514
1533
|
undefined,
|
|
1515
|
-
|
|
1534
|
+
marginCategory,
|
|
1516
1535
|
undefined,
|
|
1517
1536
|
includeOpenOrders
|
|
1518
1537
|
);
|
|
@@ -1599,7 +1618,10 @@ export class User {
|
|
|
1599
1618
|
|
|
1600
1619
|
switch (marginCategory) {
|
|
1601
1620
|
case 'Initial':
|
|
1602
|
-
rawMarginRatio =
|
|
1621
|
+
rawMarginRatio = Math.max(
|
|
1622
|
+
market.marginRatioInitial,
|
|
1623
|
+
this.getUserAccount().maxMarginRatio
|
|
1624
|
+
);
|
|
1603
1625
|
break;
|
|
1604
1626
|
case 'Maintenance':
|
|
1605
1627
|
rawMarginRatio = market.marginRatioMaintenance;
|
|
@@ -1623,7 +1645,8 @@ export class User {
|
|
|
1623
1645
|
let marginRatio = calculateMarketMarginRatio(
|
|
1624
1646
|
market,
|
|
1625
1647
|
maxSize,
|
|
1626
|
-
marginCategory
|
|
1648
|
+
marginCategory,
|
|
1649
|
+
this.getUserAccount().maxMarginRatio
|
|
1627
1650
|
);
|
|
1628
1651
|
|
|
1629
1652
|
// use more fesible size since imf factor activated
|
|
@@ -1643,7 +1666,8 @@ export class User {
|
|
|
1643
1666
|
marginRatio = calculateMarketMarginRatio(
|
|
1644
1667
|
market,
|
|
1645
1668
|
targetSize,
|
|
1646
|
-
marginCategory
|
|
1669
|
+
marginCategory,
|
|
1670
|
+
this.getUserAccount().maxMarginRatio
|
|
1647
1671
|
);
|
|
1648
1672
|
attempts += 1;
|
|
1649
1673
|
}
|
|
@@ -2177,6 +2201,7 @@ export class User {
|
|
|
2177
2201
|
: this.getPerpPositionValue(targetMarketIndex, oracleData);
|
|
2178
2202
|
|
|
2179
2203
|
let maxPositionSize = this.getPerpBuyingPower(targetMarketIndex, lpBuffer);
|
|
2204
|
+
|
|
2180
2205
|
if (maxPositionSize.gte(ZERO)) {
|
|
2181
2206
|
if (oppositeSizeValueUSDC.eq(ZERO)) {
|
|
2182
2207
|
// case 1 : Regular trade where current total position less than max, and no opposite position to account for
|
|
@@ -2262,7 +2287,8 @@ export class User {
|
|
|
2262
2287
|
ZERO,
|
|
2263
2288
|
isVariant(direction, 'long')
|
|
2264
2289
|
? SpotBalanceType.DEPOSIT
|
|
2265
|
-
: SpotBalanceType.BORROW
|
|
2290
|
+
: SpotBalanceType.BORROW,
|
|
2291
|
+
this.getUserAccount().maxMarginRatio
|
|
2266
2292
|
);
|
|
2267
2293
|
|
|
2268
2294
|
let tradeAmount = ZERO;
|
|
@@ -2275,7 +2301,8 @@ export class User {
|
|
|
2275
2301
|
oraclePrice,
|
|
2276
2302
|
'Initial',
|
|
2277
2303
|
this.getTokenAmount(targetMarketIndex).abs(),
|
|
2278
|
-
SpotBalanceType.BORROW
|
|
2304
|
+
SpotBalanceType.BORROW,
|
|
2305
|
+
this.getUserAccount().maxMarginRatio
|
|
2279
2306
|
);
|
|
2280
2307
|
freeCollateral = freeCollateral.add(
|
|
2281
2308
|
tradeAmount.mul(new BN(marginRatio)).div(MARGIN_PRECISION)
|
|
@@ -2290,7 +2317,8 @@ export class User {
|
|
|
2290
2317
|
oraclePrice,
|
|
2291
2318
|
'Initial',
|
|
2292
2319
|
this.getTokenAmount(targetMarketIndex),
|
|
2293
|
-
SpotBalanceType.DEPOSIT
|
|
2320
|
+
SpotBalanceType.DEPOSIT,
|
|
2321
|
+
this.getUserAccount().maxMarginRatio
|
|
2294
2322
|
);
|
|
2295
2323
|
freeCollateral = freeCollateral.add(
|
|
2296
2324
|
tradeAmount.mul(new BN(marginRatio)).div(MARGIN_PRECISION)
|
|
@@ -2384,7 +2412,7 @@ export class User {
|
|
|
2384
2412
|
);
|
|
2385
2413
|
|
|
2386
2414
|
const { perpLiabilityValue, perpPnl, spotAssetValue, spotLiabilityValue } =
|
|
2387
|
-
this.getLeverageComponents();
|
|
2415
|
+
this.getLeverageComponents(undefined, 'Initial');
|
|
2388
2416
|
|
|
2389
2417
|
if (!calculateSwap) {
|
|
2390
2418
|
calculateSwap = (inSwap: BN) => {
|
|
@@ -2583,7 +2611,8 @@ export class User {
|
|
|
2583
2611
|
spotPosition,
|
|
2584
2612
|
spotMarketAccount,
|
|
2585
2613
|
strictOraclePrice,
|
|
2586
|
-
marginCategory
|
|
2614
|
+
marginCategory,
|
|
2615
|
+
this.getUserAccount().maxMarginRatio
|
|
2587
2616
|
);
|
|
2588
2617
|
|
|
2589
2618
|
return freeCollateralContribution;
|
|
@@ -2606,7 +2635,8 @@ export class User {
|
|
|
2606
2635
|
spotPosition,
|
|
2607
2636
|
spotMarketAccount,
|
|
2608
2637
|
strictOraclePrice,
|
|
2609
|
-
'Initial'
|
|
2638
|
+
'Initial',
|
|
2639
|
+
this.getUserAccount().maxMarginRatio
|
|
2610
2640
|
);
|
|
2611
2641
|
|
|
2612
2642
|
if (tokenValue.gte(ZERO)) {
|
|
@@ -2678,7 +2708,7 @@ export class User {
|
|
|
2678
2708
|
);
|
|
2679
2709
|
|
|
2680
2710
|
const { perpLiabilityValue, perpPnl, spotAssetValue, spotLiabilityValue } =
|
|
2681
|
-
this.getLeverageComponents();
|
|
2711
|
+
this.getLeverageComponents(undefined, 'Initial');
|
|
2682
2712
|
|
|
2683
2713
|
const inPositionAfter = this.cloneAndUpdateSpotPosition(
|
|
2684
2714
|
inSpotPosition,
|
|
@@ -3225,7 +3255,8 @@ export class User {
|
|
|
3225
3255
|
calculateMarketMarginRatio(
|
|
3226
3256
|
perpMarket,
|
|
3227
3257
|
worstCaseBaseAmount.abs(),
|
|
3228
|
-
marginCategory
|
|
3258
|
+
marginCategory,
|
|
3259
|
+
this.getUserAccount().maxMarginRatio
|
|
3229
3260
|
)
|
|
3230
3261
|
);
|
|
3231
3262
|
|
|
@@ -3349,7 +3380,8 @@ export class User {
|
|
|
3349
3380
|
spotPosition,
|
|
3350
3381
|
spotMarketAccount,
|
|
3351
3382
|
strictOraclePrice,
|
|
3352
|
-
marginCategory
|
|
3383
|
+
marginCategory,
|
|
3384
|
+
this.getUserAccount().maxMarginRatio
|
|
3353
3385
|
);
|
|
3354
3386
|
|
|
3355
3387
|
netQuoteValue = netQuoteValue.add(ordersValue);
|
|
@@ -3393,7 +3425,8 @@ export class User {
|
|
|
3393
3425
|
baseAssetValue,
|
|
3394
3426
|
oraclePriceData.price,
|
|
3395
3427
|
spotMarketAccount,
|
|
3396
|
-
marginCategory
|
|
3428
|
+
marginCategory,
|
|
3429
|
+
this.getUserAccount().maxMarginRatio
|
|
3397
3430
|
);
|
|
3398
3431
|
|
|
3399
3432
|
if (netQuoteValue.lt(ZERO)) {
|
package/tests/amm/test.ts
CHANGED
|
@@ -568,7 +568,8 @@ describe('AMM Tests', () => {
|
|
|
568
568
|
mockMarket1.amm.maxBaseAssetReserve = mockMarket1.amm.baseAssetReserve.add(
|
|
569
569
|
new BN(1234835)
|
|
570
570
|
);
|
|
571
|
-
mockMarket1.amm.minBaseAssetReserve =
|
|
571
|
+
mockMarket1.amm.minBaseAssetReserve =
|
|
572
|
+
mockMarket1.amm.baseAssetReserve.sub(BASE_PRECISION);
|
|
572
573
|
mockMarket1.amm.quoteAssetReserve = new BN(cc).mul(BASE_PRECISION);
|
|
573
574
|
mockMarket1.amm.pegMultiplier = new BN(18.32 * PEG_PRECISION.toNumber());
|
|
574
575
|
mockMarket1.amm.sqrtK = new BN(cc).mul(BASE_PRECISION);
|
|
@@ -790,14 +791,14 @@ describe('AMM Tests', () => {
|
|
|
790
791
|
assert(totalAskSize.sub(openAsks.abs()).lte(new BN(5))); // only tiny rounding errors
|
|
791
792
|
});
|
|
792
793
|
|
|
793
|
-
|
|
794
794
|
it('orderbook L2 gen (4 topOfBookQuoteAmounts, 10 numOrders, low bid liquidity)', async () => {
|
|
795
795
|
const myMockPerpMarkets = _.cloneDeep(mockPerpMarkets);
|
|
796
796
|
|
|
797
797
|
const mockMarket1: PerpMarketAccount = myMockPerpMarkets[0];
|
|
798
798
|
const cc = 38104569;
|
|
799
799
|
mockMarket1.amm.baseAssetReserve = new BN(cc).mul(BASE_PRECISION);
|
|
800
|
-
mockMarket1.amm.maxBaseAssetReserve =
|
|
800
|
+
mockMarket1.amm.maxBaseAssetReserve =
|
|
801
|
+
mockMarket1.amm.baseAssetReserve.add(BASE_PRECISION); // only 1 base
|
|
801
802
|
mockMarket1.amm.minBaseAssetReserve = mockMarket1.amm.baseAssetReserve.div(
|
|
802
803
|
new BN(2)
|
|
803
804
|
);
|
|
@@ -873,14 +874,15 @@ describe('AMM Tests', () => {
|
|
|
873
874
|
assert(totalAskSize.sub(openAsks.abs()).lte(new BN(5))); // only tiny rounding errors
|
|
874
875
|
});
|
|
875
876
|
|
|
876
|
-
|
|
877
877
|
it('orderbook L2 gen (4 topOfBookQuoteAmounts, 10 numOrders, low ask liquidity)', async () => {
|
|
878
878
|
const myMockPerpMarkets = _.cloneDeep(mockPerpMarkets);
|
|
879
879
|
|
|
880
880
|
const mockMarket1: PerpMarketAccount = myMockPerpMarkets[0];
|
|
881
881
|
const cc = 38104569;
|
|
882
882
|
mockMarket1.amm.baseAssetReserve = new BN(cc).mul(BASE_PRECISION);
|
|
883
|
-
mockMarket1.amm.maxBaseAssetReserve = mockMarket1.amm.baseAssetReserve.add(
|
|
883
|
+
mockMarket1.amm.maxBaseAssetReserve = mockMarket1.amm.baseAssetReserve.add(
|
|
884
|
+
BASE_PRECISION.mul(new BN(1000))
|
|
885
|
+
); // 1000 base
|
|
884
886
|
mockMarket1.amm.minBaseAssetReserve = mockMarket1.amm.baseAssetReserve.sub(
|
|
885
887
|
BASE_PRECISION.div(new BN(2))
|
|
886
888
|
); // only .5 base
|
package/tests/auctions/test.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {PRICE_PRECISION, BN, deriveOracleAuctionParams} from
|
|
2
|
-
import {assert} from
|
|
3
|
-
import {PositionDirection} from
|
|
1
|
+
import { PRICE_PRECISION, BN, deriveOracleAuctionParams } from '../../src';
|
|
2
|
+
import { assert } from 'chai';
|
|
3
|
+
import { PositionDirection } from '../../lib';
|
|
4
4
|
|
|
5
5
|
describe('Auction Tests', () => {
|
|
6
|
-
|
|
7
6
|
it('deriveOracleAuctionParams', async () => {
|
|
8
7
|
let oraclePrice = new BN(100).mul(PRICE_PRECISION);
|
|
9
8
|
let auctionStartPrice = new BN(90).mul(PRICE_PRECISION);
|
|
@@ -18,9 +17,15 @@ describe('Auction Tests', () => {
|
|
|
18
17
|
limitPrice,
|
|
19
18
|
});
|
|
20
19
|
|
|
21
|
-
assert(
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
assert(
|
|
21
|
+
oracleOrderParams.auctionStartPrice.eq(new BN(-10).mul(PRICE_PRECISION))
|
|
22
|
+
);
|
|
23
|
+
assert(
|
|
24
|
+
oracleOrderParams.auctionEndPrice.eq(new BN(10).mul(PRICE_PRECISION))
|
|
25
|
+
);
|
|
26
|
+
assert(
|
|
27
|
+
oracleOrderParams.oraclePriceOffset === 20 * PRICE_PRECISION.toNumber()
|
|
28
|
+
);
|
|
24
29
|
|
|
25
30
|
oracleOrderParams = deriveOracleAuctionParams({
|
|
26
31
|
direction: PositionDirection.LONG,
|
|
@@ -47,9 +52,15 @@ describe('Auction Tests', () => {
|
|
|
47
52
|
limitPrice,
|
|
48
53
|
});
|
|
49
54
|
|
|
50
|
-
assert(
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
assert(
|
|
56
|
+
oracleOrderParams.auctionStartPrice.eq(new BN(10).mul(PRICE_PRECISION))
|
|
57
|
+
);
|
|
58
|
+
assert(
|
|
59
|
+
oracleOrderParams.auctionEndPrice.eq(new BN(-10).mul(PRICE_PRECISION))
|
|
60
|
+
);
|
|
61
|
+
assert(
|
|
62
|
+
oracleOrderParams.oraclePriceOffset === -20 * PRICE_PRECISION.toNumber()
|
|
63
|
+
);
|
|
53
64
|
|
|
54
65
|
oracleOrderParams = deriveOracleAuctionParams({
|
|
55
66
|
direction: PositionDirection.SHORT,
|
|
@@ -63,4 +74,4 @@ describe('Auction Tests', () => {
|
|
|
63
74
|
assert(oracleOrderParams.auctionEndPrice.eq(new BN(0)));
|
|
64
75
|
assert(oracleOrderParams.oraclePriceOffset === -1);
|
|
65
76
|
});
|
|
66
|
-
});
|
|
77
|
+
});
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
OrderRecord,
|
|
22
22
|
ZERO,
|
|
23
23
|
ContractTier,
|
|
24
|
-
SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION
|
|
24
|
+
SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION,
|
|
25
|
+
SPOT_MARKET_WEIGHT_PRECISION,
|
|
26
|
+
PRICE_PRECISION,
|
|
25
27
|
} from '../../src';
|
|
26
28
|
|
|
27
29
|
export const mockPerpPosition: PerpPosition = {
|
|
@@ -263,7 +265,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
263
265
|
status: MarketStatus.ACTIVE,
|
|
264
266
|
assetTier: AssetTier.COLLATERAL,
|
|
265
267
|
name: [],
|
|
266
|
-
maxTokenDeposits: new BN(1000000),
|
|
268
|
+
maxTokenDeposits: new BN(1000000 * QUOTE_PRECISION.toNumber()),
|
|
267
269
|
marketIndex: 0,
|
|
268
270
|
pubkey: PublicKey.default,
|
|
269
271
|
mint: DevnetSpotMarkets[0].mint,
|
|
@@ -300,10 +302,10 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
300
302
|
lastInterestTs: new BN(0),
|
|
301
303
|
lastTwapTs: new BN(0),
|
|
302
304
|
oracle: PublicKey.default,
|
|
303
|
-
initialAssetWeight:
|
|
304
|
-
maintenanceAssetWeight:
|
|
305
|
-
initialLiabilityWeight:
|
|
306
|
-
maintenanceLiabilityWeight:
|
|
305
|
+
initialAssetWeight: SPOT_MARKET_WEIGHT_PRECISION.toNumber(),
|
|
306
|
+
maintenanceAssetWeight: SPOT_MARKET_WEIGHT_PRECISION.toNumber(),
|
|
307
|
+
initialLiabilityWeight: SPOT_MARKET_WEIGHT_PRECISION.toNumber(),
|
|
308
|
+
maintenanceLiabilityWeight: SPOT_MARKET_WEIGHT_PRECISION.toNumber(),
|
|
307
309
|
scaleInitialAssetWeightStart: new BN(0),
|
|
308
310
|
imfFactor: 0,
|
|
309
311
|
withdrawGuardThreshold: new BN(0),
|
|
@@ -325,18 +327,18 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
325
327
|
flashLoanInitialTokenAmount: new BN(0),
|
|
326
328
|
oracleSource: OracleSource.PYTH,
|
|
327
329
|
historicalOracleData: {
|
|
328
|
-
lastOraclePrice:
|
|
330
|
+
lastOraclePrice: PRICE_PRECISION,
|
|
329
331
|
lastOracleConf: new BN(0),
|
|
330
332
|
lastOracleDelay: new BN(0),
|
|
331
|
-
lastOraclePriceTwap:
|
|
332
|
-
lastOraclePriceTwap5Min:
|
|
333
|
+
lastOraclePriceTwap: PRICE_PRECISION,
|
|
334
|
+
lastOraclePriceTwap5Min: PRICE_PRECISION,
|
|
333
335
|
lastOraclePriceTwapTs: new BN(0),
|
|
334
336
|
},
|
|
335
337
|
historicalIndexData: {
|
|
336
|
-
lastIndexBidPrice:
|
|
337
|
-
lastIndexAskPrice:
|
|
338
|
-
lastIndexPriceTwap:
|
|
339
|
-
lastIndexPriceTwap5Min:
|
|
338
|
+
lastIndexBidPrice: PRICE_PRECISION,
|
|
339
|
+
lastIndexAskPrice: PRICE_PRECISION,
|
|
340
|
+
lastIndexPriceTwap: PRICE_PRECISION,
|
|
341
|
+
lastIndexPriceTwap5Min: PRICE_PRECISION,
|
|
340
342
|
lastIndexPriceTwapTs: new BN(0),
|
|
341
343
|
},
|
|
342
344
|
},
|