@velocity-exchange/sdk 0.2.0 → 0.2.2
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/CHANGELOG.md +7 -44
- package/lib/browser/adminClient.d.ts +0 -1
- package/lib/browser/bankrun/bankrunConnection.d.ts +2 -1
- package/lib/browser/bankrun/bankrunConnection.js +23 -1
- package/lib/browser/constants/numericConstants.d.ts +2 -1
- package/lib/browser/constants/numericConstants.js +8 -4
- package/lib/browser/constants/spotMarkets.d.ts +0 -1
- package/lib/browser/core/VelocityCore.d.ts +0 -1
- package/lib/browser/core/instructions/deposit.d.ts +0 -1
- package/lib/browser/core/instructions/withdraw.d.ts +0 -1
- package/lib/browser/dlob/DLOB.d.ts +0 -1
- package/lib/browser/dlob/DLOBNode.d.ts +0 -1
- package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -1
- package/lib/browser/dlob/NodeList.d.ts +0 -1
- package/lib/browser/dlob/orderBookLevels.d.ts +0 -1
- package/lib/browser/events/eventList.d.ts +3 -3
- package/lib/browser/events/eventsServerLogProvider.d.ts +1 -1
- package/lib/browser/events/pollingLogProvider.d.ts +1 -1
- package/lib/browser/events/txEventCache.d.ts +3 -3
- package/lib/browser/events/webSocketLogProvider.d.ts +1 -1
- package/lib/browser/factory/bigNum.d.ts +0 -1
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
- package/lib/browser/jupiter/jupiterClient.d.ts +0 -1
- package/lib/browser/marginCalculation.d.ts +0 -1
- package/lib/browser/marinade/index.d.ts +2 -3
- package/lib/browser/marinade/index.js +5 -0
- package/lib/browser/math/amm.d.ts +0 -1
- package/lib/browser/math/auction.d.ts +0 -1
- package/lib/browser/math/conversion.d.ts +0 -1
- package/lib/browser/math/funding.d.ts +0 -1
- package/lib/browser/math/insurance.d.ts +0 -1
- package/lib/browser/math/liquidation.d.ts +0 -1
- package/lib/browser/math/margin.d.ts +0 -1
- package/lib/browser/math/market.d.ts +0 -1
- package/lib/browser/math/oracles.d.ts +0 -1
- package/lib/browser/math/orders.d.ts +0 -1
- package/lib/browser/math/position.d.ts +1 -2
- package/lib/browser/math/repeg.d.ts +0 -1
- package/lib/browser/math/spotBalance.d.ts +0 -1
- package/lib/browser/math/spotMarket.d.ts +0 -1
- package/lib/browser/math/spotPosition.d.ts +0 -1
- package/lib/browser/math/state.d.ts +0 -1
- package/lib/browser/math/superStake.d.ts +0 -1
- package/lib/browser/math/trade.d.ts +2 -3
- package/lib/browser/math/utils.d.ts +0 -1
- package/lib/browser/oracles/oracleClientCache.d.ts +1 -1
- package/lib/browser/oracles/pythClient.d.ts +0 -1
- package/lib/browser/oracles/pythLazerClient.d.ts +0 -1
- package/lib/browser/oracles/strictOraclePrice.d.ts +0 -1
- package/lib/browser/oracles/types.d.ts +0 -1
- package/lib/browser/oracles/utils.d.ts +0 -1
- package/lib/browser/orderParams.d.ts +0 -1
- package/lib/browser/swap/UnifiedSwapClient.d.ts +0 -1
- package/lib/browser/titan/titanClient.d.ts +0 -1
- package/lib/browser/tokenFaucet.d.ts +0 -1
- package/lib/browser/tx/txHandler.d.ts +2 -2
- package/lib/browser/types.d.ts +2 -3
- package/lib/browser/user.d.ts +0 -1
- package/lib/browser/velocityClient.d.ts +1 -2
- package/lib/node/adminClient.d.ts +0 -1
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.d.ts +2 -1
- package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.js +23 -1
- package/lib/node/constants/numericConstants.d.ts +2 -1
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +8 -4
- package/lib/node/constants/spotMarkets.d.ts +0 -1
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.d.ts +0 -1
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/instructions/deposit.d.ts +0 -1
- package/lib/node/core/instructions/deposit.d.ts.map +1 -1
- package/lib/node/core/instructions/withdraw.d.ts +0 -1
- package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.d.ts +0 -1
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOBNode.d.ts +0 -1
- package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts +0 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/NodeList.d.ts +0 -1
- package/lib/node/dlob/NodeList.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.d.ts +0 -1
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/factory/bigNum.d.ts +0 -1
- package/lib/node/factory/bigNum.d.ts.map +1 -1
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts.map +1 -1
- package/lib/node/jupiter/jupiterClient.d.ts +0 -1
- package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
- package/lib/node/marginCalculation.d.ts +0 -1
- package/lib/node/marginCalculation.d.ts.map +1 -1
- package/lib/node/marinade/index.d.ts +2 -3
- package/lib/node/marinade/index.d.ts.map +1 -1
- package/lib/node/marinade/index.js +5 -0
- package/lib/node/math/amm.d.ts +0 -1
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/auction.d.ts +0 -1
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/conversion.d.ts +0 -1
- package/lib/node/math/conversion.d.ts.map +1 -1
- package/lib/node/math/funding.d.ts +0 -1
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/insurance.d.ts +0 -1
- package/lib/node/math/insurance.d.ts.map +1 -1
- package/lib/node/math/liquidation.d.ts +0 -1
- package/lib/node/math/liquidation.d.ts.map +1 -1
- package/lib/node/math/margin.d.ts +0 -1
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/market.d.ts +0 -1
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/oracles.d.ts +0 -1
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/orders.d.ts +0 -1
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/position.d.ts +0 -1
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/repeg.d.ts +0 -1
- package/lib/node/math/repeg.d.ts.map +1 -1
- package/lib/node/math/spotBalance.d.ts +0 -1
- package/lib/node/math/spotBalance.d.ts.map +1 -1
- package/lib/node/math/spotMarket.d.ts +0 -1
- package/lib/node/math/spotMarket.d.ts.map +1 -1
- package/lib/node/math/spotPosition.d.ts +0 -1
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/state.d.ts +0 -1
- package/lib/node/math/state.d.ts.map +1 -1
- package/lib/node/math/superStake.d.ts +0 -1
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/trade.d.ts +0 -1
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/utils.d.ts +0 -1
- package/lib/node/math/utils.d.ts.map +1 -1
- package/lib/node/oracles/pythClient.d.ts +0 -1
- package/lib/node/oracles/pythClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.d.ts +0 -1
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/strictOraclePrice.d.ts +0 -1
- package/lib/node/oracles/strictOraclePrice.d.ts.map +1 -1
- package/lib/node/oracles/types.d.ts +0 -1
- package/lib/node/oracles/types.d.ts.map +1 -1
- package/lib/node/oracles/utils.d.ts +0 -1
- package/lib/node/oracles/utils.d.ts.map +1 -1
- package/lib/node/orderParams.d.ts +0 -1
- package/lib/node/orderParams.d.ts.map +1 -1
- package/lib/node/swap/UnifiedSwapClient.d.ts +0 -1
- package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
- package/lib/node/titan/titanClient.d.ts +0 -1
- package/lib/node/titan/titanClient.d.ts.map +1 -1
- package/lib/node/tokenFaucet.d.ts +0 -1
- package/lib/node/tokenFaucet.d.ts.map +1 -1
- package/lib/node/types.d.ts +0 -1
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +0 -1
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/velocityClient.d.ts +0 -1
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/package.json +16 -11
- package/src/bankrun/bankrunConnection.ts +27 -1
- package/src/constants/numericConstants.ts +6 -2
- package/src/index.ts +5 -1
- package/src/marinade/index.ts +11 -2
- package/src/userMap/referrerMap.ts +1 -1
- package/src/userMap/revenueShareEscrowMap.ts +2 -2
- package/tests/VelocityCore/remainingAccounts.test.ts +4 -5
- package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +19 -11
- package/tests/amm/test.ts +162 -95
- package/tests/decode/userAccountBufferStrings.ts +100 -100
- package/tests/dlob/helpers.ts +156 -172
- package/tests/dlob/test.ts +155 -106
- package/tests/tx/TransactionConfirmationManager.test.ts +9 -2
- package/tests/user/getMarginCalculation.ts +1 -1
- package/tests/user/helpers.ts +3 -4
- package/tests/user/marginCalculations.test.ts +2 -2
- package/tests/user/test.ts +3 -3
- package/tsconfig.browser.json +3 -1
- package/tsconfig.json +20 -2
- package/.yarn/install-state.gz +0 -0
- package/VERSION +0 -1
- package/bun.lock +0 -1907
- package/scripts/updateVersion.js +0 -28
- package/tests/decode/phoenix.ts +0 -71
package/tests/dlob/test.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
NodeToFill,
|
|
18
18
|
isOrderExpired,
|
|
19
19
|
Order,
|
|
20
|
+
MMOraclePriceData,
|
|
20
21
|
isMarketOrder,
|
|
21
22
|
isLimitOrder,
|
|
22
23
|
ZERO,
|
|
@@ -81,7 +82,6 @@ function insertOrderToDLOB(
|
|
|
81
82
|
baseAssetAmount,
|
|
82
83
|
baseAssetAmountFilled: new BN(0),
|
|
83
84
|
quoteAssetAmountFilled: new BN(0),
|
|
84
|
-
quoteAssetAmount: new BN(0),
|
|
85
85
|
direction,
|
|
86
86
|
reduceOnly: false,
|
|
87
87
|
triggerPrice: new BN(0),
|
|
@@ -99,7 +99,6 @@ function insertOrderToDLOB(
|
|
|
99
99
|
},
|
|
100
100
|
userAccount.toString(),
|
|
101
101
|
slot.toNumber(),
|
|
102
|
-
false,
|
|
103
102
|
baseAssetAmount
|
|
104
103
|
);
|
|
105
104
|
}
|
|
@@ -136,7 +135,6 @@ function insertTriggerOrderToDLOB(
|
|
|
136
135
|
baseAssetAmount,
|
|
137
136
|
baseAssetAmountFilled: new BN(0),
|
|
138
137
|
quoteAssetAmountFilled: new BN(0),
|
|
139
|
-
quoteAssetAmount: new BN(0),
|
|
140
138
|
direction,
|
|
141
139
|
reduceOnly: false,
|
|
142
140
|
triggerPrice,
|
|
@@ -154,7 +152,6 @@ function insertTriggerOrderToDLOB(
|
|
|
154
152
|
},
|
|
155
153
|
userAccount.toString(),
|
|
156
154
|
slot.toNumber(),
|
|
157
|
-
false,
|
|
158
155
|
baseAssetAmount
|
|
159
156
|
);
|
|
160
157
|
}
|
|
@@ -185,7 +182,7 @@ function printBookState(
|
|
|
185
182
|
vBid: BN | undefined,
|
|
186
183
|
vAsk: BN | undefined,
|
|
187
184
|
slot: number,
|
|
188
|
-
oracle:
|
|
185
|
+
oracle: MMOraclePriceData
|
|
189
186
|
) {
|
|
190
187
|
const askNodes = dlob.getAsks(
|
|
191
188
|
marketIndex,
|
|
@@ -279,6 +276,7 @@ describe('DLOB Tests', () => {
|
|
|
279
276
|
slot: new BN(slot),
|
|
280
277
|
confidence: new BN(1),
|
|
281
278
|
hasSufficientNumberOfDataPoints: true,
|
|
279
|
+
isMMOracleActive: true,
|
|
282
280
|
};
|
|
283
281
|
|
|
284
282
|
// check perps
|
|
@@ -293,7 +291,7 @@ describe('DLOB Tests', () => {
|
|
|
293
291
|
)) {
|
|
294
292
|
foundAsks++;
|
|
295
293
|
}
|
|
296
|
-
expect(foundAsks).to.equal(
|
|
294
|
+
expect(foundAsks).to.equal(0);
|
|
297
295
|
|
|
298
296
|
let foundBids = 0;
|
|
299
297
|
for (const _bid of dlob.getBids(
|
|
@@ -305,7 +303,7 @@ describe('DLOB Tests', () => {
|
|
|
305
303
|
)) {
|
|
306
304
|
foundBids++;
|
|
307
305
|
}
|
|
308
|
-
expect(foundBids).to.equal(
|
|
306
|
+
expect(foundBids).to.equal(0);
|
|
309
307
|
}
|
|
310
308
|
|
|
311
309
|
// check spots
|
|
@@ -352,6 +350,7 @@ describe('DLOB Tests', () => {
|
|
|
352
350
|
slot: new BN(slot),
|
|
353
351
|
confidence: new BN(1),
|
|
354
352
|
hasSufficientNumberOfDataPoints: true,
|
|
353
|
+
isMMOracleActive: true,
|
|
355
354
|
};
|
|
356
355
|
|
|
357
356
|
insertOrderToDLOB(
|
|
@@ -430,6 +429,7 @@ describe('DLOB Tests', () => {
|
|
|
430
429
|
slot: new BN(slot),
|
|
431
430
|
confidence: new BN(1),
|
|
432
431
|
hasSufficientNumberOfDataPoints: true,
|
|
432
|
+
isMMOracleActive: true,
|
|
433
433
|
};
|
|
434
434
|
|
|
435
435
|
const user0 = Keypair.generate();
|
|
@@ -560,6 +560,7 @@ describe('DLOB Tests', () => {
|
|
|
560
560
|
slot: new BN(slot),
|
|
561
561
|
confidence: new BN(1),
|
|
562
562
|
hasSufficientNumberOfDataPoints: true,
|
|
563
|
+
isMMOracleActive: true,
|
|
563
564
|
};
|
|
564
565
|
|
|
565
566
|
const user0 = Keypair.generate();
|
|
@@ -694,6 +695,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
694
695
|
slot: new BN(slot),
|
|
695
696
|
confidence: new BN(1),
|
|
696
697
|
hasSufficientNumberOfDataPoints: true,
|
|
698
|
+
isMMOracleActive: true,
|
|
697
699
|
};
|
|
698
700
|
const testCases = [
|
|
699
701
|
{
|
|
@@ -815,26 +817,29 @@ describe('DLOB Perp Tests', () => {
|
|
|
815
817
|
MarketType.PERP,
|
|
816
818
|
oracle
|
|
817
819
|
);
|
|
820
|
+
// vAMM was decoupled from the DLOB: getBids no longer synthesizes a vAMM
|
|
821
|
+
// node, so the expected sequence is the real orders only.
|
|
822
|
+
const expectedRealBids = expectedTestCase.filter((t) => !t.isVamm);
|
|
818
823
|
let countBids = 0;
|
|
819
824
|
for (const bid of allBids) {
|
|
820
825
|
expect(bid.isVammNode(), `expected vAMM node`).to.be.eq(
|
|
821
|
-
|
|
826
|
+
expectedRealBids[countBids].isVamm
|
|
822
827
|
);
|
|
823
828
|
expect(bid.order?.orderId, `expected orderId`).to.equal(
|
|
824
|
-
|
|
829
|
+
expectedRealBids[countBids].orderId
|
|
825
830
|
);
|
|
826
831
|
expect(bid.order?.price.toNumber(), `expected price`).to.equal(
|
|
827
|
-
|
|
832
|
+
expectedRealBids[countBids].price?.toNumber()
|
|
828
833
|
);
|
|
829
834
|
expect(bid.order?.direction, `expected order direction`).to.equal(
|
|
830
|
-
|
|
835
|
+
expectedRealBids[countBids].direction
|
|
831
836
|
);
|
|
832
837
|
expect(bid.order?.orderType, `expected order type`).to.equal(
|
|
833
|
-
|
|
838
|
+
expectedRealBids[countBids].orderType
|
|
834
839
|
);
|
|
835
840
|
countBids++;
|
|
836
841
|
}
|
|
837
|
-
expect(countBids).to.equal(
|
|
842
|
+
expect(countBids).to.equal(expectedRealBids.length);
|
|
838
843
|
|
|
839
844
|
const takingBids = dlob.getTakingBids(
|
|
840
845
|
marketIndex,
|
|
@@ -909,6 +914,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
909
914
|
slot: new BN(slot),
|
|
910
915
|
confidence: new BN(1),
|
|
911
916
|
hasSufficientNumberOfDataPoints: true,
|
|
917
|
+
isMMOracleActive: true,
|
|
912
918
|
};
|
|
913
919
|
const testCases = [
|
|
914
920
|
{
|
|
@@ -1017,7 +1023,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
1017
1023
|
);
|
|
1018
1024
|
countBids0++;
|
|
1019
1025
|
}
|
|
1020
|
-
|
|
1026
|
+
// vAMM decoupled from DLOB: only the 5 real market0 bids remain (no vAMM node).
|
|
1027
|
+
expect(countBids0).to.equal(5);
|
|
1021
1028
|
|
|
1022
1029
|
const bids1 = dlob.getBids(
|
|
1023
1030
|
marketIndex1,
|
|
@@ -1039,7 +1046,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
1039
1046
|
|
|
1040
1047
|
countBids1++;
|
|
1041
1048
|
}
|
|
1042
|
-
|
|
1049
|
+
// vAMM decoupled from DLOB: only the 2 real market1 bids remain (no vAMM node).
|
|
1050
|
+
expect(countBids1).to.equal(2);
|
|
1043
1051
|
});
|
|
1044
1052
|
|
|
1045
1053
|
it('Test proper asks', () => {
|
|
@@ -1054,6 +1062,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1054
1062
|
slot: new BN(slot),
|
|
1055
1063
|
confidence: new BN(1),
|
|
1056
1064
|
hasSufficientNumberOfDataPoints: true,
|
|
1065
|
+
isMMOracleActive: true,
|
|
1057
1066
|
};
|
|
1058
1067
|
const testCases = [
|
|
1059
1068
|
{
|
|
@@ -1170,22 +1179,33 @@ describe('DLOB Perp Tests', () => {
|
|
|
1170
1179
|
});
|
|
1171
1180
|
|
|
1172
1181
|
const asks = dlob.getAsks(marketIndex, vAsk, slot, MarketType.PERP, oracle);
|
|
1182
|
+
// vAMM was decoupled from the DLOB: getAsks no longer synthesizes a vAMM
|
|
1183
|
+
// node. With the vAMM generator gone from the k-way merge, the real
|
|
1184
|
+
// orders surface in this order (taking market orders merged with resting
|
|
1185
|
+
// limit orders by price): 3, 4, 2, 5, 1, 6, 7.
|
|
1186
|
+
const expectedRealAsks = [
|
|
1187
|
+
{ orderId: 3, price: 0, orderType: OrderType.MARKET },
|
|
1188
|
+
{ orderId: 4, price: 0, orderType: OrderType.MARKET },
|
|
1189
|
+
{ orderId: 2, price: 14, orderType: OrderType.LIMIT },
|
|
1190
|
+
{ orderId: 5, price: 0, orderType: OrderType.MARKET },
|
|
1191
|
+
{ orderId: 1, price: 13, orderType: OrderType.LIMIT },
|
|
1192
|
+
{ orderId: 6, price: 16, orderType: OrderType.LIMIT },
|
|
1193
|
+
{ orderId: 7, price: 17, orderType: OrderType.LIMIT },
|
|
1194
|
+
];
|
|
1173
1195
|
let countAsks = 0;
|
|
1174
1196
|
for (const ask of asks) {
|
|
1175
|
-
expect(ask.isVammNode()).to.be.eq(
|
|
1176
|
-
expect(ask.order?.orderId).to.equal(
|
|
1197
|
+
expect(ask.isVammNode()).to.be.eq(false);
|
|
1198
|
+
expect(ask.order?.orderId).to.equal(expectedRealAsks[countAsks].orderId);
|
|
1177
1199
|
expect(ask.order?.price.toNumber()).to.equal(
|
|
1178
|
-
|
|
1179
|
-
);
|
|
1180
|
-
expect(ask.order?.direction).to.equal(
|
|
1181
|
-
expectedTestCase[countAsks].direction
|
|
1200
|
+
expectedRealAsks[countAsks].price
|
|
1182
1201
|
);
|
|
1202
|
+
expect(ask.order?.direction).to.equal(PositionDirection.SHORT);
|
|
1183
1203
|
expect(ask.order?.orderType).to.equal(
|
|
1184
|
-
|
|
1204
|
+
expectedRealAsks[countAsks].orderType
|
|
1185
1205
|
);
|
|
1186
1206
|
countAsks++;
|
|
1187
1207
|
}
|
|
1188
|
-
expect(countAsks).to.equal(
|
|
1208
|
+
expect(countAsks).to.equal(expectedRealAsks.length);
|
|
1189
1209
|
|
|
1190
1210
|
const takingAsks = dlob.getTakingAsks(
|
|
1191
1211
|
marketIndex,
|
|
@@ -1255,6 +1275,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1255
1275
|
slot: new BN(12),
|
|
1256
1276
|
confidence: new BN(1),
|
|
1257
1277
|
hasSufficientNumberOfDataPoints: true,
|
|
1278
|
+
isMMOracleActive: true,
|
|
1258
1279
|
};
|
|
1259
1280
|
|
|
1260
1281
|
// 3 mkt buys
|
|
@@ -1314,7 +1335,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1314
1335
|
expect(ask.order?.orderId).to.equal(asks);
|
|
1315
1336
|
}
|
|
1316
1337
|
}
|
|
1317
|
-
expect(asks).to.equal(
|
|
1338
|
+
expect(asks).to.equal(3); // vAMM decoupled from DLOB: 3 market orders, no vAMM ask
|
|
1318
1339
|
|
|
1319
1340
|
let bids = 0;
|
|
1320
1341
|
const expectedBidOrderIds = [1, 2, 3];
|
|
@@ -1335,7 +1356,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1335
1356
|
expect(getVariant(bid.order?.direction)).to.equal('long');
|
|
1336
1357
|
expect(bid.order?.orderId).to.equal(expectedBidOrderIds[bids - 1]);
|
|
1337
1358
|
}
|
|
1338
|
-
expect(bids).to.equal(
|
|
1359
|
+
expect(bids).to.equal(3); // vAMM decoupled from DLOB: 3 market orders, no vAMM bid
|
|
1339
1360
|
});
|
|
1340
1361
|
|
|
1341
1362
|
it('Test insert limit orders', () => {
|
|
@@ -1347,6 +1368,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1347
1368
|
slot: new BN(slot),
|
|
1348
1369
|
confidence: new BN(1),
|
|
1349
1370
|
hasSufficientNumberOfDataPoints: true,
|
|
1371
|
+
isMMOracleActive: true,
|
|
1350
1372
|
};
|
|
1351
1373
|
|
|
1352
1374
|
const user0 = Keypair.generate();
|
|
@@ -1480,20 +1502,15 @@ describe('DLOB Perp Tests', () => {
|
|
|
1480
1502
|
MarketType.PERP,
|
|
1481
1503
|
oracle
|
|
1482
1504
|
)) {
|
|
1483
|
-
|
|
1484
|
-
// market orders
|
|
1485
|
-
console.log(`ask price: ${ask.order.price.toString()}`);
|
|
1486
|
-
expect(getVariant(ask.order?.status)).to.equal('open');
|
|
1487
|
-
expect(getVariant(ask.order?.orderType)).to.equal('limit');
|
|
1488
|
-
expect(getVariant(ask.order?.direction)).to.equal('short');
|
|
1489
|
-
expect(ask.order?.orderId).to.equal(asks);
|
|
1490
|
-
expect(ask.order?.price.gt(vAsk)).to.equal(true);
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
// vamm node is first for limit asks
|
|
1505
|
+
// vAMM decoupled from DLOB: every node is a real limit order now.
|
|
1494
1506
|
asks++;
|
|
1507
|
+
expect(getVariant(ask.order?.status)).to.equal('open');
|
|
1508
|
+
expect(getVariant(ask.order?.orderType)).to.equal('limit');
|
|
1509
|
+
expect(getVariant(ask.order?.direction)).to.equal('short');
|
|
1510
|
+
expect(ask.order?.orderId).to.equal(asks);
|
|
1511
|
+
expect(ask.order?.price.gt(vAsk)).to.equal(true);
|
|
1495
1512
|
}
|
|
1496
|
-
expect(asks).to.equal(
|
|
1513
|
+
expect(asks).to.equal(3); // vAMM decoupled from DLOB: 3 limit orders, no vAMM ask
|
|
1497
1514
|
|
|
1498
1515
|
let bids = 0;
|
|
1499
1516
|
for (const bid of dlob.getBids(
|
|
@@ -1503,21 +1520,15 @@ describe('DLOB Perp Tests', () => {
|
|
|
1503
1520
|
MarketType.PERP,
|
|
1504
1521
|
oracle
|
|
1505
1522
|
)) {
|
|
1506
|
-
|
|
1507
|
-
// vamm node
|
|
1508
|
-
expect(bid.order).to.equal(undefined);
|
|
1509
|
-
} else {
|
|
1510
|
-
// market orders
|
|
1511
|
-
console.log(`bid price: ${bid.order?.price.toString()}`);
|
|
1512
|
-
expect(getVariant(bid.order?.status)).to.equal('open');
|
|
1513
|
-
expect(getVariant(bid.order?.orderType)).to.equal('limit');
|
|
1514
|
-
expect(getVariant(bid.order?.direction)).to.equal('long');
|
|
1515
|
-
expect(bid.order?.orderId).to.equal(bids);
|
|
1516
|
-
expect(bid.order?.price.lt(vBid)).to.equal(true);
|
|
1517
|
-
}
|
|
1523
|
+
// vAMM decoupled from DLOB: every node is a real limit order now.
|
|
1518
1524
|
bids++;
|
|
1525
|
+
expect(getVariant(bid.order?.status)).to.equal('open');
|
|
1526
|
+
expect(getVariant(bid.order?.orderType)).to.equal('limit');
|
|
1527
|
+
expect(getVariant(bid.order?.direction)).to.equal('long');
|
|
1528
|
+
expect(bid.order?.orderId).to.equal(bids);
|
|
1529
|
+
expect(bid.order?.price.lt(vBid)).to.equal(true);
|
|
1519
1530
|
}
|
|
1520
|
-
expect(bids).to.equal(
|
|
1531
|
+
expect(bids).to.equal(3); // vAMM decoupled from DLOB: 3 limit orders, no vAMM bid
|
|
1521
1532
|
});
|
|
1522
1533
|
|
|
1523
1534
|
it('Test insert floatinglimit orders', () => {
|
|
@@ -1529,6 +1540,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1529
1540
|
slot: new BN(slot),
|
|
1530
1541
|
confidence: new BN(1),
|
|
1531
1542
|
hasSufficientNumberOfDataPoints: true,
|
|
1543
|
+
isMMOracleActive: true,
|
|
1532
1544
|
};
|
|
1533
1545
|
|
|
1534
1546
|
const user0 = Keypair.generate();
|
|
@@ -1669,7 +1681,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1669
1681
|
lastBidPrice = bid.getPrice(oracle, slot);
|
|
1670
1682
|
bids++;
|
|
1671
1683
|
}
|
|
1672
|
-
expect(bids).to.equal(
|
|
1684
|
+
expect(bids).to.equal(3); // vAMM decoupled from DLOB: 3 floating bids, no vAMM bid
|
|
1673
1685
|
|
|
1674
1686
|
// check floating asks
|
|
1675
1687
|
console.log(`asks:`);
|
|
@@ -1696,7 +1708,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1696
1708
|
}
|
|
1697
1709
|
asks++;
|
|
1698
1710
|
}
|
|
1699
|
-
expect(asks).to.equal(
|
|
1711
|
+
expect(asks).to.equal(3); // vAMM decoupled from DLOB: 3 floating asks, no vAMM ask
|
|
1700
1712
|
});
|
|
1701
1713
|
|
|
1702
1714
|
it('Test multiple market orders fill with multiple limit orders', async () => {
|
|
@@ -1775,9 +1787,11 @@ describe('DLOB Perp Tests', () => {
|
|
|
1775
1787
|
slot: new BN(12),
|
|
1776
1788
|
confidence: new BN(1),
|
|
1777
1789
|
hasSufficientNumberOfDataPoints: true,
|
|
1790
|
+
isMMOracleActive: true,
|
|
1778
1791
|
},
|
|
1779
1792
|
false,
|
|
1780
|
-
|
|
1793
|
+
mockStateAccount,
|
|
1794
|
+
mockPerpMarkets[marketIndex],
|
|
1781
1795
|
0,
|
|
1782
1796
|
1,
|
|
1783
1797
|
undefined,
|
|
@@ -1825,6 +1839,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1825
1839
|
slot: new BN(12),
|
|
1826
1840
|
confidence: new BN(1),
|
|
1827
1841
|
hasSufficientNumberOfDataPoints: true,
|
|
1842
|
+
isMMOracleActive: true,
|
|
1828
1843
|
},
|
|
1829
1844
|
mockStateAccount,
|
|
1830
1845
|
mockPerpMarkets[marketIndex]
|
|
@@ -1922,9 +1937,11 @@ describe('DLOB Perp Tests', () => {
|
|
|
1922
1937
|
slot: new BN(endSlot),
|
|
1923
1938
|
confidence: new BN(1),
|
|
1924
1939
|
hasSufficientNumberOfDataPoints: true,
|
|
1940
|
+
isMMOracleActive: true,
|
|
1925
1941
|
},
|
|
1926
1942
|
false,
|
|
1927
|
-
|
|
1943
|
+
mockStateAccount,
|
|
1944
|
+
mockPerpMarkets[marketIndex],
|
|
1928
1945
|
0,
|
|
1929
1946
|
1,
|
|
1930
1947
|
undefined,
|
|
@@ -1959,6 +1976,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
1959
1976
|
slot: new BN(endSlot),
|
|
1960
1977
|
confidence: new BN(1),
|
|
1961
1978
|
hasSufficientNumberOfDataPoints: true,
|
|
1979
|
+
isMMOracleActive: true,
|
|
1962
1980
|
},
|
|
1963
1981
|
mockStateAccount,
|
|
1964
1982
|
mockPerpMarkets[marketIndex]
|
|
@@ -2004,6 +2022,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2004
2022
|
slot: new BN(slot),
|
|
2005
2023
|
confidence: new BN(1),
|
|
2006
2024
|
hasSufficientNumberOfDataPoints: true,
|
|
2025
|
+
isMMOracleActive: true,
|
|
2007
2026
|
};
|
|
2008
2027
|
|
|
2009
2028
|
// insert some limit sells below vAMM ask, above bid
|
|
@@ -2176,9 +2195,11 @@ describe('DLOB Perp Tests', () => {
|
|
|
2176
2195
|
slot: new BN(12),
|
|
2177
2196
|
confidence: new BN(1),
|
|
2178
2197
|
hasSufficientNumberOfDataPoints: true,
|
|
2198
|
+
isMMOracleActive: true,
|
|
2179
2199
|
},
|
|
2180
2200
|
false,
|
|
2181
|
-
|
|
2201
|
+
mockStateAccount,
|
|
2202
|
+
mockPerpMarkets[marketIndex],
|
|
2182
2203
|
makerRebateNumerator,
|
|
2183
2204
|
makerRebateDenominator,
|
|
2184
2205
|
vAsk,
|
|
@@ -2218,15 +2239,19 @@ describe('DLOB Perp Tests', () => {
|
|
|
2218
2239
|
slot: new BN(12),
|
|
2219
2240
|
confidence: new BN(1),
|
|
2220
2241
|
hasSufficientNumberOfDataPoints: true,
|
|
2242
|
+
isMMOracleActive: true,
|
|
2221
2243
|
},
|
|
2222
2244
|
false,
|
|
2223
|
-
|
|
2245
|
+
mockStateAccount,
|
|
2246
|
+
mockPerpMarkets[marketIndex],
|
|
2224
2247
|
makerRebateNumerator,
|
|
2225
2248
|
makerRebateDenominator,
|
|
2226
2249
|
vAsk,
|
|
2227
2250
|
vBid
|
|
2228
2251
|
);
|
|
2229
|
-
|
|
2252
|
+
// vAMM/fallback decoupled from the DLOB: a lone post-only bid no longer
|
|
2253
|
+
// fills against fallback liquidity, so no fill nodes are produced.
|
|
2254
|
+
expect(nodesToFillAfter.length).to.equal(0);
|
|
2230
2255
|
});
|
|
2231
2256
|
|
|
2232
2257
|
it('Test post only ask fills against fallback', async () => {
|
|
@@ -2270,9 +2295,11 @@ describe('DLOB Perp Tests', () => {
|
|
|
2270
2295
|
slot: new BN(12),
|
|
2271
2296
|
confidence: new BN(1),
|
|
2272
2297
|
hasSufficientNumberOfDataPoints: true,
|
|
2298
|
+
isMMOracleActive: true,
|
|
2273
2299
|
},
|
|
2274
2300
|
false,
|
|
2275
|
-
|
|
2301
|
+
mockStateAccount,
|
|
2302
|
+
mockPerpMarkets[marketIndex],
|
|
2276
2303
|
makerRebateNumerator,
|
|
2277
2304
|
makerRebateDenominator,
|
|
2278
2305
|
vAsk,
|
|
@@ -2312,15 +2339,19 @@ describe('DLOB Perp Tests', () => {
|
|
|
2312
2339
|
slot: new BN(12),
|
|
2313
2340
|
confidence: new BN(1),
|
|
2314
2341
|
hasSufficientNumberOfDataPoints: true,
|
|
2342
|
+
isMMOracleActive: true,
|
|
2315
2343
|
},
|
|
2316
2344
|
false,
|
|
2317
|
-
|
|
2345
|
+
mockStateAccount,
|
|
2346
|
+
mockPerpMarkets[marketIndex],
|
|
2318
2347
|
makerRebateNumerator,
|
|
2319
2348
|
makerRebateDenominator,
|
|
2320
2349
|
vAsk,
|
|
2321
2350
|
vBid
|
|
2322
2351
|
);
|
|
2323
|
-
|
|
2352
|
+
// vAMM/fallback decoupled from the DLOB: a lone post-only ask no longer
|
|
2353
|
+
// fills against fallback liquidity, so no fill nodes are produced.
|
|
2354
|
+
expect(nodesToFillAfter.length).to.equal(0);
|
|
2324
2355
|
});
|
|
2325
2356
|
|
|
2326
2357
|
it('Test trigger orders', () => {
|
|
@@ -2349,6 +2380,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2349
2380
|
slot: new BN(slot),
|
|
2350
2381
|
confidence: new BN(1),
|
|
2351
2382
|
hasSufficientNumberOfDataPoints: true,
|
|
2383
|
+
isMMOracleActive: true,
|
|
2352
2384
|
};
|
|
2353
2385
|
|
|
2354
2386
|
const orderIdsToTrigger = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
@@ -2622,6 +2654,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2622
2654
|
slot: new BN(slot0),
|
|
2623
2655
|
confidence: new BN(1),
|
|
2624
2656
|
hasSufficientNumberOfDataPoints: true,
|
|
2657
|
+
isMMOracleActive: true,
|
|
2625
2658
|
},
|
|
2626
2659
|
mockStateAccount,
|
|
2627
2660
|
mockPerpMarkets[marketIndex]
|
|
@@ -2643,6 +2676,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2643
2676
|
slot: new BN(slot1),
|
|
2644
2677
|
confidence: new BN(1),
|
|
2645
2678
|
hasSufficientNumberOfDataPoints: true,
|
|
2679
|
+
isMMOracleActive: true,
|
|
2646
2680
|
},
|
|
2647
2681
|
mockStateAccount,
|
|
2648
2682
|
mockPerpMarkets[marketIndex]
|
|
@@ -2678,6 +2712,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2678
2712
|
slot: new BN(slot),
|
|
2679
2713
|
confidence: new BN(1),
|
|
2680
2714
|
hasSufficientNumberOfDataPoints: true,
|
|
2715
|
+
isMMOracleActive: true,
|
|
2681
2716
|
};
|
|
2682
2717
|
|
|
2683
2718
|
// insert some floating limit sells above vAMM ask
|
|
@@ -2749,6 +2784,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2749
2784
|
slot: new BN(slot),
|
|
2750
2785
|
confidence: new BN(1),
|
|
2751
2786
|
hasSufficientNumberOfDataPoints: true,
|
|
2787
|
+
isMMOracleActive: true,
|
|
2752
2788
|
},
|
|
2753
2789
|
mockStateAccount,
|
|
2754
2790
|
mockPerpMarkets[marketIndex]
|
|
@@ -2795,6 +2831,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2795
2831
|
slot: new BN(slot),
|
|
2796
2832
|
confidence: new BN(1),
|
|
2797
2833
|
hasSufficientNumberOfDataPoints: true,
|
|
2834
|
+
isMMOracleActive: true,
|
|
2798
2835
|
},
|
|
2799
2836
|
mockStateAccount,
|
|
2800
2837
|
mockPerpMarkets[marketIndex]
|
|
@@ -2846,6 +2883,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2846
2883
|
slot: new BN(slot),
|
|
2847
2884
|
confidence: new BN(1),
|
|
2848
2885
|
hasSufficientNumberOfDataPoints: true,
|
|
2886
|
+
isMMOracleActive: true,
|
|
2849
2887
|
};
|
|
2850
2888
|
|
|
2851
2889
|
// insert some floating limit sells above vAMM ask
|
|
@@ -2907,7 +2945,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
2907
2945
|
MarketType.PERP,
|
|
2908
2946
|
oracle,
|
|
2909
2947
|
false,
|
|
2910
|
-
|
|
2948
|
+
mockStateAccount,
|
|
2949
|
+
mockPerpMarkets[marketIndex],
|
|
2911
2950
|
0,
|
|
2912
2951
|
1,
|
|
2913
2952
|
undefined,
|
|
@@ -2963,17 +3002,15 @@ describe('DLOB Perp Tests', () => {
|
|
|
2963
3002
|
for (const n of nodesToFillAfter) {
|
|
2964
3003
|
printCrossedNodes(n, auctionOverSlot);
|
|
2965
3004
|
}
|
|
2966
|
-
|
|
3005
|
+
// vAMM decoupled from the DLOB: findNodesToFill no longer matches takers
|
|
3006
|
+
// against vAMM/fallback liquidity. Only the real taker-vs-maker crossing
|
|
3007
|
+
// remains (taker order 4 vs resting limit maker order 1); the second node
|
|
3008
|
+
// that previously filled order 5 against the vAMM is gone.
|
|
3009
|
+
expect(nodesToFillAfter.length).to.equal(1);
|
|
2967
3010
|
|
|
2968
3011
|
// taker should fill completely with best maker
|
|
2969
3012
|
expect(nodesToFillAfter[0].node.order?.orderId).to.equal(4);
|
|
2970
3013
|
expect(nodesToFillAfter[0].makerNodes[0]?.order?.orderId).to.equal(1);
|
|
2971
|
-
|
|
2972
|
-
// taker should fill the rest with the vAMM
|
|
2973
|
-
expect(nodesToFillAfter[1].node.order?.orderId).to.equal(5);
|
|
2974
|
-
expect(nodesToFillAfter[1].makerNodes[0]?.order?.orderId).to.equal(
|
|
2975
|
-
undefined
|
|
2976
|
-
);
|
|
2977
3014
|
});
|
|
2978
3015
|
|
|
2979
3016
|
it('Test skips vAMM and fills market sell order with floating limit buys during auction', () => {
|
|
@@ -2995,6 +3032,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
2995
3032
|
slot: new BN(slot),
|
|
2996
3033
|
confidence: new BN(1),
|
|
2997
3034
|
hasSufficientNumberOfDataPoints: true,
|
|
3035
|
+
isMMOracleActive: true,
|
|
2998
3036
|
};
|
|
2999
3037
|
|
|
3000
3038
|
// insert some floating limit buy below vAMM bid
|
|
@@ -3165,6 +3203,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3165
3203
|
slot: new BN(slot),
|
|
3166
3204
|
confidence: new BN(1),
|
|
3167
3205
|
hasSufficientNumberOfDataPoints: true,
|
|
3206
|
+
isMMOracleActive: true,
|
|
3168
3207
|
};
|
|
3169
3208
|
|
|
3170
3209
|
// insert some floating limit buy below vAMM bid
|
|
@@ -3330,6 +3369,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3330
3369
|
slot: new BN(slot),
|
|
3331
3370
|
confidence: new BN(1),
|
|
3332
3371
|
hasSufficientNumberOfDataPoints: true,
|
|
3372
|
+
isMMOracleActive: true,
|
|
3333
3373
|
};
|
|
3334
3374
|
|
|
3335
3375
|
// insert some floating limit buy below vAMM bid
|
|
@@ -3418,25 +3458,11 @@ describe('DLOB Perp Tests', () => {
|
|
|
3418
3458
|
printCrossedNodes(n, afterAuctionSlot);
|
|
3419
3459
|
}
|
|
3420
3460
|
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
expect(
|
|
3426
|
-
nodesToFillAfter[0].makerNodes[0]?.order?.orderId,
|
|
3427
|
-
'wrong maker orderId'
|
|
3428
|
-
).to.equal(undefined);
|
|
3429
|
-
|
|
3430
|
-
expect(
|
|
3431
|
-
nodesToFillAfter[1].node.order?.orderId,
|
|
3432
|
-
'wrong taker orderId'
|
|
3433
|
-
).to.equal(2);
|
|
3434
|
-
expect(
|
|
3435
|
-
nodesToFillAfter[1].makerNodes[0]?.order?.orderId,
|
|
3436
|
-
'wrong maker orderId'
|
|
3437
|
-
).to.equal(undefined);
|
|
3438
|
-
|
|
3439
|
-
expect(nodesToFillAfter.length).to.equal(2);
|
|
3461
|
+
// vAMM decoupled from the DLOB: the crossing bids previously filled
|
|
3462
|
+
// against vAMM/fallback liquidity (makerNodes[0] === undefined). With the
|
|
3463
|
+
// vAMM gone and no opposing resting asks on the book, findNodesToFill
|
|
3464
|
+
// produces no fill nodes at all.
|
|
3465
|
+
expect(nodesToFillAfter.length).to.equal(0);
|
|
3440
3466
|
});
|
|
3441
3467
|
|
|
3442
3468
|
it('Test fills two limit orders better than vAmm', () => {
|
|
@@ -3456,6 +3482,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3456
3482
|
slot: new BN(slot),
|
|
3457
3483
|
confidence: new BN(1),
|
|
3458
3484
|
hasSufficientNumberOfDataPoints: true,
|
|
3485
|
+
isMMOracleActive: true,
|
|
3459
3486
|
};
|
|
3460
3487
|
|
|
3461
3488
|
// insert a sell below the bid, but above vBid
|
|
@@ -3545,6 +3572,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3545
3572
|
slot: new BN(slot),
|
|
3546
3573
|
confidence: new BN(1),
|
|
3547
3574
|
hasSufficientNumberOfDataPoints: true,
|
|
3575
|
+
isMMOracleActive: true,
|
|
3548
3576
|
};
|
|
3549
3577
|
|
|
3550
3578
|
// resting bid above vBid (better)
|
|
@@ -3637,6 +3665,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3637
3665
|
slot: new BN(slot),
|
|
3638
3666
|
confidence: new BN(1),
|
|
3639
3667
|
hasSufficientNumberOfDataPoints: true,
|
|
3668
|
+
isMMOracleActive: true,
|
|
3640
3669
|
};
|
|
3641
3670
|
|
|
3642
3671
|
// insert a sell that crosses amm bid
|
|
@@ -3722,7 +3751,8 @@ describe('DLOB Perp Tests', () => {
|
|
|
3722
3751
|
MarketType.PERP,
|
|
3723
3752
|
oracle,
|
|
3724
3753
|
false,
|
|
3725
|
-
|
|
3754
|
+
mockStateAccount,
|
|
3755
|
+
mockPerpMarkets[marketIndex],
|
|
3726
3756
|
vAsk,
|
|
3727
3757
|
vBid
|
|
3728
3758
|
);
|
|
@@ -3749,6 +3779,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3749
3779
|
slot: new BN(slot),
|
|
3750
3780
|
confidence: new BN(1),
|
|
3751
3781
|
hasSufficientNumberOfDataPoints: true,
|
|
3782
|
+
isMMOracleActive: true,
|
|
3752
3783
|
};
|
|
3753
3784
|
|
|
3754
3785
|
insertOrderToDLOB(
|
|
@@ -3871,6 +3902,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3871
3902
|
slot: new BN(slot),
|
|
3872
3903
|
confidence: new BN(1),
|
|
3873
3904
|
hasSufficientNumberOfDataPoints: true,
|
|
3905
|
+
isMMOracleActive: true,
|
|
3874
3906
|
};
|
|
3875
3907
|
|
|
3876
3908
|
const users = [
|
|
@@ -3937,7 +3969,6 @@ describe('DLOB Perp Tests', () => {
|
|
|
3937
3969
|
userOrderId: 0,
|
|
3938
3970
|
baseAssetAmountFilled: new BN(0),
|
|
3939
3971
|
quoteAssetAmountFilled: new BN(0),
|
|
3940
|
-
quoteAssetAmount: new BN(0),
|
|
3941
3972
|
reduceOnly: false,
|
|
3942
3973
|
triggerPrice: new BN(0),
|
|
3943
3974
|
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
@@ -3949,8 +3980,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
3949
3980
|
};
|
|
3950
3981
|
dlob.insertSignedMsgOrder(
|
|
3951
3982
|
order,
|
|
3952
|
-
users[orderIndex].publicKey.toString()
|
|
3953
|
-
false
|
|
3983
|
+
users[orderIndex].publicKey.toString()
|
|
3954
3984
|
);
|
|
3955
3985
|
});
|
|
3956
3986
|
});
|
|
@@ -4013,6 +4043,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
4013
4043
|
slot: new BN(slot),
|
|
4014
4044
|
confidence: new BN(1),
|
|
4015
4045
|
hasSufficientNumberOfDataPoints: true,
|
|
4046
|
+
isMMOracleActive: true,
|
|
4016
4047
|
};
|
|
4017
4048
|
|
|
4018
4049
|
const user0 = Keypair.generate();
|
|
@@ -4039,7 +4070,6 @@ describe('DLOB Perp Tests', () => {
|
|
|
4039
4070
|
userOrderId: 0,
|
|
4040
4071
|
baseAssetAmountFilled: new BN(0),
|
|
4041
4072
|
quoteAssetAmountFilled: new BN(0),
|
|
4042
|
-
quoteAssetAmount: new BN(0),
|
|
4043
4073
|
reduceOnly: false,
|
|
4044
4074
|
triggerPrice: new BN(0),
|
|
4045
4075
|
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
@@ -4049,7 +4079,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
4049
4079
|
maxTs: ZERO,
|
|
4050
4080
|
postedSlotTail: 0,
|
|
4051
4081
|
};
|
|
4052
|
-
dlob.insertSignedMsgOrder(limitOrder, user0.publicKey.toString()
|
|
4082
|
+
dlob.insertSignedMsgOrder(limitOrder, user0.publicKey.toString());
|
|
4053
4083
|
|
|
4054
4084
|
// Initially, the order should be in taking orders (auction not complete)
|
|
4055
4085
|
let takingBids = Array.from(
|
|
@@ -4092,6 +4122,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
4092
4122
|
slot: new BN(slot),
|
|
4093
4123
|
confidence: new BN(1),
|
|
4094
4124
|
hasSufficientNumberOfDataPoints: true,
|
|
4125
|
+
isMMOracleActive: true,
|
|
4095
4126
|
};
|
|
4096
4127
|
|
|
4097
4128
|
const user0 = Keypair.generate();
|
|
@@ -4118,7 +4149,6 @@ describe('DLOB Perp Tests', () => {
|
|
|
4118
4149
|
userOrderId: 0,
|
|
4119
4150
|
baseAssetAmountFilled: new BN(0),
|
|
4120
4151
|
quoteAssetAmountFilled: new BN(0),
|
|
4121
|
-
quoteAssetAmount: new BN(0),
|
|
4122
4152
|
reduceOnly: false,
|
|
4123
4153
|
triggerPrice: new BN(0),
|
|
4124
4154
|
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
@@ -4128,7 +4158,7 @@ describe('DLOB Perp Tests', () => {
|
|
|
4128
4158
|
maxTs: ZERO,
|
|
4129
4159
|
postedSlotTail: 0,
|
|
4130
4160
|
};
|
|
4131
|
-
dlob.insertSignedMsgOrder(postOnlyOrder, user0.publicKey.toString()
|
|
4161
|
+
dlob.insertSignedMsgOrder(postOnlyOrder, user0.publicKey.toString());
|
|
4132
4162
|
|
|
4133
4163
|
// PostOnly orders should always be in resting orders, never in taking orders
|
|
4134
4164
|
const takingBids = Array.from(
|
|
@@ -4159,6 +4189,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
4159
4189
|
slot: new BN(slot),
|
|
4160
4190
|
confidence: new BN(1),
|
|
4161
4191
|
hasSufficientNumberOfDataPoints: true,
|
|
4192
|
+
isMMOracleActive: true,
|
|
4162
4193
|
};
|
|
4163
4194
|
const testCases = [
|
|
4164
4195
|
{
|
|
@@ -4294,6 +4325,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
4294
4325
|
slot: new BN(slot),
|
|
4295
4326
|
confidence: new BN(1),
|
|
4296
4327
|
hasSufficientNumberOfDataPoints: true,
|
|
4328
|
+
isMMOracleActive: true,
|
|
4297
4329
|
};
|
|
4298
4330
|
const testCases = [
|
|
4299
4331
|
{
|
|
@@ -4428,6 +4460,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
4428
4460
|
slot: new BN(slot),
|
|
4429
4461
|
confidence: new BN(1),
|
|
4430
4462
|
hasSufficientNumberOfDataPoints: true,
|
|
4463
|
+
isMMOracleActive: true,
|
|
4431
4464
|
};
|
|
4432
4465
|
const testCases = [
|
|
4433
4466
|
{
|
|
@@ -4517,12 +4550,21 @@ describe('DLOB Spot Tests', () => {
|
|
|
4517
4550
|
);
|
|
4518
4551
|
}
|
|
4519
4552
|
|
|
4520
|
-
const expectedTestCase = testCases.sort((a, b) => {
|
|
4521
|
-
// ascending order
|
|
4522
|
-
return a.expectedIdx - b.expectedIdx;
|
|
4523
|
-
});
|
|
4524
4553
|
const asks = dlob.getAsks(marketIndex, vAsk, slot, MarketType.SPOT, oracle);
|
|
4525
4554
|
|
|
4555
|
+
// With the AMM/vAMM generator gone from the k-way merge in getAsks, the
|
|
4556
|
+
// real orders surface in this order (taking market orders merged with
|
|
4557
|
+
// resting limit orders by price): 3, 4, 2, 5, 1, 6, 7.
|
|
4558
|
+
const expectedRealAsks = [
|
|
4559
|
+
{ orderId: 3, price: 0, orderType: OrderType.MARKET },
|
|
4560
|
+
{ orderId: 4, price: 0, orderType: OrderType.MARKET },
|
|
4561
|
+
{ orderId: 2, price: 14, orderType: OrderType.LIMIT },
|
|
4562
|
+
{ orderId: 5, price: 0, orderType: OrderType.MARKET },
|
|
4563
|
+
{ orderId: 1, price: 13, orderType: OrderType.LIMIT },
|
|
4564
|
+
{ orderId: 6, price: 16, orderType: OrderType.LIMIT },
|
|
4565
|
+
{ orderId: 7, price: 17, orderType: OrderType.LIMIT },
|
|
4566
|
+
];
|
|
4567
|
+
|
|
4526
4568
|
console.log('The Book Asks:');
|
|
4527
4569
|
let countAsks = 0;
|
|
4528
4570
|
for (const ask of asks) {
|
|
@@ -4535,20 +4577,18 @@ describe('DLOB Spot Tests', () => {
|
|
|
4535
4577
|
)}, price: ${ask.order?.price.toString()}, quantity: ${ask.order?.baseAssetAmountFilled.toString()}/${ask.order?.baseAssetAmount.toString()}`
|
|
4536
4578
|
);
|
|
4537
4579
|
|
|
4538
|
-
expect(ask.order?.orderId).to.equal(
|
|
4580
|
+
expect(ask.order?.orderId).to.equal(expectedRealAsks[countAsks].orderId);
|
|
4539
4581
|
expect(ask.order?.price.toNumber()).to.equal(
|
|
4540
|
-
|
|
4541
|
-
);
|
|
4542
|
-
expect(ask.order?.direction).to.equal(
|
|
4543
|
-
expectedTestCase[countAsks].direction
|
|
4582
|
+
expectedRealAsks[countAsks].price
|
|
4544
4583
|
);
|
|
4584
|
+
expect(ask.order?.direction).to.equal(PositionDirection.SHORT);
|
|
4545
4585
|
expect(ask.order?.orderType).to.equal(
|
|
4546
|
-
|
|
4586
|
+
expectedRealAsks[countAsks].orderType
|
|
4547
4587
|
);
|
|
4548
4588
|
countAsks++;
|
|
4549
4589
|
}
|
|
4550
4590
|
|
|
4551
|
-
expect(countAsks).to.equal(
|
|
4591
|
+
expect(countAsks).to.equal(expectedRealAsks.length);
|
|
4552
4592
|
});
|
|
4553
4593
|
|
|
4554
4594
|
it('Test insert market orders', () => {
|
|
@@ -4560,6 +4600,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
4560
4600
|
slot: new BN(slot),
|
|
4561
4601
|
confidence: new BN(1),
|
|
4562
4602
|
hasSufficientNumberOfDataPoints: true,
|
|
4603
|
+
isMMOracleActive: true,
|
|
4563
4604
|
};
|
|
4564
4605
|
const dlob = new DLOB();
|
|
4565
4606
|
const marketIndex = 0;
|
|
@@ -4650,6 +4691,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
4650
4691
|
slot: new BN(slot),
|
|
4651
4692
|
confidence: new BN(1),
|
|
4652
4693
|
hasSufficientNumberOfDataPoints: true,
|
|
4694
|
+
isMMOracleActive: true,
|
|
4653
4695
|
};
|
|
4654
4696
|
|
|
4655
4697
|
const user0 = Keypair.generate();
|
|
@@ -5082,6 +5124,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
5082
5124
|
slot: new BN(slot),
|
|
5083
5125
|
confidence: new BN(1),
|
|
5084
5126
|
hasSufficientNumberOfDataPoints: true,
|
|
5127
|
+
isMMOracleActive: true,
|
|
5085
5128
|
};
|
|
5086
5129
|
|
|
5087
5130
|
// insert some limit sells below vAMM ask, above bid
|
|
@@ -5231,6 +5274,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
5231
5274
|
slot: new BN(slot),
|
|
5232
5275
|
confidence: new BN(1),
|
|
5233
5276
|
hasSufficientNumberOfDataPoints: true,
|
|
5277
|
+
isMMOracleActive: true,
|
|
5234
5278
|
};
|
|
5235
5279
|
|
|
5236
5280
|
// insert some limit sells below vAMM ask, above bid
|
|
@@ -5357,6 +5401,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
5357
5401
|
slot: new BN(slot),
|
|
5358
5402
|
confidence: new BN(1),
|
|
5359
5403
|
hasSufficientNumberOfDataPoints: true,
|
|
5404
|
+
isMMOracleActive: true,
|
|
5360
5405
|
};
|
|
5361
5406
|
|
|
5362
5407
|
// insert some limit sells below vAMM ask, above bid
|
|
@@ -5486,6 +5531,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
5486
5531
|
slot: new BN(slot),
|
|
5487
5532
|
confidence: new BN(1),
|
|
5488
5533
|
hasSufficientNumberOfDataPoints: true,
|
|
5534
|
+
isMMOracleActive: true,
|
|
5489
5535
|
};
|
|
5490
5536
|
|
|
5491
5537
|
// insert some limit sells below vAMM ask, above bid
|
|
@@ -5676,6 +5722,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
5676
5722
|
slot: new BN(slot),
|
|
5677
5723
|
confidence: new BN(1),
|
|
5678
5724
|
hasSufficientNumberOfDataPoints: true,
|
|
5725
|
+
isMMOracleActive: true,
|
|
5679
5726
|
};
|
|
5680
5727
|
|
|
5681
5728
|
const orderIdsToTrigger = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
@@ -5990,6 +6037,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
5990
6037
|
slot: new BN(slot),
|
|
5991
6038
|
confidence: new BN(1),
|
|
5992
6039
|
hasSufficientNumberOfDataPoints: true,
|
|
6040
|
+
isMMOracleActive: true,
|
|
5993
6041
|
};
|
|
5994
6042
|
|
|
5995
6043
|
const user0 = Keypair.generate();
|
|
@@ -6079,6 +6127,7 @@ describe('DLOB Spot Tests', () => {
|
|
|
6079
6127
|
slot: new BN(slot),
|
|
6080
6128
|
confidence: new BN(1),
|
|
6081
6129
|
hasSufficientNumberOfDataPoints: true,
|
|
6130
|
+
isMMOracleActive: true,
|
|
6082
6131
|
};
|
|
6083
6132
|
|
|
6084
6133
|
const user0 = Keypair.generate();
|