@velocity-exchange/sdk 0.4.0 → 0.6.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 +3 -3
- package/lib/browser/adminClient.d.ts +52 -0
- package/lib/browser/adminClient.js +97 -0
- package/lib/browser/config.js +6 -7
- package/lib/browser/constants/numericConstants.d.ts +1 -1
- package/lib/browser/constants/numericConstants.js +1 -1
- package/lib/browser/decode/user.js +5 -1
- package/lib/browser/idl/velocity.d.ts +191 -15
- package/lib/browser/idl/velocity.json +192 -16
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -0
- package/lib/browser/orderSubscriber/OrderSubscriber.js +10 -4
- package/lib/browser/pyth/pythLazerSubscriber.js +37 -27
- package/lib/browser/types.d.ts +6 -0
- package/lib/browser/user.d.ts +20 -3
- package/lib/browser/user.js +52 -4
- package/lib/browser/velocityClient.d.ts +46 -10
- package/lib/browser/velocityClient.js +107 -35
- package/lib/node/adminClient.d.ts +52 -0
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +97 -0
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +6 -7
- package/lib/node/constants/numericConstants.d.ts +1 -1
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +1 -1
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +5 -1
- package/lib/node/idl/velocity.d.ts +191 -15
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +192 -16
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -0
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +10 -4
- package/lib/node/pyth/pythLazerSubscriber.d.ts.map +1 -1
- package/lib/node/pyth/pythLazerSubscriber.js +37 -27
- package/lib/node/types.d.ts +6 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +20 -3
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +52 -4
- package/lib/node/velocityClient.d.ts +46 -10
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +107 -35
- package/package.json +7 -3
- package/.prettierignore +0 -1
- package/CHANGELOG.md +0 -132
- package/build-browser.js +0 -58
- package/bunfig.toml +0 -3
- package/esbuild-shims.js +0 -12
- package/scripts/deposit-isolated-positions.ts +0 -110
- package/scripts/find-flagged-users.ts +0 -213
- package/scripts/grpc-client-test-comparison.ts +0 -372
- package/scripts/grpc-multiuser-client-test-comparison.ts +0 -158
- package/scripts/postbuild.js +0 -95
- package/scripts/single-grpc-client-test.ts +0 -284
- package/scripts/withdraw-isolated-positions.ts +0 -174
- package/src/accounts/README_WebSocketAccountSubscriberV2.md +0 -95
- package/src/accounts/README_WebSocketProgramAccountSubscriberV2.md +0 -135
- package/src/accounts/basicUserAccountSubscriber.ts +0 -79
- package/src/accounts/basicUserStatsAccountSubscriber.ts +0 -87
- package/src/accounts/bulkAccountLoader.ts +0 -358
- package/src/accounts/bulkUserStatsSubscription.ts +0 -40
- package/src/accounts/bulkUserSubscription.ts +0 -39
- package/src/accounts/customizedCadenceBulkAccountLoader.ts +0 -250
- package/src/accounts/fetch.ts +0 -200
- package/src/accounts/grpcAccountSubscriber.ts +0 -225
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +0 -73
- package/src/accounts/grpcMultiAccountSubscriber.ts +0 -566
- package/src/accounts/grpcMultiUserAccountSubscriber.ts +0 -328
- package/src/accounts/grpcProgramAccountSubscriber.ts +0 -264
- package/src/accounts/grpcUserAccountSubscriber.ts +0 -63
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +0 -65
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +0 -257
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +0 -941
- package/src/accounts/laserProgramAccountSubscriber.ts +0 -266
- package/src/accounts/oneShotUserAccountSubscriber.ts +0 -88
- package/src/accounts/oneShotUserStatsAccountSubscriber.ts +0 -94
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +0 -223
- package/src/accounts/pollingOracleAccountSubscriber.ts +0 -151
- package/src/accounts/pollingTokenAccountSubscriber.ts +0 -147
- package/src/accounts/pollingUserAccountSubscriber.ts +0 -198
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +0 -180
- package/src/accounts/pollingVelocityClientAccountSubscriber.ts +0 -774
- package/src/accounts/testBulkAccountLoader.ts +0 -59
- package/src/accounts/types.ts +0 -428
- package/src/accounts/utils.ts +0 -90
- package/src/accounts/webSocketAccountSubscriber.ts +0 -304
- package/src/accounts/webSocketAccountSubscriberV2.ts +0 -536
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +0 -171
- package/src/accounts/webSocketProgramAccountSubscriber.ts +0 -244
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +0 -1048
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +0 -1042
- package/src/accounts/webSocketUserAccountSubscriber.ts +0 -139
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +0 -131
- package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +0 -865
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +0 -897
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +0 -127
- package/src/addresses/marketAddresses.ts +0 -28
- package/src/addresses/pda.ts +0 -620
- package/src/adminClient.ts +0 -8136
- package/src/assert/assert.ts +0 -5
- package/src/auctionSubscriber/auctionSubscriber.ts +0 -86
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +0 -99
- package/src/auctionSubscriber/index.ts +0 -9
- package/src/auctionSubscriber/types.ts +0 -30
- package/src/bankrun/bankrunConnection.ts +0 -630
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +0 -160
- package/src/blockhashSubscriber/index.ts +0 -6
- package/src/blockhashSubscriber/types.ts +0 -13
- package/src/clock/clockSubscriber.ts +0 -146
- package/src/config.ts +0 -312
- package/src/constants/index.ts +0 -9
- package/src/constants/numericConstants.ts +0 -194
- package/src/constants/perpMarkets.ts +0 -127
- package/src/constants/spotMarkets.ts +0 -104
- package/src/constants/txConstants.ts +0 -2
- package/src/constituentMap/constituentMap.ts +0 -305
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +0 -99
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +0 -121
- package/src/core/VelocityCore.ts +0 -606
- package/src/core/index.ts +0 -12
- package/src/core/instructions/deposit.ts +0 -64
- package/src/core/instructions/fill.ts +0 -51
- package/src/core/instructions/funding.ts +0 -33
- package/src/core/instructions/liquidation.ts +0 -55
- package/src/core/instructions/orders.ts +0 -84
- package/src/core/instructions/perpOrders.ts +0 -312
- package/src/core/instructions/settlement.ts +0 -40
- package/src/core/instructions/trigger.ts +0 -41
- package/src/core/instructions/withdraw.ts +0 -65
- package/src/core/remainingAccounts.ts +0 -320
- package/src/core/signedMsg.ts +0 -109
- package/src/decode/customCoder.ts +0 -148
- package/src/decode/user.ts +0 -401
- package/src/dlob/DLOB.ts +0 -2793
- package/src/dlob/DLOBNode.ts +0 -305
- package/src/dlob/DLOBSubscriber.ts +0 -269
- package/src/dlob/NodeList.ts +0 -244
- package/src/dlob/orderBookLevels.ts +0 -695
- package/src/dlob/types.ts +0 -37
- package/src/events/eventList.ts +0 -114
- package/src/events/eventSubscriber.ts +0 -521
- package/src/events/eventsServerLogProvider.ts +0 -189
- package/src/events/fetchLogs.ts +0 -219
- package/src/events/parse.ts +0 -271
- package/src/events/pollingLogProvider.ts +0 -113
- package/src/events/sort.ts +0 -51
- package/src/events/txEventCache.ts +0 -92
- package/src/events/types.ts +0 -337
- package/src/events/webSocketLogProvider.ts +0 -152
- package/src/factory/bigNum.ts +0 -709
- package/src/factory/oracleClient.ts +0 -73
- package/src/idl/pyth.json +0 -142
- package/src/idl/pyth.ts +0 -97
- package/src/idl/pyth_solana_receiver.json +0 -628
- package/src/idl/token_faucet.json +0 -229
- package/src/idl/token_faucet.ts +0 -197
- package/src/idl/velocity.json +0 -23974
- package/src/idl/velocity.ts +0 -23980
- package/src/index.ts +0 -150
- package/src/indicative-quotes/indicativeQuotesSender.ts +0 -233
- package/src/isomorphic/README.md +0 -19
- package/src/isomorphic/anchor.browser.ts +0 -44
- package/src/isomorphic/anchor.node.ts +0 -1
- package/src/isomorphic/anchor.ts +0 -1
- package/src/isomorphic/anchor29.browser.ts +0 -24
- package/src/isomorphic/anchor29.node.ts +0 -1
- package/src/isomorphic/anchor29.ts +0 -1
- package/src/isomorphic/grpc.browser.ts +0 -4
- package/src/isomorphic/grpc.node.ts +0 -130
- package/src/isomorphic/grpc.ts +0 -1
- package/src/jupiter/jupiterClient.ts +0 -502
- package/src/keypair.ts +0 -32
- package/src/margin/README.md +0 -138
- package/src/marginCalculation.ts +0 -407
- package/src/marinade/idl/idl.json +0 -1962
- package/src/marinade/index.ts +0 -73
- package/src/marinade/types.ts +0 -3925
- package/src/math/amm.ts +0 -1758
- package/src/math/auction.ts +0 -480
- package/src/math/bankruptcy.ts +0 -138
- package/src/math/builder.ts +0 -130
- package/src/math/conversion.ts +0 -45
- package/src/math/exchangeStatus.ts +0 -261
- package/src/math/funding.ts +0 -498
- package/src/math/insurance.ts +0 -171
- package/src/math/liquidation.ts +0 -433
- package/src/math/margin.ts +0 -327
- package/src/math/market.ts +0 -487
- package/src/math/oracles.ts +0 -477
- package/src/math/orders.ts +0 -500
- package/src/math/position.ts +0 -381
- package/src/math/repeg.ts +0 -223
- package/src/math/spotBalance.ts +0 -996
- package/src/math/spotMarket.ts +0 -115
- package/src/math/spotPosition.ts +0 -263
- package/src/math/state.ts +0 -71
- package/src/math/superStake.ts +0 -602
- package/src/math/tiers.ts +0 -73
- package/src/math/trade.ts +0 -879
- package/src/math/utils.ts +0 -183
- package/src/memcmp.ts +0 -279
- package/src/oracles/oracleClientCache.ts +0 -41
- package/src/oracles/oracleId.ts +0 -99
- package/src/oracles/prelaunchOracleClient.ts +0 -63
- package/src/oracles/pythClient.ts +0 -125
- package/src/oracles/pythLazerClient.ts +0 -141
- package/src/oracles/quoteAssetOracleClient.ts +0 -43
- package/src/oracles/strictOraclePrice.ts +0 -40
- package/src/oracles/types.ts +0 -82
- package/src/oracles/utils.ts +0 -45
- package/src/orderParams.ts +0 -117
- package/src/orderSubscriber/OrderSubscriber.ts +0 -378
- package/src/orderSubscriber/PollingSubscription.ts +0 -50
- package/src/orderSubscriber/WebsocketSubscription.ts +0 -137
- package/src/orderSubscriber/grpcSubscription.ts +0 -155
- package/src/orderSubscriber/index.ts +0 -7
- package/src/orderSubscriber/types.ts +0 -64
- package/src/priorityFee/averageOverSlotsStrategy.ts +0 -17
- package/src/priorityFee/averageStrategy.ts +0 -13
- package/src/priorityFee/ewmaStrategy.ts +0 -51
- package/src/priorityFee/heliusPriorityFeeMethod.ts +0 -68
- package/src/priorityFee/index.ts +0 -16
- package/src/priorityFee/maxOverSlotsStrategy.ts +0 -18
- package/src/priorityFee/maxStrategy.ts +0 -8
- package/src/priorityFee/priorityFeeSubscriber.ts +0 -328
- package/src/priorityFee/priorityFeeSubscriberMap.ts +0 -134
- package/src/priorityFee/solanaPriorityFeeMethod.ts +0 -46
- package/src/priorityFee/types.ts +0 -82
- package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -53
- package/src/pyth/constants.ts +0 -9
- package/src/pyth/index.ts +0 -15
- package/src/pyth/pythLazerSubscriber.ts +0 -365
- package/src/pyth/types.ts +0 -4451
- package/src/pyth/utils.ts +0 -13
- package/src/slot/SlotSubscriber.ts +0 -126
- package/src/slot/SlothashSubscriber.ts +0 -163
- package/src/swap/UnifiedSwapClient.ts +0 -315
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +0 -81
- package/src/swift/index.ts +0 -10
- package/src/swift/signedMsgUserAccountSubscriber.ts +0 -251
- package/src/swift/swiftOrderSubscriber.ts +0 -351
- package/src/testClient.ts +0 -42
- package/src/titan/titanClient.ts +0 -438
- package/src/token/index.ts +0 -13
- package/src/tokenFaucet.ts +0 -296
- package/src/tx/baseTxSender.ts +0 -651
- package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +0 -31
- package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +0 -105
- package/src/tx/blockhashFetcher/types.ts +0 -9
- package/src/tx/fastSingleTxSender.ts +0 -200
- package/src/tx/forwardOnlyTxSender.ts +0 -193
- package/src/tx/priorityFeeCalculator.ts +0 -117
- package/src/tx/reportTransactionError.ts +0 -176
- package/src/tx/retryTxSender.ts +0 -177
- package/src/tx/txHandler.ts +0 -1009
- package/src/tx/txParamProcessor.ts +0 -225
- package/src/tx/types.ts +0 -117
- package/src/tx/utils.ts +0 -133
- package/src/tx/whileValidTxSender.ts +0 -377
- package/src/types.ts +0 -2575
- package/src/user.ts +0 -5316
- package/src/userConfig.ts +0 -38
- package/src/userMap/PollingSubscription.ts +0 -61
- package/src/userMap/WebsocketSubscription.ts +0 -93
- package/src/userMap/grpcSubscription.ts +0 -93
- package/src/userMap/referrerMap.ts +0 -360
- package/src/userMap/revenueShareEscrowMap.ts +0 -342
- package/src/userMap/userMap.ts +0 -784
- package/src/userMap/userMapConfig.ts +0 -82
- package/src/userMap/userStatsMap.ts +0 -393
- package/src/userName.ts +0 -37
- package/src/userStats.ts +0 -159
- package/src/userStatsConfig.ts +0 -35
- package/src/util/TransactionConfirmationManager.ts +0 -333
- package/src/util/chainClock.ts +0 -65
- package/src/util/computeUnits.ts +0 -101
- package/src/util/digest.ts +0 -33
- package/src/util/ed25519Utils.ts +0 -95
- package/src/util/promiseTimeout.ts +0 -23
- package/src/velocityClient.ts +0 -14802
- package/src/velocityClientConfig.ts +0 -119
- package/src/wallet.ts +0 -91
- package/tests/VelocityCore/builder_escrow.test.ts +0 -121
- package/tests/VelocityCore/decode.test.ts +0 -16
- package/tests/VelocityCore/fill_trigger.test.ts +0 -73
- package/tests/VelocityCore/instructions.test.ts +0 -46
- package/tests/VelocityCore/pdas.test.ts +0 -30
- package/tests/VelocityCore/perp_orders.test.ts +0 -205
- package/tests/VelocityCore/remainingAccounts.test.ts +0 -72
- package/tests/VelocityCore/settlement_liquidation.test.ts +0 -69
- package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +0 -211
- package/tests/amm/test.ts +0 -2402
- package/tests/auctions/test.ts +0 -81
- package/tests/bn/test.ts +0 -355
- package/tests/builder/builderFee.test.ts +0 -42
- package/tests/ci/verifyConstants.ts +0 -393
- package/tests/decode/test.ts +0 -262
- package/tests/decode/userAccountBufferStrings.ts +0 -102
- package/tests/dlob/helpers.ts +0 -748
- package/tests/dlob/test.ts +0 -6969
- package/tests/dlob/tickSizeStandardization.ts +0 -545
- package/tests/events/parseLogsForCuUsage.ts +0 -139
- package/tests/exchangeStatus/test.ts +0 -45
- package/tests/insurance/test.ts +0 -40
- package/tests/liquidation/test.ts +0 -125
- package/tests/oracles/mmOracleGate.test.ts +0 -379
- package/tests/oracles/pythPegSnap.test.ts +0 -76
- package/tests/sdkParity/enumParity.test.ts +0 -84
- package/tests/sdkParity/marginCategoryFill.test.ts +0 -143
- package/tests/sdkParity/memcmpOffsets.test.ts +0 -139
- package/tests/spot/test.ts +0 -281
- package/tests/tx/TransactionConfirmationManager.test.ts +0 -312
- package/tests/tx/cachedBlockhashFetcher.test.ts +0 -96
- package/tests/tx/priorityFeeCalculator.ts +0 -77
- package/tests/tx/priorityFeeStrategy.ts +0 -95
- package/tests/user/bankruptcy.ts +0 -165
- package/tests/user/feeAndWithdrawLimits.ts +0 -284
- package/tests/user/getMarginCalculation.ts +0 -586
- package/tests/user/helpers.ts +0 -184
- package/tests/user/liquidations.ts +0 -129
- package/tests/user/marginCalculations.test.ts +0 -321
- package/tests/user/test.ts +0 -833
- package/tsconfig.browser.json +0 -18
- package/tsconfig.json +0 -36
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* VelocityClientConfig — configuration types for constructing a {@link VelocityClient}.
|
|
3
|
-
*
|
|
4
|
-
* Key options: RPC connection, wallet/keypair, account subscription mode
|
|
5
|
-
* (WebSocket vs polling), oracle client selection, transaction sender config,
|
|
6
|
-
* and feature flags (activeSubAccountId, authority override).
|
|
7
|
-
*/
|
|
8
|
-
import {
|
|
9
|
-
Commitment,
|
|
10
|
-
ConfirmOptions,
|
|
11
|
-
Connection,
|
|
12
|
-
PublicKey,
|
|
13
|
-
TransactionVersion,
|
|
14
|
-
} from '@solana/web3.js';
|
|
15
|
-
import { IWallet, TxParams, UserAccount } from './types';
|
|
16
|
-
import { OracleInfo } from './oracles/types';
|
|
17
|
-
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
18
|
-
import { VelocityEnv } from './config';
|
|
19
|
-
import { TxSender } from './tx/types';
|
|
20
|
-
import { TxHandler, TxHandlerConfig } from './tx/txHandler';
|
|
21
|
-
import {
|
|
22
|
-
GrpcConfigs,
|
|
23
|
-
ResubOpts,
|
|
24
|
-
DelistedMarketSetting,
|
|
25
|
-
} from './accounts/types';
|
|
26
|
-
import { Coder, Program } from './isomorphic/anchor';
|
|
27
|
-
import { WebSocketAccountSubscriber } from './accounts/webSocketAccountSubscriber';
|
|
28
|
-
import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscriberV2';
|
|
29
|
-
import { grpcVelocityClientAccountSubscriberV2 } from './accounts/grpcVelocityClientAccountSubscriberV2';
|
|
30
|
-
import { grpcVelocityClientAccountSubscriber } from './accounts/grpcVelocityClientAccountSubscriber';
|
|
31
|
-
import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
|
|
32
|
-
import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
33
|
-
import { WebSocketVelocityClientAccountSubscriber } from './accounts/webSocketVelocityClientAccountSubscriber';
|
|
34
|
-
import { WebSocketVelocityClientAccountSubscriberV2 } from './accounts/webSocketVelocityClientAccountSubscriberV2';
|
|
35
|
-
|
|
36
|
-
export type VelocityClientConfig = {
|
|
37
|
-
connection: Connection;
|
|
38
|
-
wallet: IWallet;
|
|
39
|
-
env?: VelocityEnv;
|
|
40
|
-
programID?: PublicKey;
|
|
41
|
-
accountSubscription?: VelocityClientSubscriptionConfig;
|
|
42
|
-
opts?: ConfirmOptions;
|
|
43
|
-
txSender?: TxSender;
|
|
44
|
-
txHandler?: TxHandler;
|
|
45
|
-
subAccountIds?: number[];
|
|
46
|
-
activeSubAccountId?: number;
|
|
47
|
-
perpMarketIndexes?: number[];
|
|
48
|
-
spotMarketIndexes?: number[];
|
|
49
|
-
/** @deprecated use marketLookupTables */
|
|
50
|
-
marketLookupTable?: PublicKey;
|
|
51
|
-
marketLookupTables?: PublicKey[];
|
|
52
|
-
oracleInfos?: OracleInfo[];
|
|
53
|
-
userStats?: boolean;
|
|
54
|
-
authority?: PublicKey; // explicitly pass an authority if signer is delegate
|
|
55
|
-
includeDelegates?: boolean; // flag for whether to load delegate accounts as well
|
|
56
|
-
authoritySubAccountMap?: Map<string, number[]>; // if passed this will override subAccountIds and includeDelegates
|
|
57
|
-
skipLoadUsers?: boolean; // if passed to constructor, no user accounts will be loaded. they will load if updateWallet is called afterwards.
|
|
58
|
-
txVersion?: TransactionVersion; // which tx version to use
|
|
59
|
-
txParams?: TxParams; // default tx params to use
|
|
60
|
-
enableMetricsEvents?: boolean;
|
|
61
|
-
txHandlerConfig?: TxHandlerConfig;
|
|
62
|
-
delistedMarketSetting?: DelistedMarketSetting;
|
|
63
|
-
useHotWalletAdmin?: boolean;
|
|
64
|
-
coder?: Coder;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
type GrpcVelocityClientAccountSubscriberCtor = new (
|
|
68
|
-
grpcConfigs: GrpcConfigs,
|
|
69
|
-
program: Program,
|
|
70
|
-
perpMarketIndexes: number[],
|
|
71
|
-
spotMarketIndexes: number[],
|
|
72
|
-
oracleInfos: OracleInfo[],
|
|
73
|
-
shouldFindAllMarketsAndOracles: boolean,
|
|
74
|
-
delistedMarketSetting: DelistedMarketSetting
|
|
75
|
-
) =>
|
|
76
|
-
| grpcVelocityClientAccountSubscriberV2
|
|
77
|
-
| grpcVelocityClientAccountSubscriber;
|
|
78
|
-
|
|
79
|
-
type WsVelocityClientAccountSubscriberCtor = new (
|
|
80
|
-
program: Program,
|
|
81
|
-
perpMarketIndexes: number[],
|
|
82
|
-
spotMarketIndexes: number[],
|
|
83
|
-
oracleInfos: OracleInfo[],
|
|
84
|
-
shouldFindAllMarketsAndOracles: boolean,
|
|
85
|
-
delistedMarketSetting: DelistedMarketSetting
|
|
86
|
-
) =>
|
|
87
|
-
| WebSocketVelocityClientAccountSubscriber
|
|
88
|
-
| WebSocketVelocityClientAccountSubscriberV2;
|
|
89
|
-
|
|
90
|
-
export type VelocityClientSubscriptionConfig =
|
|
91
|
-
| {
|
|
92
|
-
type: 'grpc';
|
|
93
|
-
grpcConfigs: GrpcConfigs;
|
|
94
|
-
resubTimeoutMs?: number;
|
|
95
|
-
logResubMessages?: boolean;
|
|
96
|
-
velocityClientAccountSubscriber?: GrpcVelocityClientAccountSubscriberCtor;
|
|
97
|
-
grpcMultiUserAccountSubscriber?: grpcMultiUserAccountSubscriber;
|
|
98
|
-
}
|
|
99
|
-
| {
|
|
100
|
-
type: 'websocket';
|
|
101
|
-
resubTimeoutMs?: number;
|
|
102
|
-
logResubMessages?: boolean;
|
|
103
|
-
commitment?: Commitment;
|
|
104
|
-
programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
105
|
-
perpMarketAccountSubscriber?: new (
|
|
106
|
-
accountName: string,
|
|
107
|
-
program: Program,
|
|
108
|
-
accountPublicKey: PublicKey,
|
|
109
|
-
decodeBuffer?: (buffer: Buffer) => any,
|
|
110
|
-
resubOpts?: ResubOpts,
|
|
111
|
-
commitment?: Commitment
|
|
112
|
-
) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
|
|
113
|
-
/** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */
|
|
114
|
-
velocityClientAccountSubscriber?: WsVelocityClientAccountSubscriberCtor;
|
|
115
|
-
}
|
|
116
|
-
| {
|
|
117
|
-
type: 'polling';
|
|
118
|
-
accountLoader: BulkAccountLoader;
|
|
119
|
-
};
|
package/src/wallet.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Keypair,
|
|
3
|
-
PublicKey,
|
|
4
|
-
Transaction,
|
|
5
|
-
VersionedTransaction,
|
|
6
|
-
} from '@solana/web3.js';
|
|
7
|
-
import { IWallet, IVersionedWallet } from './types';
|
|
8
|
-
import nacl from 'tweetnacl';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Local-keypair implementation of `IWallet`/`IVersionedWallet` that signs directly with an
|
|
12
|
-
* in-memory `Keypair` (no external wallet/RPC round-trip). Suitable for keeper bots, scripts, and
|
|
13
|
-
* tests; not for browser dapps holding user funds.
|
|
14
|
-
*/
|
|
15
|
-
export class Wallet implements IWallet, IVersionedWallet {
|
|
16
|
-
constructor(readonly payer: Keypair) {}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Partially signs a legacy `Transaction` with this wallet's keypair, leaving any other
|
|
20
|
-
* required signatures untouched.
|
|
21
|
-
* @param tx - Transaction to sign; mutated in place.
|
|
22
|
-
* @returns The same transaction instance, now signed by `payer`.
|
|
23
|
-
*/
|
|
24
|
-
async signTransaction(tx: Transaction): Promise<Transaction> {
|
|
25
|
-
tx.partialSign(this.payer);
|
|
26
|
-
return tx;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Signs a `VersionedTransaction` with this wallet's keypair.
|
|
31
|
-
* @param tx - Transaction to sign; mutated in place.
|
|
32
|
-
* @returns The same transaction instance, now signed by `payer`.
|
|
33
|
-
*/
|
|
34
|
-
async signVersionedTransaction(
|
|
35
|
-
tx: VersionedTransaction
|
|
36
|
-
): Promise<VersionedTransaction> {
|
|
37
|
-
tx.sign([this.payer]);
|
|
38
|
-
return tx;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Partially signs a batch of legacy `Transaction`s with this wallet's keypair.
|
|
43
|
-
* @param txs - Transactions to sign; each is mutated in place.
|
|
44
|
-
* @returns The same transaction instances, now signed by `payer`.
|
|
45
|
-
*/
|
|
46
|
-
async signAllTransactions(txs: Transaction[]): Promise<Transaction[]> {
|
|
47
|
-
return txs.map((t) => {
|
|
48
|
-
t.partialSign(this.payer);
|
|
49
|
-
return t;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Signs a batch of `VersionedTransaction`s with this wallet's keypair.
|
|
55
|
-
* @param txs - Transactions to sign; each is mutated in place.
|
|
56
|
-
* @returns The same transaction instances, now signed by `payer`.
|
|
57
|
-
*/
|
|
58
|
-
async signAllVersionedTransactions(
|
|
59
|
-
txs: VersionedTransaction[]
|
|
60
|
-
): Promise<VersionedTransaction[]> {
|
|
61
|
-
return txs.map((t) => {
|
|
62
|
-
t.sign([this.payer]);
|
|
63
|
-
return t;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** The wallet's public key, i.e. `payer.publicKey`. */
|
|
68
|
-
get publicKey(): PublicKey {
|
|
69
|
-
return this.payer.publicKey;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* `Wallet` variant that additionally supports raw message signing (`signMessage`), needed for
|
|
75
|
-
* flows like swift/signed-message orders that sign an ed25519 payload outside of a transaction.
|
|
76
|
-
*/
|
|
77
|
-
export class WalletV2 extends Wallet {
|
|
78
|
-
constructor(readonly payer: Keypair) {
|
|
79
|
-
super(payer);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Signs an arbitrary message with this wallet's ed25519 secret key (detached signature, not a
|
|
84
|
-
* transaction).
|
|
85
|
-
* @param message - Raw bytes to sign.
|
|
86
|
-
* @returns The 64-byte detached ed25519 signature.
|
|
87
|
-
*/
|
|
88
|
-
async signMessage(message: Uint8Array): Promise<Uint8Array> {
|
|
89
|
-
return Buffer.from(nacl.sign.detached(message, this.payer.secretKey));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Keypair, PublicKey } from '@solana/web3.js';
|
|
3
|
-
import { VelocityClient } from '../../src/velocityClient';
|
|
4
|
-
import { ReferrerMap } from '../../src/userMap/referrerMap';
|
|
5
|
-
import { getRevenueShareEscrowAccountPublicKey } from '../../src/addresses/pda';
|
|
6
|
-
import { RevenueShareEscrowAccount } from '../../src/types';
|
|
7
|
-
|
|
8
|
-
// `getTakerEscrowAccountMeta` decides whether a perp fill must carry the taker's
|
|
9
|
-
// RevenueShareEscrow account. It only reads `this.program.programId`, so we can
|
|
10
|
-
// exercise the decision with a minimal `this` instead of a full client.
|
|
11
|
-
// Regression guard for: a referred taker (escrow initialized with a referrer)
|
|
12
|
-
// whose order carries no builder code must still get the escrow attached, else
|
|
13
|
-
// the program rejects the fill with UnableToLoadRevenueShareAccount.
|
|
14
|
-
const getTakerEscrowAccountMeta = (VelocityClient.prototype as any)
|
|
15
|
-
.getTakerEscrowAccountMeta as (
|
|
16
|
-
takerAuthority: PublicKey,
|
|
17
|
-
orderHasBuilder: boolean,
|
|
18
|
-
takerEscrow?: RevenueShareEscrowAccount,
|
|
19
|
-
takerIsReferred?: boolean
|
|
20
|
-
) => { pubkey: PublicKey; isWritable: boolean; isSigner: boolean } | undefined;
|
|
21
|
-
|
|
22
|
-
const programId = Keypair.generate().publicKey;
|
|
23
|
-
const ctx = { program: { programId } };
|
|
24
|
-
const escrow = (
|
|
25
|
-
authority: PublicKey,
|
|
26
|
-
referrer: PublicKey
|
|
27
|
-
): RevenueShareEscrowAccount =>
|
|
28
|
-
({ authority, referrer }) as unknown as RevenueShareEscrowAccount;
|
|
29
|
-
|
|
30
|
-
describe('getTakerEscrowAccountMeta (fill escrow attachment)', () => {
|
|
31
|
-
test('takerIsReferred, order without builder -> escrow attached', () => {
|
|
32
|
-
const authority = Keypair.generate().publicKey;
|
|
33
|
-
const meta = getTakerEscrowAccountMeta.call(
|
|
34
|
-
ctx,
|
|
35
|
-
authority,
|
|
36
|
-
false,
|
|
37
|
-
undefined,
|
|
38
|
-
true
|
|
39
|
-
);
|
|
40
|
-
expect(meta).toBeDefined();
|
|
41
|
-
expect(
|
|
42
|
-
meta!.pubkey.equals(
|
|
43
|
-
getRevenueShareEscrowAccountPublicKey(programId, authority)
|
|
44
|
-
)
|
|
45
|
-
).toBe(true);
|
|
46
|
-
expect(meta!.isWritable).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('not referred, order without builder -> no escrow', () => {
|
|
50
|
-
const authority = Keypair.generate().publicKey;
|
|
51
|
-
expect(
|
|
52
|
-
getTakerEscrowAccountMeta.call(ctx, authority, false, undefined, false)
|
|
53
|
-
).toBeUndefined();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('builder-code order attaches escrow (no referral signal needed)', () => {
|
|
57
|
-
const authority = Keypair.generate().publicKey;
|
|
58
|
-
const meta = getTakerEscrowAccountMeta.call(
|
|
59
|
-
ctx,
|
|
60
|
-
authority,
|
|
61
|
-
true,
|
|
62
|
-
undefined
|
|
63
|
-
);
|
|
64
|
-
expect(meta).toBeDefined();
|
|
65
|
-
expect(
|
|
66
|
-
meta!.pubkey.equals(
|
|
67
|
-
getRevenueShareEscrowAccountPublicKey(programId, authority)
|
|
68
|
-
)
|
|
69
|
-
).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('decoded escrow with a referrer still attaches (back-compat)', () => {
|
|
73
|
-
const authority = Keypair.generate().publicKey;
|
|
74
|
-
const meta = getTakerEscrowAccountMeta.call(
|
|
75
|
-
ctx,
|
|
76
|
-
authority,
|
|
77
|
-
false,
|
|
78
|
-
escrow(authority, Keypair.generate().publicKey)
|
|
79
|
-
);
|
|
80
|
-
expect(meta).toBeDefined();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('escrow belonging to a different authority is rejected', () => {
|
|
84
|
-
const authority = Keypair.generate().publicKey;
|
|
85
|
-
const wrong = escrow(
|
|
86
|
-
Keypair.generate().publicKey,
|
|
87
|
-
Keypair.generate().publicKey
|
|
88
|
-
);
|
|
89
|
-
expect(() =>
|
|
90
|
-
getTakerEscrowAccountMeta.call(ctx, authority, false, wrong)
|
|
91
|
-
).toThrow();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Guards the referral bit ReferrerMap reads out of the taker's UserStats — the
|
|
96
|
-
// signal the fillers pass to getFillPerpOrderIx. Locks the `referrer_status`
|
|
97
|
-
// byte offset (188) and the BuilderReferral bit (0b100).
|
|
98
|
-
describe('ReferrerMap.mustGetIsBuilderReferral', () => {
|
|
99
|
-
const REFERRER_STATUS_OFFSET = 188;
|
|
100
|
-
const statsBuffer = (referrerStatus: number): Buffer => {
|
|
101
|
-
const buf = Buffer.alloc(REFERRER_STATUS_OFFSET + 8);
|
|
102
|
-
buf[REFERRER_STATUS_OFFSET] = referrerStatus;
|
|
103
|
-
return buf;
|
|
104
|
-
};
|
|
105
|
-
const fakeClient = (buf: Buffer | null) =>
|
|
106
|
-
({
|
|
107
|
-
program: { programId: Keypair.generate().publicKey },
|
|
108
|
-
connection: { getAccountInfo: async () => (buf ? { data: buf } : null) },
|
|
109
|
-
}) as any;
|
|
110
|
-
const authority = () => Keypair.generate().publicKey.toBase58();
|
|
111
|
-
|
|
112
|
-
test('BuilderReferral bit set -> true', async () => {
|
|
113
|
-
const map = new ReferrerMap(fakeClient(statsBuffer(0b100)));
|
|
114
|
-
expect(await map.mustGetIsBuilderReferral(authority())).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('IsReferred without BuilderReferral -> false', async () => {
|
|
118
|
-
const map = new ReferrerMap(fakeClient(statsBuffer(0b010)));
|
|
119
|
-
expect(await map.mustGetIsBuilderReferral(authority())).toBe(false);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { VelocityCore } from '../../src/core/VelocityCore';
|
|
3
|
-
import { userAccountBufferStrings } from '../decode/userAccountBufferStrings';
|
|
4
|
-
|
|
5
|
-
describe('VelocityCore decoding', () => {
|
|
6
|
-
test('can decode User account from fixture buffer', () => {
|
|
7
|
-
const s = userAccountBufferStrings[0];
|
|
8
|
-
const buf = Buffer.from(s, 'base64');
|
|
9
|
-
const decoded = VelocityCore.decodeUserAccount(buf);
|
|
10
|
-
|
|
11
|
-
expect(decoded).toBeTruthy();
|
|
12
|
-
expect(decoded.authority).toBeTruthy();
|
|
13
|
-
expect(decoded.delegate).toBeTruthy();
|
|
14
|
-
expect(decoded.name).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Keypair } from '@solana/web3.js';
|
|
3
|
-
import { VelocityCore } from '../../src/core/VelocityCore';
|
|
4
|
-
|
|
5
|
-
describe('VelocityCore fill/trigger builders', () => {
|
|
6
|
-
test('buildFillPerpOrderInstruction wires accounts + args', async () => {
|
|
7
|
-
const called: any[] = [];
|
|
8
|
-
const fakeIx = {
|
|
9
|
-
keys: [],
|
|
10
|
-
programId: Keypair.generate().publicKey,
|
|
11
|
-
data: Buffer.alloc(0),
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const program = {
|
|
15
|
-
instruction: {
|
|
16
|
-
fillPerpOrder: async (...args: any[]) => {
|
|
17
|
-
called.push(args);
|
|
18
|
-
return fakeIx;
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
const pk = () => Keypair.generate().publicKey;
|
|
23
|
-
|
|
24
|
-
const ix = await VelocityCore.buildFillPerpOrderInstruction({
|
|
25
|
-
program,
|
|
26
|
-
orderId: 7,
|
|
27
|
-
state: pk(),
|
|
28
|
-
filler: pk(),
|
|
29
|
-
fillerStats: pk(),
|
|
30
|
-
user: pk(),
|
|
31
|
-
userStats: pk(),
|
|
32
|
-
authority: pk(),
|
|
33
|
-
remainingAccounts: [],
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(ix).toBe(fakeIx as any);
|
|
37
|
-
expect(called.length).toBe(1);
|
|
38
|
-
expect(called[0][0]).toBe(7);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('buildTriggerOrderInstruction wires accounts + args', async () => {
|
|
42
|
-
const called: any[] = [];
|
|
43
|
-
const fakeIx = {
|
|
44
|
-
keys: [],
|
|
45
|
-
programId: Keypair.generate().publicKey,
|
|
46
|
-
data: Buffer.alloc(0),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const program = {
|
|
50
|
-
instruction: {
|
|
51
|
-
triggerOrder: async (...args: any[]) => {
|
|
52
|
-
called.push(args);
|
|
53
|
-
return fakeIx;
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
const pk = () => Keypair.generate().publicKey;
|
|
58
|
-
|
|
59
|
-
const ix = await VelocityCore.buildTriggerOrderInstruction({
|
|
60
|
-
program,
|
|
61
|
-
orderId: 9,
|
|
62
|
-
state: pk(),
|
|
63
|
-
filler: pk(),
|
|
64
|
-
user: pk(),
|
|
65
|
-
authority: pk(),
|
|
66
|
-
remainingAccounts: [],
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(ix).toBe(fakeIx as any);
|
|
70
|
-
expect(called.length).toBe(1);
|
|
71
|
-
expect(called[0][0]).toBe(9);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { VelocityCore } from '../../src/core/VelocityCore';
|
|
3
|
-
import { Keypair } from '@solana/web3.js';
|
|
4
|
-
import { BN } from '../../src/isomorphic/anchor';
|
|
5
|
-
|
|
6
|
-
describe('VelocityCore instruction builders', () => {
|
|
7
|
-
test('buildDepositInstruction calls underlying program.deposit', async () => {
|
|
8
|
-
const called: any[] = [];
|
|
9
|
-
const fakeIx = {
|
|
10
|
-
keys: [],
|
|
11
|
-
programId: Keypair.generate().publicKey,
|
|
12
|
-
data: Buffer.alloc(0),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const program = {
|
|
16
|
-
instruction: {
|
|
17
|
-
deposit: async (...args: any[]) => {
|
|
18
|
-
called.push(args);
|
|
19
|
-
return fakeIx;
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const pk = () => Keypair.generate().publicKey;
|
|
25
|
-
|
|
26
|
-
const ix = await VelocityCore.buildDepositInstruction({
|
|
27
|
-
program,
|
|
28
|
-
marketIndex: 1,
|
|
29
|
-
amount: new BN(123),
|
|
30
|
-
reduceOnly: false,
|
|
31
|
-
state: pk(),
|
|
32
|
-
spotMarket: pk(),
|
|
33
|
-
spotMarketVault: pk(),
|
|
34
|
-
user: pk(),
|
|
35
|
-
userStats: pk(),
|
|
36
|
-
userTokenAccount: pk(),
|
|
37
|
-
authority: pk(),
|
|
38
|
-
tokenProgram: pk(),
|
|
39
|
-
remainingAccounts: [],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
expect(ix).toBe(fakeIx as any);
|
|
43
|
-
expect(called.length).toBe(1);
|
|
44
|
-
expect(called[0][0]).toBe(1);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Keypair, PublicKey } from '@solana/web3.js';
|
|
3
|
-
import { VelocityCore } from '../../src/core/VelocityCore';
|
|
4
|
-
|
|
5
|
-
describe('VelocityCore.pdas', () => {
|
|
6
|
-
test('derives deterministic user/state PDAs', async () => {
|
|
7
|
-
const programId = Keypair.generate().publicKey;
|
|
8
|
-
const authority = Keypair.generate().publicKey;
|
|
9
|
-
|
|
10
|
-
const [state] =
|
|
11
|
-
await VelocityCore.pdas.getVelocityStateAccountPublicKeyAndNonce(
|
|
12
|
-
programId
|
|
13
|
-
);
|
|
14
|
-
const user0 = await VelocityCore.pdas.getUserAccountPublicKey(
|
|
15
|
-
programId,
|
|
16
|
-
authority,
|
|
17
|
-
0
|
|
18
|
-
);
|
|
19
|
-
const user1 = await VelocityCore.pdas.getUserAccountPublicKey(
|
|
20
|
-
programId,
|
|
21
|
-
authority,
|
|
22
|
-
1
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
expect(state).toBeInstanceOf(PublicKey);
|
|
26
|
-
expect(user0).toBeInstanceOf(PublicKey);
|
|
27
|
-
expect(user1).toBeInstanceOf(PublicKey);
|
|
28
|
-
expect(user0.toBase58()).not.toEqual(user1.toBase58());
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Keypair } from '@solana/web3.js';
|
|
3
|
-
import { VelocityCore } from '../../src/core/VelocityCore';
|
|
4
|
-
|
|
5
|
-
describe('VelocityCore perp order instruction builders', () => {
|
|
6
|
-
const pk = () => Keypair.generate().publicKey;
|
|
7
|
-
const fakeIx = {
|
|
8
|
-
keys: [],
|
|
9
|
-
programId: Keypair.generate().publicKey,
|
|
10
|
-
data: Buffer.alloc(0),
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
test('buildPlacePerpOrderInstruction', async () => {
|
|
14
|
-
const called: any[] = [];
|
|
15
|
-
const program = {
|
|
16
|
-
instruction: {
|
|
17
|
-
placePerpOrder: async (...args: any[]) => {
|
|
18
|
-
called.push(args);
|
|
19
|
-
return fakeIx;
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const ix = await VelocityCore.buildPlacePerpOrderInstruction({
|
|
24
|
-
program,
|
|
25
|
-
orderParams: { x: 1 },
|
|
26
|
-
state: pk(),
|
|
27
|
-
user: pk(),
|
|
28
|
-
userStats: pk(),
|
|
29
|
-
authority: pk(),
|
|
30
|
-
remainingAccounts: [],
|
|
31
|
-
});
|
|
32
|
-
expect(ix).toBe(fakeIx as any);
|
|
33
|
-
expect(called[0][0]).toEqual({ x: 1 });
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('buildPlaceAndTakePerpOrderInstruction', async () => {
|
|
37
|
-
const called: any[] = [];
|
|
38
|
-
const program = {
|
|
39
|
-
instruction: {
|
|
40
|
-
placeAndTakePerpOrder: async (...args: any[]) => {
|
|
41
|
-
called.push(args);
|
|
42
|
-
return fakeIx;
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
const ix = await VelocityCore.buildPlaceAndTakePerpOrderInstruction({
|
|
47
|
-
program,
|
|
48
|
-
orderParams: { m: 0 },
|
|
49
|
-
optionalParams: 256,
|
|
50
|
-
state: pk(),
|
|
51
|
-
user: pk(),
|
|
52
|
-
userStats: pk(),
|
|
53
|
-
authority: pk(),
|
|
54
|
-
remainingAccounts: [],
|
|
55
|
-
});
|
|
56
|
-
expect(ix).toBe(fakeIx as any);
|
|
57
|
-
expect(called[0][1]).toBe(256);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('buildPlaceAndMakePerpOrderInstruction', async () => {
|
|
61
|
-
const called: any[] = [];
|
|
62
|
-
const program = {
|
|
63
|
-
instruction: {
|
|
64
|
-
placeAndMakePerpOrder: async (...args: any[]) => {
|
|
65
|
-
called.push(args);
|
|
66
|
-
return fakeIx;
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
const ix = await VelocityCore.buildPlaceAndMakePerpOrderInstruction({
|
|
71
|
-
program,
|
|
72
|
-
orderParams: {},
|
|
73
|
-
takerOrderId: 7,
|
|
74
|
-
state: pk(),
|
|
75
|
-
user: pk(),
|
|
76
|
-
userStats: pk(),
|
|
77
|
-
taker: pk(),
|
|
78
|
-
takerStats: pk(),
|
|
79
|
-
authority: pk(),
|
|
80
|
-
remainingAccounts: [],
|
|
81
|
-
});
|
|
82
|
-
expect(ix).toBe(fakeIx as any);
|
|
83
|
-
expect(called[0][1]).toBe(7);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('buildCancelOrderInstruction', async () => {
|
|
87
|
-
const called: any[] = [];
|
|
88
|
-
const program = {
|
|
89
|
-
instruction: {
|
|
90
|
-
cancelOrder: async (...args: any[]) => {
|
|
91
|
-
called.push(args);
|
|
92
|
-
return fakeIx;
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
const ix = await VelocityCore.buildCancelOrderInstruction({
|
|
97
|
-
program,
|
|
98
|
-
orderId: 3,
|
|
99
|
-
state: pk(),
|
|
100
|
-
user: pk(),
|
|
101
|
-
authority: pk(),
|
|
102
|
-
remainingAccounts: [],
|
|
103
|
-
});
|
|
104
|
-
expect(ix).toBe(fakeIx as any);
|
|
105
|
-
expect(called[0][0]).toBe(3);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('buildCancelOrderByUserIdInstruction', async () => {
|
|
109
|
-
const called: any[] = [];
|
|
110
|
-
const program = {
|
|
111
|
-
instruction: {
|
|
112
|
-
cancelOrderByUserId: async (...args: any[]) => {
|
|
113
|
-
called.push(args);
|
|
114
|
-
return fakeIx;
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
const ix = await VelocityCore.buildCancelOrderByUserIdInstruction({
|
|
119
|
-
program,
|
|
120
|
-
userOrderId: 9,
|
|
121
|
-
state: pk(),
|
|
122
|
-
user: pk(),
|
|
123
|
-
authority: pk(),
|
|
124
|
-
oracle: pk(),
|
|
125
|
-
remainingAccounts: [],
|
|
126
|
-
});
|
|
127
|
-
expect(ix).toBe(fakeIx as any);
|
|
128
|
-
expect(called[0][0]).toBe(9);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('buildCancelOrdersByIdsInstruction', async () => {
|
|
132
|
-
const called: any[] = [];
|
|
133
|
-
const program = {
|
|
134
|
-
instruction: {
|
|
135
|
-
cancelOrdersByIds: async (...args: any[]) => {
|
|
136
|
-
called.push(args);
|
|
137
|
-
return fakeIx;
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
const ids = [1, 2];
|
|
142
|
-
const ix = await VelocityCore.buildCancelOrdersByIdsInstruction({
|
|
143
|
-
program,
|
|
144
|
-
orderIds: ids,
|
|
145
|
-
state: pk(),
|
|
146
|
-
user: pk(),
|
|
147
|
-
authority: pk(),
|
|
148
|
-
remainingAccounts: [],
|
|
149
|
-
});
|
|
150
|
-
expect(ix).toBe(fakeIx as any);
|
|
151
|
-
expect(called[0][0]).toBe(ids);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('buildModifyOrderInstruction', async () => {
|
|
155
|
-
const called: any[] = [];
|
|
156
|
-
const program = {
|
|
157
|
-
instruction: {
|
|
158
|
-
modifyOrder: async (...args: any[]) => {
|
|
159
|
-
called.push(args);
|
|
160
|
-
return fakeIx;
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
const mp = { baseAssetAmount: null };
|
|
165
|
-
const ix = await VelocityCore.buildModifyOrderInstruction({
|
|
166
|
-
program,
|
|
167
|
-
orderId: 4,
|
|
168
|
-
modifyParams: mp,
|
|
169
|
-
state: pk(),
|
|
170
|
-
user: pk(),
|
|
171
|
-
userStats: pk(),
|
|
172
|
-
authority: pk(),
|
|
173
|
-
remainingAccounts: [],
|
|
174
|
-
});
|
|
175
|
-
expect(ix).toBe(fakeIx as any);
|
|
176
|
-
expect(called[0][0]).toBe(4);
|
|
177
|
-
expect(called[0][1]).toBe(mp);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('buildModifyOrderByUserIdInstruction', async () => {
|
|
181
|
-
const called: any[] = [];
|
|
182
|
-
const program = {
|
|
183
|
-
instruction: {
|
|
184
|
-
modifyOrderByUserId: async (...args: any[]) => {
|
|
185
|
-
called.push(args);
|
|
186
|
-
return fakeIx;
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
const mp = { reduceOnly: false };
|
|
191
|
-
const ix = await VelocityCore.buildModifyOrderByUserIdInstruction({
|
|
192
|
-
program,
|
|
193
|
-
userOrderId: 11,
|
|
194
|
-
modifyParams: mp,
|
|
195
|
-
state: pk(),
|
|
196
|
-
user: pk(),
|
|
197
|
-
userStats: pk(),
|
|
198
|
-
authority: pk(),
|
|
199
|
-
remainingAccounts: [],
|
|
200
|
-
});
|
|
201
|
-
expect(ix).toBe(fakeIx as any);
|
|
202
|
-
expect(called[0][0]).toBe(11);
|
|
203
|
-
expect(called[0][1]).toBe(mp);
|
|
204
|
-
});
|
|
205
|
-
});
|