@velocity-exchange/sdk 0.2.2 → 0.2.4
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 +12 -0
- package/lib/browser/adminClient.d.ts +4 -2
- package/lib/browser/adminClient.js +21 -4
- package/lib/browser/config.js +1 -1
- package/lib/browser/constants/numericConstants.d.ts +1 -0
- package/lib/browser/constants/numericConstants.js +2 -1
- package/lib/browser/constants/spotMarkets.js +1 -1
- package/lib/browser/idl/velocity.d.ts +61 -9
- package/lib/browser/idl/velocity.json +61 -9
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.js +1 -0
- package/lib/browser/math/funding.js +20 -4
- package/lib/browser/math/liquidation.d.ts +14 -0
- package/lib/browser/math/liquidation.js +14 -0
- package/lib/browser/math/spotMarket.d.ts +6 -0
- package/lib/browser/math/spotMarket.js +16 -1
- package/lib/browser/tx/forwardOnlyTxSender.d.ts +37 -0
- package/lib/browser/tx/forwardOnlyTxSender.js +92 -0
- package/lib/browser/types.d.ts +77 -9
- package/lib/browser/userMap/userMap.js +5 -1
- package/lib/node/adminClient.d.ts +4 -2
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +21 -4
- package/lib/node/config.js +1 -1
- package/lib/node/constants/numericConstants.d.ts +1 -0
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +2 -1
- package/lib/node/constants/spotMarkets.js +1 -1
- package/lib/node/idl/velocity.d.ts +61 -9
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +61 -9
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +20 -4
- package/lib/node/math/liquidation.d.ts +14 -0
- package/lib/node/math/liquidation.d.ts.map +1 -1
- package/lib/node/math/liquidation.js +14 -0
- package/lib/node/math/spotMarket.d.ts +6 -0
- package/lib/node/math/spotMarket.d.ts.map +1 -1
- package/lib/node/math/spotMarket.js +16 -1
- package/lib/node/tx/forwardOnlyTxSender.d.ts +38 -0
- package/lib/node/tx/forwardOnlyTxSender.d.ts.map +1 -0
- package/lib/node/tx/forwardOnlyTxSender.js +92 -0
- package/lib/node/types.d.ts +77 -9
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +5 -1
- package/package.json +1 -1
- package/src/adminClient.ts +53 -3
- package/src/config.ts +1 -1
- package/src/constants/numericConstants.ts +1 -0
- package/src/constants/spotMarkets.ts +1 -1
- package/src/idl/velocity.json +61 -9
- package/src/idl/velocity.ts +61 -9
- package/src/index.ts +1 -0
- package/src/math/funding.ts +23 -5
- package/src/math/liquidation.ts +14 -0
- package/src/math/spotMarket.ts +28 -2
- package/src/tx/forwardOnlyTxSender.ts +145 -0
- package/src/types.ts +84 -9
- package/src/userMap/userMap.ts +5 -1
- package/tests/amm/test.ts +2 -2
- package/tests/dlob/helpers.ts +26 -4
package/src/math/spotMarket.ts
CHANGED
|
@@ -5,8 +5,12 @@ import {
|
|
|
5
5
|
SpotBalanceType,
|
|
6
6
|
SpotMarketAccount,
|
|
7
7
|
} from '../types';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
calculateAssetWeight,
|
|
10
|
+
calculateLiabilityWeight,
|
|
11
|
+
getTokenAmount,
|
|
12
|
+
} from './spotBalance';
|
|
13
|
+
import { MARGIN_PRECISION, ZERO } from '../constants/numericConstants';
|
|
10
14
|
import { numberToSafeBN } from './utils';
|
|
11
15
|
|
|
12
16
|
export function castNumberToSpotPrecision(
|
|
@@ -54,3 +58,25 @@ export function calculateSpotMarketMarginRatio(
|
|
|
54
58
|
|
|
55
59
|
return marginRatio;
|
|
56
60
|
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns the maximum remaining deposit that can be made to the spot market. If the maxTokenDeposits on the market is zero then there is no limit and this function will also return zero. (so that needs to be checked)
|
|
64
|
+
* @param market
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
export function calculateMaxRemainingDeposit(market: SpotMarketAccount) {
|
|
68
|
+
const marketMaxTokenDeposits = market.maxTokenDeposits;
|
|
69
|
+
|
|
70
|
+
if (marketMaxTokenDeposits.eq(ZERO)) {
|
|
71
|
+
// If the maxTokenDeposits is set to zero then that means there is no limit. Return the largest number we can to represent infinite available deposit.
|
|
72
|
+
return ZERO;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const totalDepositsTokenAmount = getTokenAmount(
|
|
76
|
+
market.depositBalance,
|
|
77
|
+
market,
|
|
78
|
+
SpotBalanceType.DEPOSIT
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return BN.max(ZERO, marketMaxTokenDeposits.sub(totalDepositsTokenAmount));
|
|
82
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfirmOptions,
|
|
3
|
+
Connection,
|
|
4
|
+
VersionedTransaction,
|
|
5
|
+
} from '@solana/web3.js';
|
|
6
|
+
import bs58 from 'bs58';
|
|
7
|
+
import { BaseTxSender } from './baseTxSender';
|
|
8
|
+
import { ConfirmationStrategy, TxSigAndSlot } from './types';
|
|
9
|
+
import { TxHandler } from './txHandler';
|
|
10
|
+
import { IWallet } from '../types';
|
|
11
|
+
import { DEFAULT_CONFIRMATION_OPTS } from '../config';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_TIMEOUT = 35000;
|
|
14
|
+
const DEFAULT_RETRY = 5000;
|
|
15
|
+
|
|
16
|
+
type ResolveReference = {
|
|
17
|
+
resolve?: () => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export class ForwardOnlyTxSender extends BaseTxSender {
|
|
21
|
+
connection: Connection;
|
|
22
|
+
wallet: IWallet;
|
|
23
|
+
opts: ConfirmOptions;
|
|
24
|
+
timeout: number;
|
|
25
|
+
retrySleep: number;
|
|
26
|
+
additionalConnections: Connection[];
|
|
27
|
+
timoutCount = 0;
|
|
28
|
+
|
|
29
|
+
public constructor({
|
|
30
|
+
connection,
|
|
31
|
+
wallet,
|
|
32
|
+
opts = { ...DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 },
|
|
33
|
+
timeout = DEFAULT_TIMEOUT,
|
|
34
|
+
retrySleep = DEFAULT_RETRY,
|
|
35
|
+
confirmationStrategy = ConfirmationStrategy.Combo,
|
|
36
|
+
additionalTxSenderCallbacks = [],
|
|
37
|
+
txHandler,
|
|
38
|
+
trackTxLandRate,
|
|
39
|
+
txLandRateLookbackWindowMinutes,
|
|
40
|
+
landRateToFeeFunc,
|
|
41
|
+
throwOnTimeoutError = true,
|
|
42
|
+
}: {
|
|
43
|
+
connection: Connection;
|
|
44
|
+
wallet: IWallet;
|
|
45
|
+
opts?: ConfirmOptions;
|
|
46
|
+
timeout?: number;
|
|
47
|
+
retrySleep?: number;
|
|
48
|
+
confirmationStrategy?: ConfirmationStrategy;
|
|
49
|
+
additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
|
|
50
|
+
txHandler?: TxHandler;
|
|
51
|
+
trackTxLandRate?: boolean;
|
|
52
|
+
txLandRateLookbackWindowMinutes?: number;
|
|
53
|
+
landRateToFeeFunc?: (landRate: number) => number;
|
|
54
|
+
throwOnTimeoutError?: boolean;
|
|
55
|
+
}) {
|
|
56
|
+
super({
|
|
57
|
+
connection,
|
|
58
|
+
wallet,
|
|
59
|
+
opts,
|
|
60
|
+
timeout,
|
|
61
|
+
additionalConnections: [],
|
|
62
|
+
confirmationStrategy,
|
|
63
|
+
additionalTxSenderCallbacks,
|
|
64
|
+
txHandler,
|
|
65
|
+
trackTxLandRate,
|
|
66
|
+
txLandRateLookbackWindowMinutes,
|
|
67
|
+
landRateToFeeFunc,
|
|
68
|
+
throwOnTimeoutError,
|
|
69
|
+
});
|
|
70
|
+
this.connection = connection;
|
|
71
|
+
this.wallet = wallet;
|
|
72
|
+
this.opts = opts;
|
|
73
|
+
this.timeout = timeout;
|
|
74
|
+
this.retrySleep = retrySleep;
|
|
75
|
+
this.additionalConnections = [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async sleep(reference: ResolveReference): Promise<void> {
|
|
79
|
+
return new Promise((resolve) => {
|
|
80
|
+
reference.resolve = resolve;
|
|
81
|
+
setTimeout(resolve, this.retrySleep);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
sendToAdditionalConnections(
|
|
86
|
+
rawTx: Buffer | Uint8Array,
|
|
87
|
+
_opts: ConfirmOptions
|
|
88
|
+
): void {
|
|
89
|
+
this.additionalTxSenderCallbacks?.map((callback) => {
|
|
90
|
+
callback(bs58.encode(rawTx));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async sendRawTransaction(
|
|
95
|
+
rawTransaction: Buffer | Uint8Array,
|
|
96
|
+
opts: ConfirmOptions
|
|
97
|
+
): Promise<TxSigAndSlot> {
|
|
98
|
+
const deserializedTx = VersionedTransaction.deserialize(rawTransaction);
|
|
99
|
+
|
|
100
|
+
const txSig = deserializedTx.signatures[0];
|
|
101
|
+
const encodedTxSig = bs58.encode(txSig);
|
|
102
|
+
|
|
103
|
+
const startTime = this.getTimestamp();
|
|
104
|
+
|
|
105
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
106
|
+
this.txSigCache?.set(encodedTxSig, false);
|
|
107
|
+
|
|
108
|
+
let done = false;
|
|
109
|
+
const resolveReference: ResolveReference = {
|
|
110
|
+
resolve: undefined,
|
|
111
|
+
};
|
|
112
|
+
const stopWaiting = () => {
|
|
113
|
+
done = true;
|
|
114
|
+
if (resolveReference.resolve) {
|
|
115
|
+
resolveReference.resolve();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
(async () => {
|
|
120
|
+
while (!done && this.getTimestamp() - startTime < this.timeout) {
|
|
121
|
+
await this.sleep(resolveReference);
|
|
122
|
+
if (!done) {
|
|
123
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
|
|
128
|
+
let slot: number | undefined;
|
|
129
|
+
try {
|
|
130
|
+
const result = await this.confirmTransaction(
|
|
131
|
+
encodedTxSig,
|
|
132
|
+
opts.commitment
|
|
133
|
+
);
|
|
134
|
+
slot = result?.context?.slot;
|
|
135
|
+
this.txSigCache?.set(encodedTxSig, true);
|
|
136
|
+
// eslint-disable-next-line no-useless-catch
|
|
137
|
+
} catch (e) {
|
|
138
|
+
throw e;
|
|
139
|
+
} finally {
|
|
140
|
+
stopWaiting();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { txSig: encodedTxSig, slot };
|
|
144
|
+
}
|
|
145
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -371,6 +371,8 @@ export type DepositRecord = {
|
|
|
371
371
|
depositRecordId: BN;
|
|
372
372
|
explanation: DepositExplanation;
|
|
373
373
|
transferUser?: PublicKey;
|
|
374
|
+
signer?: PublicKey;
|
|
375
|
+
userTokenAmountAfter: BN;
|
|
374
376
|
};
|
|
375
377
|
|
|
376
378
|
export type SpotInterestRecord = {
|
|
@@ -465,13 +467,14 @@ export type LiquidationRecord = {
|
|
|
465
467
|
marginFreed: BN;
|
|
466
468
|
liquidationId: number;
|
|
467
469
|
bankrupt: boolean;
|
|
468
|
-
canceledOrderIds:
|
|
470
|
+
canceledOrderIds: number[];
|
|
469
471
|
liquidatePerp: LiquidatePerpRecord;
|
|
470
472
|
liquidateSpot: LiquidateSpotRecord;
|
|
471
473
|
liquidateBorrowForPerpPnl: LiquidateBorrowForPerpPnlRecord;
|
|
472
474
|
liquidatePerpPnlForDeposit: LiquidatePerpPnlForDepositRecord;
|
|
473
475
|
perpBankruptcy: PerpBankruptcyRecord;
|
|
474
476
|
spotBankruptcy: SpotBankruptcyRecord;
|
|
477
|
+
bitFlags: number;
|
|
475
478
|
};
|
|
476
479
|
|
|
477
480
|
export class LiquidationType {
|
|
@@ -498,11 +501,12 @@ export type LiquidatePerpRecord = {
|
|
|
498
501
|
oraclePrice: BN;
|
|
499
502
|
baseAssetAmount: BN;
|
|
500
503
|
quoteAssetAmount: BN;
|
|
501
|
-
userOrderId:
|
|
502
|
-
liquidatorOrderId:
|
|
504
|
+
userOrderId: number;
|
|
505
|
+
liquidatorOrderId: number;
|
|
503
506
|
fillRecordId: BN;
|
|
504
507
|
liquidatorFee: BN;
|
|
505
508
|
ifFee: BN;
|
|
509
|
+
protocolFee: BN;
|
|
506
510
|
};
|
|
507
511
|
|
|
508
512
|
export type LiquidateSpotRecord = {
|
|
@@ -513,6 +517,7 @@ export type LiquidateSpotRecord = {
|
|
|
513
517
|
liabilityPrice: BN;
|
|
514
518
|
liabilityTransfer: BN;
|
|
515
519
|
ifFee: BN;
|
|
520
|
+
protocolFee: BN;
|
|
516
521
|
};
|
|
517
522
|
|
|
518
523
|
export type LiquidateBorrowForPerpPnlRecord = {
|
|
@@ -615,6 +620,9 @@ export type OrderActionRecord = {
|
|
|
615
620
|
takerExistingBaseAssetAmount: BN | null;
|
|
616
621
|
makerExistingQuoteEntryAmount: BN | null;
|
|
617
622
|
makerExistingBaseAssetAmount: BN | null;
|
|
623
|
+
triggerPrice: BN | null;
|
|
624
|
+
builderIdx: number | null;
|
|
625
|
+
builderFee: BN | null;
|
|
618
626
|
};
|
|
619
627
|
|
|
620
628
|
export type SwapRecord = {
|
|
@@ -661,8 +669,6 @@ export type LPSwapRecord = {
|
|
|
661
669
|
inConstituentIndex: number;
|
|
662
670
|
outOraclePrice: BN;
|
|
663
671
|
inOraclePrice: BN;
|
|
664
|
-
outMint: PublicKey;
|
|
665
|
-
inMint: PublicKey;
|
|
666
672
|
lastAum: BN;
|
|
667
673
|
lastAumSlot: BN;
|
|
668
674
|
inMarketCurrentWeight: BN;
|
|
@@ -685,7 +691,6 @@ export type LPMintRedeemRecord = {
|
|
|
685
691
|
constituentIndex: number;
|
|
686
692
|
oraclePrice: BN;
|
|
687
693
|
mint: PublicKey;
|
|
688
|
-
lpMint: PublicKey;
|
|
689
694
|
lpAmount: BN;
|
|
690
695
|
lpFee: BN;
|
|
691
696
|
lpPrice: BN;
|
|
@@ -728,6 +733,7 @@ export type LPBorrowLendDepositRecord = {
|
|
|
728
733
|
export type StateAccount = {
|
|
729
734
|
coldAdmin: PublicKey;
|
|
730
735
|
warmAdmin: PublicKey;
|
|
736
|
+
pauseAdmin: PublicKey;
|
|
731
737
|
hotAmmCrank: PublicKey;
|
|
732
738
|
hotLpCache: PublicKey;
|
|
733
739
|
hotLpSwap: PublicKey;
|
|
@@ -764,6 +770,7 @@ export type StateAccount = {
|
|
|
764
770
|
liquidationDuration: number;
|
|
765
771
|
maxInitializeUserFee: number;
|
|
766
772
|
featureBitFlags: number;
|
|
773
|
+
lpPoolFeatureBitFlags: number;
|
|
767
774
|
};
|
|
768
775
|
|
|
769
776
|
export type PerpMarketAccount = {
|
|
@@ -807,6 +814,7 @@ export type PerpMarketAccount = {
|
|
|
807
814
|
pausedOperations: number;
|
|
808
815
|
|
|
809
816
|
lastFillPrice: BN;
|
|
817
|
+
poolId: number;
|
|
810
818
|
|
|
811
819
|
hedgeConfig: {
|
|
812
820
|
poolId: number;
|
|
@@ -838,6 +846,8 @@ export type PerpMarketAccount = {
|
|
|
838
846
|
lastFundingRateShort: BN;
|
|
839
847
|
lastFundingRateTs: BN;
|
|
840
848
|
netUnsettledFundingPnl: BN;
|
|
849
|
+
fundingClampThreshold: number;
|
|
850
|
+
fundingRampSlope: number;
|
|
841
851
|
orderStepSize: BN;
|
|
842
852
|
orderTickSize: BN;
|
|
843
853
|
};
|
|
@@ -906,6 +916,7 @@ export type SpotMarketAccount = {
|
|
|
906
916
|
|
|
907
917
|
lastInterestTs: BN;
|
|
908
918
|
lastTwapTs: BN;
|
|
919
|
+
expiryTs: BN;
|
|
909
920
|
initialAssetWeight: number;
|
|
910
921
|
maintenanceAssetWeight: number;
|
|
911
922
|
initialLiabilityWeight: number;
|
|
@@ -986,12 +997,21 @@ export type AMM = {
|
|
|
986
997
|
totalFeeMinusDistributions: BN;
|
|
987
998
|
/// @deprecated frozen pre-isolation analytics counter
|
|
988
999
|
totalFeeWithdrawn: BN;
|
|
1000
|
+
askBaseAssetReserve: BN;
|
|
1001
|
+
askQuoteAssetReserve: BN;
|
|
1002
|
+
bidBaseAssetReserve: BN;
|
|
1003
|
+
bidQuoteAssetReserve: BN;
|
|
989
1004
|
lastUpdateSlot: BN;
|
|
990
1005
|
netRevenueSinceLastFunding: BN;
|
|
991
1006
|
lastCumulativeFundingRateLong: BN;
|
|
992
1007
|
lastCumulativeFundingRateShort: BN;
|
|
1008
|
+
lastOracleReservePriceSpreadPct: BN;
|
|
1009
|
+
lastSpreadUpdateSlot: BN;
|
|
993
1010
|
baseSpread: number;
|
|
994
1011
|
maxSpread: number;
|
|
1012
|
+
longSpread: number;
|
|
1013
|
+
shortSpread: number;
|
|
1014
|
+
referencePriceOffset: number;
|
|
995
1015
|
maxFillReserveFraction: number;
|
|
996
1016
|
maxSlippageRatio: number;
|
|
997
1017
|
curveUpdateIntensity: number;
|
|
@@ -1064,6 +1084,8 @@ export type UserStatsAccount = {
|
|
|
1064
1084
|
};
|
|
1065
1085
|
referrer: PublicKey;
|
|
1066
1086
|
referrerStatus: number;
|
|
1087
|
+
disableUpdatePerpBidAskTwap: number;
|
|
1088
|
+
pausedOperations: number;
|
|
1067
1089
|
authority: PublicKey;
|
|
1068
1090
|
ifStakedQuoteAssetAmount: BN;
|
|
1069
1091
|
delegatePermissions: number;
|
|
@@ -1386,8 +1408,8 @@ export type FeeTier = {
|
|
|
1386
1408
|
};
|
|
1387
1409
|
|
|
1388
1410
|
export type OrderFillerRewardStructure = {
|
|
1389
|
-
rewardNumerator:
|
|
1390
|
-
rewardDenominator:
|
|
1411
|
+
rewardNumerator: number;
|
|
1412
|
+
rewardDenominator: number;
|
|
1391
1413
|
timeBasedRewardLowerBound: BN;
|
|
1392
1414
|
};
|
|
1393
1415
|
|
|
@@ -1424,6 +1446,25 @@ export type PrelaunchOracle = {
|
|
|
1424
1446
|
perpMarketIndex: number;
|
|
1425
1447
|
};
|
|
1426
1448
|
|
|
1449
|
+
export type PrelaunchOracleParams = {
|
|
1450
|
+
perpMarketIndex: number;
|
|
1451
|
+
price: BN | null;
|
|
1452
|
+
maxPrice: BN | null;
|
|
1453
|
+
};
|
|
1454
|
+
|
|
1455
|
+
export type PythLazerOracle = {
|
|
1456
|
+
price: BN;
|
|
1457
|
+
publishTime: BN;
|
|
1458
|
+
postedSlot: BN;
|
|
1459
|
+
exponent: number;
|
|
1460
|
+
conf: BN;
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
export type UpdatePerpMarketSummaryStatsParams = {
|
|
1464
|
+
netUnsettledFundingPnl: BN | null;
|
|
1465
|
+
updateAmmSummaryStats: boolean | null;
|
|
1466
|
+
};
|
|
1467
|
+
|
|
1427
1468
|
export type MarginCategory = 'Initial' | 'Maintenance';
|
|
1428
1469
|
|
|
1429
1470
|
export type InsuranceFundStake = {
|
|
@@ -1434,6 +1475,7 @@ export type InsuranceFundStake = {
|
|
|
1434
1475
|
|
|
1435
1476
|
ifShares: BN;
|
|
1436
1477
|
ifBase: BN;
|
|
1478
|
+
lastValidTs: BN;
|
|
1437
1479
|
|
|
1438
1480
|
lastWithdrawRequestShares: BN;
|
|
1439
1481
|
lastWithdrawRequestValue: BN;
|
|
@@ -1521,6 +1563,10 @@ export type SignedMsgUserOrdersAccount = {
|
|
|
1521
1563
|
signedMsgOrderData: SignedMsgOrderId[];
|
|
1522
1564
|
};
|
|
1523
1565
|
|
|
1566
|
+
export type SignedMsgWsDelegatesAccount = {
|
|
1567
|
+
delegates: PublicKey[];
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1524
1570
|
export type RevenueShareAccount = {
|
|
1525
1571
|
authority: PublicKey;
|
|
1526
1572
|
totalReferrerRewards: BN;
|
|
@@ -1555,8 +1601,25 @@ export type BuilderInfo = {
|
|
|
1555
1601
|
padding: number[];
|
|
1556
1602
|
};
|
|
1557
1603
|
|
|
1604
|
+
export type PerpMarketFeeSweepRecord = {
|
|
1605
|
+
ts: BN;
|
|
1606
|
+
marketIndex: number;
|
|
1607
|
+
ifSwept: BN;
|
|
1608
|
+
protocolSwept: BN;
|
|
1609
|
+
ammProvisionTokenized: BN;
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
export type ProtocolFeeWithdrawRecord = {
|
|
1613
|
+
ts: BN;
|
|
1614
|
+
marketIndex: number;
|
|
1615
|
+
isPerp: boolean;
|
|
1616
|
+
spotMarketIndex: number;
|
|
1617
|
+
amount: BN;
|
|
1618
|
+
recipientTokenAccount: PublicKey;
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1558
1621
|
export type RevenueShareSettleRecord = {
|
|
1559
|
-
ts:
|
|
1622
|
+
ts: BN;
|
|
1560
1623
|
builder: PublicKey | null;
|
|
1561
1624
|
referrer: PublicKey | null;
|
|
1562
1625
|
feeSettled: BN;
|
|
@@ -1626,6 +1689,8 @@ export type LPPoolAccount = {
|
|
|
1626
1689
|
bump: number;
|
|
1627
1690
|
gammaExecution: number;
|
|
1628
1691
|
xi: number;
|
|
1692
|
+
targetOracleDelayFeeBpsPer10Slots: number;
|
|
1693
|
+
targetPositionDelayFeeBpsPer10Slots: number;
|
|
1629
1694
|
};
|
|
1630
1695
|
|
|
1631
1696
|
export type ConstituentSpotBalance = {
|
|
@@ -1724,6 +1789,7 @@ export type CacheInfo = {
|
|
|
1724
1789
|
};
|
|
1725
1790
|
|
|
1726
1791
|
export type AmmCache = {
|
|
1792
|
+
bump: number;
|
|
1727
1793
|
cache: CacheInfo[];
|
|
1728
1794
|
};
|
|
1729
1795
|
|
|
@@ -1737,3 +1803,12 @@ export class TransferFeeAndPnlPoolDirection {
|
|
|
1737
1803
|
static readonly FEE_TO_PNL_POOL = { feeToPnlPool: {} };
|
|
1738
1804
|
static readonly PNL_TO_FEE_POOL = { pnlToFeePool: {} };
|
|
1739
1805
|
}
|
|
1806
|
+
|
|
1807
|
+
export type TransferFeeAndPnlPoolRecord = {
|
|
1808
|
+
ts: BN;
|
|
1809
|
+
slot: BN;
|
|
1810
|
+
perpMarketIndexWithFeePool: number;
|
|
1811
|
+
perpMarketIndexWithPnlPool: number;
|
|
1812
|
+
direction: TransferFeeAndPnlPoolDirection;
|
|
1813
|
+
amount: BN;
|
|
1814
|
+
};
|
package/src/userMap/userMap.ts
CHANGED
|
@@ -44,7 +44,11 @@ import { grpcSubscription } from './grpcSubscription';
|
|
|
44
44
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
45
45
|
import { EventEmitter } from 'events';
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
// Velocity's User account is 4496 bytes (8-byte discriminator + 4488 struct);
|
|
48
|
+
// drift's was 4376. This caps the zstd-decompressed buffer in defaultSync — if it's
|
|
49
|
+
// smaller than the real account, the buffer is truncated and decodeUser reads past
|
|
50
|
+
// the end (RangeError: ERR_BUFFER_OUT_OF_BOUNDS). Must be >= the on-chain User size.
|
|
51
|
+
const MAX_USER_ACCOUNT_SIZE_BYTES = 4496;
|
|
48
52
|
|
|
49
53
|
export interface UserMapInterface {
|
|
50
54
|
eventEmitter: StrictEventEmitter<EventEmitter, UserEvents>;
|
package/tests/amm/test.ts
CHANGED
|
@@ -1566,8 +1566,8 @@ describe('AMM Tests', () => {
|
|
|
1566
1566
|
|
|
1567
1567
|
assert(markTwapLive.eq(new BN('1949826')));
|
|
1568
1568
|
assert(oracleTwapLive.eq(new BN('1942510')));
|
|
1569
|
-
assert(est1.eq(new BN('
|
|
1570
|
-
assert(est2.eq(new BN('
|
|
1569
|
+
assert(est1.eq(new BN('14858')));
|
|
1570
|
+
assert(est2.eq(new BN('14858')));
|
|
1571
1571
|
});
|
|
1572
1572
|
|
|
1573
1573
|
it('predicted funding rate mock2', () => {
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -52,9 +52,23 @@ export const mockAMM: AMM = {
|
|
|
52
52
|
quoteAssetReserve: new BN(12)
|
|
53
53
|
.mul(QUOTE_PRECISION)
|
|
54
54
|
.mul(AMM_TO_QUOTE_PRECISION_RATIO),
|
|
55
|
+
// zero-spread mock: bid/ask reserves mirror the base/quote reserves
|
|
56
|
+
askBaseAssetReserve: new BN(1).mul(BASE_PRECISION),
|
|
57
|
+
askQuoteAssetReserve: new BN(12)
|
|
58
|
+
.mul(QUOTE_PRECISION)
|
|
59
|
+
.mul(AMM_TO_QUOTE_PRECISION_RATIO),
|
|
60
|
+
bidBaseAssetReserve: new BN(1).mul(BASE_PRECISION),
|
|
61
|
+
bidQuoteAssetReserve: new BN(12)
|
|
62
|
+
.mul(QUOTE_PRECISION)
|
|
63
|
+
.mul(AMM_TO_QUOTE_PRECISION_RATIO),
|
|
55
64
|
sqrtK: new BN(1),
|
|
56
65
|
pegMultiplier: new BN(1),
|
|
57
66
|
maxSlippageRatio: 1_000_000,
|
|
67
|
+
lastOracleReservePriceSpreadPct: new BN(0),
|
|
68
|
+
lastSpreadUpdateSlot: new BN(0),
|
|
69
|
+
longSpread: 0,
|
|
70
|
+
shortSpread: 0,
|
|
71
|
+
referencePriceOffset: 0,
|
|
58
72
|
|
|
59
73
|
feePool: {
|
|
60
74
|
scaledBalance: new BN(0),
|
|
@@ -177,6 +191,7 @@ function mockPerpMarketCommon(): Omit<
|
|
|
177
191
|
},
|
|
178
192
|
quoteSpotMarketIndex: 0,
|
|
179
193
|
feeAdjustment: 0,
|
|
194
|
+
poolId: 0,
|
|
180
195
|
pausedOperations: 0,
|
|
181
196
|
hedgeConfig: {
|
|
182
197
|
poolId: 0,
|
|
@@ -208,6 +223,8 @@ function mockPerpMarketCommon(): Omit<
|
|
|
208
223
|
lastFundingRateShort: new BN(0),
|
|
209
224
|
lastFundingRateTs: new BN(0),
|
|
210
225
|
netUnsettledFundingPnl: new BN(0),
|
|
226
|
+
fundingClampThreshold: 5,
|
|
227
|
+
fundingRampSlope: 1000000,
|
|
211
228
|
orderStepSize: new BN(1),
|
|
212
229
|
orderTickSize: new BN(1),
|
|
213
230
|
};
|
|
@@ -283,6 +300,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
283
300
|
borrowBalance: new BN(0),
|
|
284
301
|
lastInterestTs: new BN(0),
|
|
285
302
|
lastTwapTs: new BN(0),
|
|
303
|
+
expiryTs: new BN(0),
|
|
286
304
|
oracle: PublicKey.default,
|
|
287
305
|
initialAssetWeight: SPOT_MARKET_WEIGHT_PRECISION.toNumber(),
|
|
288
306
|
maintenanceAssetWeight: SPOT_MARKET_WEIGHT_PRECISION.toNumber(),
|
|
@@ -376,6 +394,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
376
394
|
borrowBalance: new BN(0),
|
|
377
395
|
lastInterestTs: new BN(0),
|
|
378
396
|
lastTwapTs: new BN(0),
|
|
397
|
+
expiryTs: new BN(0),
|
|
379
398
|
oracle: PublicKey.default,
|
|
380
399
|
initialAssetWeight: 0,
|
|
381
400
|
maintenanceAssetWeight: 0,
|
|
@@ -471,6 +490,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
471
490
|
borrowBalance: new BN(0),
|
|
472
491
|
lastInterestTs: new BN(0),
|
|
473
492
|
lastTwapTs: new BN(0),
|
|
493
|
+
expiryTs: new BN(0),
|
|
474
494
|
oracle: PublicKey.default,
|
|
475
495
|
initialAssetWeight: 0,
|
|
476
496
|
maintenanceAssetWeight: 0,
|
|
@@ -524,6 +544,7 @@ export const mockSpotMarkets: Array<SpotMarketAccount> = [
|
|
|
524
544
|
export const mockStateAccount: StateAccount = {
|
|
525
545
|
coldAdmin: PublicKey.default,
|
|
526
546
|
warmAdmin: PublicKey.default,
|
|
547
|
+
pauseAdmin: PublicKey.default,
|
|
527
548
|
hotAmmCrank: PublicKey.default,
|
|
528
549
|
hotLpCache: PublicKey.default,
|
|
529
550
|
hotLpSwap: PublicKey.default,
|
|
@@ -538,6 +559,7 @@ export const mockStateAccount: StateAccount = {
|
|
|
538
559
|
protocolFeeRecipientPerp: PublicKey.default,
|
|
539
560
|
protocolFeeRecipientSpot: PublicKey.default,
|
|
540
561
|
featureBitFlags: 0,
|
|
562
|
+
lpPoolFeatureBitFlags: 0,
|
|
541
563
|
defaultMarketOrderTimeInForce: 0,
|
|
542
564
|
defaultSpotAuctionDuration: 0,
|
|
543
565
|
discountMint: PublicKey.default,
|
|
@@ -576,8 +598,8 @@ export const mockStateAccount: StateAccount = {
|
|
|
576
598
|
},
|
|
577
599
|
],
|
|
578
600
|
fillerRewardStructure: {
|
|
579
|
-
rewardNumerator:
|
|
580
|
-
rewardDenominator:
|
|
601
|
+
rewardNumerator: 0,
|
|
602
|
+
rewardDenominator: 0,
|
|
581
603
|
timeBasedRewardLowerBound: new BN(0),
|
|
582
604
|
},
|
|
583
605
|
flatFillerFee: new BN(0),
|
|
@@ -601,8 +623,8 @@ export const mockStateAccount: StateAccount = {
|
|
|
601
623
|
},
|
|
602
624
|
],
|
|
603
625
|
fillerRewardStructure: {
|
|
604
|
-
rewardNumerator:
|
|
605
|
-
rewardDenominator:
|
|
626
|
+
rewardNumerator: 0,
|
|
627
|
+
rewardDenominator: 0,
|
|
606
628
|
timeBasedRewardLowerBound: new BN(0),
|
|
607
629
|
},
|
|
608
630
|
flatFillerFee: new BN(0),
|