@velocity-exchange/sdk 0.4.0 → 0.6.0

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.
Files changed (323) hide show
  1. package/README.md +3 -3
  2. package/lib/browser/adminClient.d.ts +35 -0
  3. package/lib/browser/adminClient.js +65 -0
  4. package/lib/browser/config.js +6 -7
  5. package/lib/browser/constants/numericConstants.d.ts +1 -1
  6. package/lib/browser/constants/numericConstants.js +1 -1
  7. package/lib/browser/decode/user.js +5 -1
  8. package/lib/browser/idl/velocity.d.ts +146 -3
  9. package/lib/browser/idl/velocity.json +147 -4
  10. package/lib/browser/orderSubscriber/OrderSubscriber.js +3 -0
  11. package/lib/browser/pyth/pythLazerSubscriber.js +37 -27
  12. package/lib/browser/types.d.ts +4 -0
  13. package/lib/browser/user.d.ts +15 -0
  14. package/lib/browser/user.js +37 -1
  15. package/lib/browser/velocityClient.d.ts +46 -10
  16. package/lib/browser/velocityClient.js +107 -35
  17. package/lib/node/adminClient.d.ts +35 -0
  18. package/lib/node/adminClient.d.ts.map +1 -1
  19. package/lib/node/adminClient.js +65 -0
  20. package/lib/node/config.d.ts.map +1 -1
  21. package/lib/node/config.js +6 -7
  22. package/lib/node/constants/numericConstants.d.ts +1 -1
  23. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  24. package/lib/node/constants/numericConstants.js +1 -1
  25. package/lib/node/decode/user.d.ts.map +1 -1
  26. package/lib/node/decode/user.js +5 -1
  27. package/lib/node/idl/velocity.d.ts +146 -3
  28. package/lib/node/idl/velocity.d.ts.map +1 -1
  29. package/lib/node/idl/velocity.json +147 -4
  30. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  31. package/lib/node/orderSubscriber/OrderSubscriber.js +3 -0
  32. package/lib/node/pyth/pythLazerSubscriber.d.ts.map +1 -1
  33. package/lib/node/pyth/pythLazerSubscriber.js +37 -27
  34. package/lib/node/types.d.ts +4 -0
  35. package/lib/node/types.d.ts.map +1 -1
  36. package/lib/node/user.d.ts +15 -0
  37. package/lib/node/user.d.ts.map +1 -1
  38. package/lib/node/user.js +37 -1
  39. package/lib/node/velocityClient.d.ts +46 -10
  40. package/lib/node/velocityClient.d.ts.map +1 -1
  41. package/lib/node/velocityClient.js +107 -35
  42. package/package.json +7 -3
  43. package/.prettierignore +0 -1
  44. package/CHANGELOG.md +0 -132
  45. package/build-browser.js +0 -58
  46. package/bunfig.toml +0 -3
  47. package/esbuild-shims.js +0 -12
  48. package/scripts/deposit-isolated-positions.ts +0 -110
  49. package/scripts/find-flagged-users.ts +0 -213
  50. package/scripts/grpc-client-test-comparison.ts +0 -372
  51. package/scripts/grpc-multiuser-client-test-comparison.ts +0 -158
  52. package/scripts/postbuild.js +0 -95
  53. package/scripts/single-grpc-client-test.ts +0 -284
  54. package/scripts/withdraw-isolated-positions.ts +0 -174
  55. package/src/accounts/README_WebSocketAccountSubscriberV2.md +0 -95
  56. package/src/accounts/README_WebSocketProgramAccountSubscriberV2.md +0 -135
  57. package/src/accounts/basicUserAccountSubscriber.ts +0 -79
  58. package/src/accounts/basicUserStatsAccountSubscriber.ts +0 -87
  59. package/src/accounts/bulkAccountLoader.ts +0 -358
  60. package/src/accounts/bulkUserStatsSubscription.ts +0 -40
  61. package/src/accounts/bulkUserSubscription.ts +0 -39
  62. package/src/accounts/customizedCadenceBulkAccountLoader.ts +0 -250
  63. package/src/accounts/fetch.ts +0 -200
  64. package/src/accounts/grpcAccountSubscriber.ts +0 -225
  65. package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +0 -73
  66. package/src/accounts/grpcMultiAccountSubscriber.ts +0 -566
  67. package/src/accounts/grpcMultiUserAccountSubscriber.ts +0 -328
  68. package/src/accounts/grpcProgramAccountSubscriber.ts +0 -264
  69. package/src/accounts/grpcUserAccountSubscriber.ts +0 -63
  70. package/src/accounts/grpcUserStatsAccountSubscriber.ts +0 -65
  71. package/src/accounts/grpcVelocityClientAccountSubscriber.ts +0 -257
  72. package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +0 -941
  73. package/src/accounts/laserProgramAccountSubscriber.ts +0 -266
  74. package/src/accounts/oneShotUserAccountSubscriber.ts +0 -88
  75. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +0 -94
  76. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +0 -223
  77. package/src/accounts/pollingOracleAccountSubscriber.ts +0 -151
  78. package/src/accounts/pollingTokenAccountSubscriber.ts +0 -147
  79. package/src/accounts/pollingUserAccountSubscriber.ts +0 -198
  80. package/src/accounts/pollingUserStatsAccountSubscriber.ts +0 -180
  81. package/src/accounts/pollingVelocityClientAccountSubscriber.ts +0 -774
  82. package/src/accounts/testBulkAccountLoader.ts +0 -59
  83. package/src/accounts/types.ts +0 -428
  84. package/src/accounts/utils.ts +0 -90
  85. package/src/accounts/webSocketAccountSubscriber.ts +0 -304
  86. package/src/accounts/webSocketAccountSubscriberV2.ts +0 -536
  87. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +0 -171
  88. package/src/accounts/webSocketProgramAccountSubscriber.ts +0 -244
  89. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +0 -1048
  90. package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +0 -1042
  91. package/src/accounts/webSocketUserAccountSubscriber.ts +0 -139
  92. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +0 -131
  93. package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +0 -865
  94. package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +0 -897
  95. package/src/accounts/websocketProgramUserAccountSubscriber.ts +0 -127
  96. package/src/addresses/marketAddresses.ts +0 -28
  97. package/src/addresses/pda.ts +0 -620
  98. package/src/adminClient.ts +0 -8136
  99. package/src/assert/assert.ts +0 -5
  100. package/src/auctionSubscriber/auctionSubscriber.ts +0 -86
  101. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +0 -99
  102. package/src/auctionSubscriber/index.ts +0 -9
  103. package/src/auctionSubscriber/types.ts +0 -30
  104. package/src/bankrun/bankrunConnection.ts +0 -630
  105. package/src/blockhashSubscriber/BlockhashSubscriber.ts +0 -160
  106. package/src/blockhashSubscriber/index.ts +0 -6
  107. package/src/blockhashSubscriber/types.ts +0 -13
  108. package/src/clock/clockSubscriber.ts +0 -146
  109. package/src/config.ts +0 -312
  110. package/src/constants/index.ts +0 -9
  111. package/src/constants/numericConstants.ts +0 -194
  112. package/src/constants/perpMarkets.ts +0 -127
  113. package/src/constants/spotMarkets.ts +0 -104
  114. package/src/constants/txConstants.ts +0 -2
  115. package/src/constituentMap/constituentMap.ts +0 -305
  116. package/src/constituentMap/pollingConstituentAccountSubscriber.ts +0 -99
  117. package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +0 -121
  118. package/src/core/VelocityCore.ts +0 -606
  119. package/src/core/index.ts +0 -12
  120. package/src/core/instructions/deposit.ts +0 -64
  121. package/src/core/instructions/fill.ts +0 -51
  122. package/src/core/instructions/funding.ts +0 -33
  123. package/src/core/instructions/liquidation.ts +0 -55
  124. package/src/core/instructions/orders.ts +0 -84
  125. package/src/core/instructions/perpOrders.ts +0 -312
  126. package/src/core/instructions/settlement.ts +0 -40
  127. package/src/core/instructions/trigger.ts +0 -41
  128. package/src/core/instructions/withdraw.ts +0 -65
  129. package/src/core/remainingAccounts.ts +0 -320
  130. package/src/core/signedMsg.ts +0 -109
  131. package/src/decode/customCoder.ts +0 -148
  132. package/src/decode/user.ts +0 -401
  133. package/src/dlob/DLOB.ts +0 -2793
  134. package/src/dlob/DLOBNode.ts +0 -305
  135. package/src/dlob/DLOBSubscriber.ts +0 -269
  136. package/src/dlob/NodeList.ts +0 -244
  137. package/src/dlob/orderBookLevels.ts +0 -695
  138. package/src/dlob/types.ts +0 -37
  139. package/src/events/eventList.ts +0 -114
  140. package/src/events/eventSubscriber.ts +0 -521
  141. package/src/events/eventsServerLogProvider.ts +0 -189
  142. package/src/events/fetchLogs.ts +0 -219
  143. package/src/events/parse.ts +0 -271
  144. package/src/events/pollingLogProvider.ts +0 -113
  145. package/src/events/sort.ts +0 -51
  146. package/src/events/txEventCache.ts +0 -92
  147. package/src/events/types.ts +0 -337
  148. package/src/events/webSocketLogProvider.ts +0 -152
  149. package/src/factory/bigNum.ts +0 -709
  150. package/src/factory/oracleClient.ts +0 -73
  151. package/src/idl/pyth.json +0 -142
  152. package/src/idl/pyth.ts +0 -97
  153. package/src/idl/pyth_solana_receiver.json +0 -628
  154. package/src/idl/token_faucet.json +0 -229
  155. package/src/idl/token_faucet.ts +0 -197
  156. package/src/idl/velocity.json +0 -23974
  157. package/src/idl/velocity.ts +0 -23980
  158. package/src/index.ts +0 -150
  159. package/src/indicative-quotes/indicativeQuotesSender.ts +0 -233
  160. package/src/isomorphic/README.md +0 -19
  161. package/src/isomorphic/anchor.browser.ts +0 -44
  162. package/src/isomorphic/anchor.node.ts +0 -1
  163. package/src/isomorphic/anchor.ts +0 -1
  164. package/src/isomorphic/anchor29.browser.ts +0 -24
  165. package/src/isomorphic/anchor29.node.ts +0 -1
  166. package/src/isomorphic/anchor29.ts +0 -1
  167. package/src/isomorphic/grpc.browser.ts +0 -4
  168. package/src/isomorphic/grpc.node.ts +0 -130
  169. package/src/isomorphic/grpc.ts +0 -1
  170. package/src/jupiter/jupiterClient.ts +0 -502
  171. package/src/keypair.ts +0 -32
  172. package/src/margin/README.md +0 -138
  173. package/src/marginCalculation.ts +0 -407
  174. package/src/marinade/idl/idl.json +0 -1962
  175. package/src/marinade/index.ts +0 -73
  176. package/src/marinade/types.ts +0 -3925
  177. package/src/math/amm.ts +0 -1758
  178. package/src/math/auction.ts +0 -480
  179. package/src/math/bankruptcy.ts +0 -138
  180. package/src/math/builder.ts +0 -130
  181. package/src/math/conversion.ts +0 -45
  182. package/src/math/exchangeStatus.ts +0 -261
  183. package/src/math/funding.ts +0 -498
  184. package/src/math/insurance.ts +0 -171
  185. package/src/math/liquidation.ts +0 -433
  186. package/src/math/margin.ts +0 -327
  187. package/src/math/market.ts +0 -487
  188. package/src/math/oracles.ts +0 -477
  189. package/src/math/orders.ts +0 -500
  190. package/src/math/position.ts +0 -381
  191. package/src/math/repeg.ts +0 -223
  192. package/src/math/spotBalance.ts +0 -996
  193. package/src/math/spotMarket.ts +0 -115
  194. package/src/math/spotPosition.ts +0 -263
  195. package/src/math/state.ts +0 -71
  196. package/src/math/superStake.ts +0 -602
  197. package/src/math/tiers.ts +0 -73
  198. package/src/math/trade.ts +0 -879
  199. package/src/math/utils.ts +0 -183
  200. package/src/memcmp.ts +0 -279
  201. package/src/oracles/oracleClientCache.ts +0 -41
  202. package/src/oracles/oracleId.ts +0 -99
  203. package/src/oracles/prelaunchOracleClient.ts +0 -63
  204. package/src/oracles/pythClient.ts +0 -125
  205. package/src/oracles/pythLazerClient.ts +0 -141
  206. package/src/oracles/quoteAssetOracleClient.ts +0 -43
  207. package/src/oracles/strictOraclePrice.ts +0 -40
  208. package/src/oracles/types.ts +0 -82
  209. package/src/oracles/utils.ts +0 -45
  210. package/src/orderParams.ts +0 -117
  211. package/src/orderSubscriber/OrderSubscriber.ts +0 -378
  212. package/src/orderSubscriber/PollingSubscription.ts +0 -50
  213. package/src/orderSubscriber/WebsocketSubscription.ts +0 -137
  214. package/src/orderSubscriber/grpcSubscription.ts +0 -155
  215. package/src/orderSubscriber/index.ts +0 -7
  216. package/src/orderSubscriber/types.ts +0 -64
  217. package/src/priorityFee/averageOverSlotsStrategy.ts +0 -17
  218. package/src/priorityFee/averageStrategy.ts +0 -13
  219. package/src/priorityFee/ewmaStrategy.ts +0 -51
  220. package/src/priorityFee/heliusPriorityFeeMethod.ts +0 -68
  221. package/src/priorityFee/index.ts +0 -16
  222. package/src/priorityFee/maxOverSlotsStrategy.ts +0 -18
  223. package/src/priorityFee/maxStrategy.ts +0 -8
  224. package/src/priorityFee/priorityFeeSubscriber.ts +0 -328
  225. package/src/priorityFee/priorityFeeSubscriberMap.ts +0 -134
  226. package/src/priorityFee/solanaPriorityFeeMethod.ts +0 -46
  227. package/src/priorityFee/types.ts +0 -82
  228. package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -53
  229. package/src/pyth/constants.ts +0 -9
  230. package/src/pyth/index.ts +0 -15
  231. package/src/pyth/pythLazerSubscriber.ts +0 -365
  232. package/src/pyth/types.ts +0 -4451
  233. package/src/pyth/utils.ts +0 -13
  234. package/src/slot/SlotSubscriber.ts +0 -126
  235. package/src/slot/SlothashSubscriber.ts +0 -163
  236. package/src/swap/UnifiedSwapClient.ts +0 -315
  237. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +0 -81
  238. package/src/swift/index.ts +0 -10
  239. package/src/swift/signedMsgUserAccountSubscriber.ts +0 -251
  240. package/src/swift/swiftOrderSubscriber.ts +0 -351
  241. package/src/testClient.ts +0 -42
  242. package/src/titan/titanClient.ts +0 -438
  243. package/src/token/index.ts +0 -13
  244. package/src/tokenFaucet.ts +0 -296
  245. package/src/tx/baseTxSender.ts +0 -651
  246. package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +0 -31
  247. package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +0 -105
  248. package/src/tx/blockhashFetcher/types.ts +0 -9
  249. package/src/tx/fastSingleTxSender.ts +0 -200
  250. package/src/tx/forwardOnlyTxSender.ts +0 -193
  251. package/src/tx/priorityFeeCalculator.ts +0 -117
  252. package/src/tx/reportTransactionError.ts +0 -176
  253. package/src/tx/retryTxSender.ts +0 -177
  254. package/src/tx/txHandler.ts +0 -1009
  255. package/src/tx/txParamProcessor.ts +0 -225
  256. package/src/tx/types.ts +0 -117
  257. package/src/tx/utils.ts +0 -133
  258. package/src/tx/whileValidTxSender.ts +0 -377
  259. package/src/types.ts +0 -2575
  260. package/src/user.ts +0 -5316
  261. package/src/userConfig.ts +0 -38
  262. package/src/userMap/PollingSubscription.ts +0 -61
  263. package/src/userMap/WebsocketSubscription.ts +0 -93
  264. package/src/userMap/grpcSubscription.ts +0 -93
  265. package/src/userMap/referrerMap.ts +0 -360
  266. package/src/userMap/revenueShareEscrowMap.ts +0 -342
  267. package/src/userMap/userMap.ts +0 -784
  268. package/src/userMap/userMapConfig.ts +0 -82
  269. package/src/userMap/userStatsMap.ts +0 -393
  270. package/src/userName.ts +0 -37
  271. package/src/userStats.ts +0 -159
  272. package/src/userStatsConfig.ts +0 -35
  273. package/src/util/TransactionConfirmationManager.ts +0 -333
  274. package/src/util/chainClock.ts +0 -65
  275. package/src/util/computeUnits.ts +0 -101
  276. package/src/util/digest.ts +0 -33
  277. package/src/util/ed25519Utils.ts +0 -95
  278. package/src/util/promiseTimeout.ts +0 -23
  279. package/src/velocityClient.ts +0 -14802
  280. package/src/velocityClientConfig.ts +0 -119
  281. package/src/wallet.ts +0 -91
  282. package/tests/VelocityCore/builder_escrow.test.ts +0 -121
  283. package/tests/VelocityCore/decode.test.ts +0 -16
  284. package/tests/VelocityCore/fill_trigger.test.ts +0 -73
  285. package/tests/VelocityCore/instructions.test.ts +0 -46
  286. package/tests/VelocityCore/pdas.test.ts +0 -30
  287. package/tests/VelocityCore/perp_orders.test.ts +0 -205
  288. package/tests/VelocityCore/remainingAccounts.test.ts +0 -72
  289. package/tests/VelocityCore/settlement_liquidation.test.ts +0 -69
  290. package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +0 -211
  291. package/tests/amm/test.ts +0 -2402
  292. package/tests/auctions/test.ts +0 -81
  293. package/tests/bn/test.ts +0 -355
  294. package/tests/builder/builderFee.test.ts +0 -42
  295. package/tests/ci/verifyConstants.ts +0 -393
  296. package/tests/decode/test.ts +0 -262
  297. package/tests/decode/userAccountBufferStrings.ts +0 -102
  298. package/tests/dlob/helpers.ts +0 -748
  299. package/tests/dlob/test.ts +0 -6969
  300. package/tests/dlob/tickSizeStandardization.ts +0 -545
  301. package/tests/events/parseLogsForCuUsage.ts +0 -139
  302. package/tests/exchangeStatus/test.ts +0 -45
  303. package/tests/insurance/test.ts +0 -40
  304. package/tests/liquidation/test.ts +0 -125
  305. package/tests/oracles/mmOracleGate.test.ts +0 -379
  306. package/tests/oracles/pythPegSnap.test.ts +0 -76
  307. package/tests/sdkParity/enumParity.test.ts +0 -84
  308. package/tests/sdkParity/marginCategoryFill.test.ts +0 -143
  309. package/tests/sdkParity/memcmpOffsets.test.ts +0 -139
  310. package/tests/spot/test.ts +0 -281
  311. package/tests/tx/TransactionConfirmationManager.test.ts +0 -312
  312. package/tests/tx/cachedBlockhashFetcher.test.ts +0 -96
  313. package/tests/tx/priorityFeeCalculator.ts +0 -77
  314. package/tests/tx/priorityFeeStrategy.ts +0 -95
  315. package/tests/user/bankruptcy.ts +0 -165
  316. package/tests/user/feeAndWithdrawLimits.ts +0 -284
  317. package/tests/user/getMarginCalculation.ts +0 -586
  318. package/tests/user/helpers.ts +0 -184
  319. package/tests/user/liquidations.ts +0 -129
  320. package/tests/user/marginCalculations.test.ts +0 -321
  321. package/tests/user/test.ts +0 -833
  322. package/tsconfig.browser.json +0 -18
  323. package/tsconfig.json +0 -36
@@ -1,606 +0,0 @@
1
- import type {
2
- AccountMeta,
3
- Connection,
4
- PublicKey,
5
- TransactionInstruction,
6
- } from '@solana/web3.js';
7
-
8
- import * as pdas from '../addresses/pda';
9
- import * as constants from '../constants';
10
- import { decodeUser } from '../decode/user';
11
- import { CustomBorshCoder } from '../decode/customCoder';
12
- import velocityIDL from '../idl/velocity.json';
13
- import type { Velocity } from '../idl/velocity';
14
- import type { UserAccount } from '../types';
15
- import type { VelocityProgram } from '../config';
16
- import { fetchAccount } from '../accounts/fetch';
17
- import type { BN } from '@coral-xyz/anchor';
18
- import { buildDepositInstruction } from './instructions/deposit';
19
- import { buildWithdrawInstruction } from './instructions/withdraw';
20
- import {
21
- buildCancelOrdersInstruction,
22
- buildPlaceOrdersInstruction,
23
- } from './instructions/orders';
24
- import { buildFillPerpOrderInstruction } from './instructions/fill';
25
- import { buildTriggerOrderInstruction } from './instructions/trigger';
26
- import { buildSettlePnlInstruction } from './instructions/settlement';
27
- import { buildLiquidatePerpInstruction } from './instructions/liquidation';
28
- import { buildUpdateFundingRateInstruction } from './instructions/funding';
29
- import {
30
- buildCancelOrderByUserIdInstruction,
31
- buildCancelOrderInstruction,
32
- buildCancelOrdersByIdsInstruction,
33
- buildModifyOrderByUserIdInstruction,
34
- buildModifyOrderInstruction,
35
- buildPlaceAndMakePerpOrderInstruction,
36
- buildPlaceAndTakePerpOrderInstruction,
37
- buildPlacePerpOrderInstruction,
38
- } from './instructions/perpOrders';
39
- import * as remainingAccounts from './remainingAccounts';
40
- import * as signedMsg from './signedMsg';
41
-
42
- /**
43
- * Configuration passed to subscription-free `VelocityCore` helpers that need to know
44
- * which deployment (program id / IDL) they are building instructions against.
45
- */
46
- export type VelocityCoreContext = {
47
- /** Velocity program id. */
48
- programId: PublicKey;
49
-
50
- /** Anchor IDL json for Velocity (defaults to bundled `idl/velocity.json`). */
51
- idl?: Velocity;
52
- };
53
-
54
- /**
55
- * `VelocityCore` is the subscription-free escape hatch of the SDK: a static-method
56
- * surface for deriving PDAs, decoding raw account buffers, building `remainingAccounts`,
57
- * and constructing `TransactionInstruction`s directly against a `Program<Velocity>` —
58
- * with no `VelocityClient` subscription, polling, or websocket state required. Every
59
- * method here is pure (or a single RPC call) and safe to use from a stateless backend,
60
- * a keeper bot, or any context where the full subscribed client is overkill.
61
- *
62
- * Transaction/instruction builders will be progressively moved here from `VelocityClient`.
63
- */
64
- export class VelocityCore {
65
- /** Re-export of `../addresses/pda` — pure PDA derivation helpers (state, user, spot/perp market, vaults, etc). */
66
- static readonly pdas = pdas;
67
-
68
- /** Re-export of `../constants` — SDK-wide numeric precisions, market configs, and program constants. */
69
- static readonly constants = constants;
70
-
71
- /** Re-export of `./remainingAccounts` — pure builder for the oracle/market `AccountMeta[]` every trading/keeper instruction needs in `remainingAccounts`. */
72
- static readonly remainingAccounts = remainingAccounts;
73
-
74
- /** Re-export of `./signedMsg` — Borsh encode/decode helpers for Swift (signed order) message envelopes. */
75
- static readonly signedMsg = signedMsg;
76
-
77
- /** Returns the SDK's bundled Velocity Anchor IDL (`idl/velocity.json`), typed as `Velocity`. */
78
- static defaultIdl(): Velocity {
79
- return velocityIDL as unknown as Velocity;
80
- }
81
-
82
- /**
83
- * Builds a `CustomBorshCoder` for the given IDL, usable to encode/decode Anchor
84
- * account and type layouts without constructing a full `Program`.
85
- * @param idl - IDL to build the coder from. Defaults to `VelocityCore.defaultIdl()`.
86
- * @returns a coder that can (de)serialize any account/type defined in `idl`.
87
- */
88
- static coder(idl: Velocity = VelocityCore.defaultIdl()): CustomBorshCoder {
89
- return new CustomBorshCoder(idl as any);
90
- }
91
-
92
- /**
93
- * Decodes a raw Velocity `User` account buffer (including its 8-byte Anchor
94
- * discriminator) into a `UserAccount`, without needing a `Program` or RPC call.
95
- * Does not verify the discriminator — passing a buffer for a different account
96
- * type will produce garbage or throw from an out-of-bounds read.
97
- * @param buffer - raw on-chain account data for a `User` PDA.
98
- * @returns the decoded `UserAccount`.
99
- */
100
- static decodeUserAccount(buffer: Buffer): UserAccount {
101
- return decodeUser(buffer);
102
- }
103
-
104
- /**
105
- * Fetches a `User` account over RPC and decodes it, with no subscription required.
106
- * @param connection - RPC connection to fetch the account from.
107
- * @param userAccountPublicKey - the `User` PDA's address.
108
- * @returns the decoded `UserAccount`, or `null` if the account does not exist.
109
- */
110
- static async fetchUserAccount(
111
- connection: Connection,
112
- userAccountPublicKey: PublicKey
113
- ): Promise<UserAccount | null> {
114
- const data = await fetchAccount(connection, userAccountPublicKey);
115
- return data ? VelocityCore.decodeUserAccount(data) : null;
116
- }
117
-
118
- /**
119
- * Builds a `deposit` instruction, transferring tokens from `userTokenAccount` into
120
- * the protocol's `spotMarketVault` and crediting the `user` account's spot position.
121
- * Any signer may fund someone else's `user` account this way (`authority` need not be
122
- * `user`'s owner/delegate) — the SDK only requires `userTokenAccount` be owned by
123
- * `authority`; on mainnet, deposits from a non-owner/delegate authority additionally
124
- * require that authority to be on-chain-whitelisted, or the instruction throws.
125
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
126
- * @param args.marketIndex - target spot market index.
127
- * @param args.amount - deposit amount, in the spot market's mint's native token precision (e.g. 1e6 for a 6-decimal USDC-like mint) — not a fixed SDK precision.
128
- * @param args.reduceOnly - if true (or if the market is reduce-only), the deposited amount is capped to the user's current borrow balance in this market so the deposit can only repay a borrow, never flip to a net deposit.
129
- * @param args.state - the global `State` PDA.
130
- * @param args.spotMarket - the target `SpotMarket` PDA.
131
- * @param args.spotMarketVault - the spot market's token vault PDA (destination of the transfer).
132
- * @param args.user - the `User` account being credited.
133
- * @param args.userStats - the depositing user's `UserStats` PDA.
134
- * @param args.userTokenAccount - token account the deposit is transferred from; must share a mint with `spotMarketVault` and be owned by `authority`.
135
- * @param args.authority - signer authorizing the token transfer (source token account owner).
136
- * @param args.tokenProgram - the SPL Token or Token-2022 program owning the mint.
137
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` for `marketIndex` (see `VelocityCore.remainingAccounts.getRemainingAccounts`), plus the deposited mint account, plus any Token-2022 transfer-hook accounts the mint requires.
138
- * @returns the unsigned `deposit` `TransactionInstruction`.
139
- */
140
- static async buildDepositInstruction(args: {
141
- program: VelocityProgram;
142
- marketIndex: number;
143
- amount: BN;
144
- reduceOnly: boolean;
145
- state: PublicKey;
146
- spotMarket: PublicKey;
147
- spotMarketVault: PublicKey;
148
- user: PublicKey;
149
- userStats: PublicKey;
150
- userTokenAccount: PublicKey;
151
- authority: PublicKey;
152
- tokenProgram: PublicKey;
153
- remainingAccounts: AccountMeta[];
154
- }): Promise<TransactionInstruction> {
155
- return await buildDepositInstruction(args);
156
- }
157
-
158
- /**
159
- * Builds a `withdraw` instruction, transferring tokens from the protocol's
160
- * `spotMarketVault` to `userTokenAccount` and debiting (or borrowing against)
161
- * the user's spot position. Unlike deposit, withdrawal requires `authority` to be
162
- * the `user` account's own `authority` field (delegates cannot withdraw).
163
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
164
- * @param args.marketIndex - source spot market index.
165
- * @param args.amount - withdrawal amount, in the spot market's mint's native token precision.
166
- * @param args.reduceOnly - if true (or if the market is reduce-only), the withdrawal is capped to the user's current deposit balance in this market so it can only reduce a deposit, never open/increase a borrow.
167
- * @param args.state - the global `State` PDA.
168
- * @param args.spotMarket - the source `SpotMarket` PDA.
169
- * @param args.spotMarketVault - the spot market's token vault PDA (source of the transfer).
170
- * @param args.velocitySigner - the program's PDA signer authority (`state.signer`) used to authorize the vault-to-user CPI transfer; must equal the `state` account's recorded `signer` field or the instruction throws.
171
- * @param args.user - the `User` account being debited; its `authority` must equal `args.authority`.
172
- * @param args.userStats - the withdrawing user's `UserStats` PDA; its `authority` must also equal `args.authority`.
173
- * @param args.userTokenAccount - token account the withdrawal is transferred to; must share a mint with `spotMarketVault`.
174
- * @param args.authority - signer that must equal `user.authority` (and `userStats.authority`).
175
- * @param args.tokenProgram - the SPL Token or Token-2022 program owning the mint.
176
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` for `marketIndex`, plus the withdrawn mint account, plus any Token-2022 transfer-hook accounts.
177
- * @returns the unsigned `withdraw` `TransactionInstruction`.
178
- */
179
- static async buildWithdrawInstruction(args: {
180
- program: VelocityProgram;
181
- marketIndex: number;
182
- amount: BN;
183
- reduceOnly: boolean;
184
- state: PublicKey;
185
- spotMarket: PublicKey;
186
- spotMarketVault: PublicKey;
187
- velocitySigner: PublicKey;
188
- user: PublicKey;
189
- userStats: PublicKey;
190
- userTokenAccount: PublicKey;
191
- authority: PublicKey;
192
- tokenProgram: PublicKey;
193
- remainingAccounts: AccountMeta[];
194
- }): Promise<TransactionInstruction> {
195
- return await buildWithdrawInstruction(args);
196
- }
197
-
198
- /**
199
- * Builds a `placeOrders` instruction, placing a batch of up to 32 perp and/or spot
200
- * orders in one instruction. None of the orders may be immediate-or-cancel — IOC
201
- * orders are only valid via `placeAndTake`/`placeAndMake` — or the instruction throws.
202
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
203
- * @param args.formattedParams - array of `OrderParams` (see `OrderParams` in `types`): `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`triggerPrice`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
204
- * @param args.state - the global `State` PDA.
205
- * @param args.user - the `User` account the orders are placed on; `authority` must own or be a delegate of it.
206
- * @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `place_orders` accounts (only `state`/`user`/`authority` are used).
207
- * @param args.authority - signer that must own or be a registered delegate of `user`.
208
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` covering every order's market, plus (if builder codes are enabled protocol-wide) the placing user's `RevenueShareEscrow` account when any order carries a `builderIdx`.
209
- * @returns the unsigned `placeOrders` `TransactionInstruction`.
210
- */
211
- static async buildPlaceOrdersInstruction(args: {
212
- program: VelocityProgram;
213
- formattedParams: any[];
214
- state: PublicKey;
215
- user: PublicKey;
216
- userStats: PublicKey;
217
- authority: PublicKey;
218
- remainingAccounts: AccountMeta[];
219
- }): Promise<TransactionInstruction> {
220
- return await buildPlaceOrdersInstruction(args);
221
- }
222
-
223
- /**
224
- * Builds a `cancelOrders` instruction, cancelling every open order on `user` that
225
- * matches all of the given (optional) filters. Passing `null`/`undefined` for a
226
- * filter means "don't filter on this dimension" — passing all three as `null`
227
- * cancels every open order.
228
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
229
- * @param args.marketType - only cancel orders of this `MarketType` (`Perp`/`Spot`), or `null` for both.
230
- * @param args.marketIndex - only cancel orders on this market index, or `null` for all markets.
231
- * @param args.direction - only cancel orders with this `PositionDirection` (long/short), or `null` for both.
232
- * @param args.user - the `User` account whose orders are cancelled.
233
- * @param args.state - the global `State` PDA.
234
- * @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `cancel_orders` accounts (only `state`/`user`/`authority` are used).
235
- * @param args.authority - signer that must own or be a registered delegate of `user`.
236
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive auction/oracle-offset prices for the cancelled orders.
237
- * @returns the unsigned `cancelOrders` `TransactionInstruction`.
238
- */
239
- static async buildCancelOrdersInstruction(args: {
240
- program: VelocityProgram;
241
- marketType: any;
242
- marketIndex: number | null;
243
- direction: any;
244
- user: PublicKey;
245
- state: PublicKey;
246
- userStats: PublicKey;
247
- authority: PublicKey;
248
- remainingAccounts: AccountMeta[];
249
- }): Promise<TransactionInstruction> {
250
- return await buildCancelOrdersInstruction(args);
251
- }
252
-
253
- /**
254
- * Builds a `fillPerpOrder` instruction, matching a resting perp order against the
255
- * AMM and/or the supplied maker accounts. Permissionless: `user` (the order owner)
256
- * does not need to sign — only `authority` (owner/delegate of `filler`) does.
257
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
258
- * @param args.orderId - the order to fill, or `null` to fill `user`'s most recently placed order (resolved on-chain via `get_last_order_id`).
259
- * @param args.state - the global `State` PDA.
260
- * @param args.filler - the keeper's `User` account that earns the filler reward.
261
- * @param args.fillerStats - the filler's `UserStats` PDA.
262
- * @param args.user - the order owner's `User` account (the taker being filled).
263
- * @param args.userStats - the taker's `UserStats` PDA.
264
- * @param args.authority - signer that must own or be a registered delegate of `filler`.
265
- * @param args.remainingAccounts - writable perp market + oracle `AccountMeta[]` for the order's market, followed by any maker/referrer `(User, UserStats)` account pairs, followed by the taker's `RevenueShareEscrow` account if builder codes are enabled protocol-wide.
266
- * @returns the unsigned `fillPerpOrder` `TransactionInstruction`.
267
- */
268
- static async buildFillPerpOrderInstruction(args: {
269
- program: VelocityProgram;
270
- orderId: number | null;
271
- state: PublicKey;
272
- filler: PublicKey;
273
- fillerStats: PublicKey;
274
- user: PublicKey;
275
- userStats: PublicKey;
276
- authority: PublicKey;
277
- remainingAccounts: AccountMeta[];
278
- }): Promise<TransactionInstruction> {
279
- return await buildFillPerpOrderInstruction(args);
280
- }
281
-
282
- /**
283
- * Builds a `triggerOrder` instruction, flipping a resting trigger order (stop-loss /
284
- * take-profit) into a fillable market/limit order once its trigger condition is met
285
- * against the oracle. Permissionless: `user` (the order owner) does not need to sign
286
- * — only `authority` (owner/delegate of `filler`) does. Does not fill the order; a
287
- * subsequent `fillPerpOrder` (or `placeAndTake`) is needed to actually execute it.
288
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
289
- * @param args.orderId - the trigger order's on-chain order ID.
290
- * @param args.state - the global `State` PDA.
291
- * @param args.filler - the keeper's `User` account submitting the trigger.
292
- * @param args.user - the order owner's `User` account.
293
- * @param args.authority - signer that must own or be a registered delegate of `filler`.
294
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` for the order's market.
295
- * @returns the unsigned `triggerOrder` `TransactionInstruction`.
296
- */
297
- static async buildTriggerOrderInstruction(args: {
298
- program: VelocityProgram;
299
- orderId: number;
300
- state: PublicKey;
301
- filler: PublicKey;
302
- user: PublicKey;
303
- authority: PublicKey;
304
- remainingAccounts: AccountMeta[];
305
- }): Promise<TransactionInstruction> {
306
- return await buildTriggerOrderInstruction(args);
307
- }
308
-
309
- /**
310
- * Builds a `settlePnl` instruction, settling `user`'s realized/expired perp PnL on
311
- * `marketIndex` against the quote spot market vault. Fully permissionless: `authority`
312
- * does not need to own or be a delegate of `user` — any signer can crank this.
313
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
314
- * @param args.marketIndex - the perp market whose position PnL is settled.
315
- * @param args.state - the global `State` PDA.
316
- * @param args.authority - any signer; not required to own `user`.
317
- * @param args.user - the `User` account being settled.
318
- * @param args.spotMarketVault - the quote (market index 0) spot market's token vault PDA.
319
- * @param args.remainingAccounts - writable perp market + oracle `AccountMeta[]` for `marketIndex`, plus the writable quote spot market, plus (if builder codes are enabled) `user`'s `RevenueShareEscrow` and the revenue-share market map needed to sweep completed builder fees.
320
- * @returns the unsigned `settlePnl` `TransactionInstruction`.
321
- */
322
- static async buildSettlePnlInstruction(args: {
323
- program: VelocityProgram;
324
- marketIndex: number;
325
- state: PublicKey;
326
- authority: PublicKey;
327
- user: PublicKey;
328
- spotMarketVault: PublicKey;
329
- remainingAccounts: AccountMeta[];
330
- }): Promise<TransactionInstruction> {
331
- return await buildSettlePnlInstruction(args);
332
- }
333
-
334
- /**
335
- * Builds a `liquidatePerp` instruction, letting `liquidator` take over (part of) an
336
- * under-margined perp position from `user`. `user` does not need to sign; `authority`
337
- * must own or be a delegate of `liquidator`, and `liquidator` must differ from `user`.
338
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
339
- * @param args.marketIndex - the perp market being liquidated.
340
- * @param args.maxBaseAssetAmount - maximum base amount the liquidator is willing to take on, BASE_PRECISION (1e9).
341
- * @param args.limitPrice - worst acceptable execution price, PRICE_PRECISION (1e6), or `null` for no limit.
342
- * @param args.state - the global `State` PDA.
343
- * @param args.authority - signer that must own or be a registered delegate of `liquidator`.
344
- * @param args.user - the `User` account being liquidated.
345
- * @param args.userStats - the liquidated user's `UserStats` PDA.
346
- * @param args.liquidator - the `User` account taking over the position; must not equal `user`.
347
- * @param args.liquidatorStats - the liquidator's `UserStats` PDA.
348
- * @param args.remainingAccounts - writable perp market + oracle `AccountMeta[]` for `marketIndex`.
349
- * @returns the unsigned `liquidatePerp` `TransactionInstruction`.
350
- */
351
- static async buildLiquidatePerpInstruction(args: {
352
- program: VelocityProgram;
353
- marketIndex: number;
354
- maxBaseAssetAmount: any;
355
- limitPrice: any | null;
356
- state: PublicKey;
357
- authority: PublicKey;
358
- user: PublicKey;
359
- userStats: PublicKey;
360
- liquidator: PublicKey;
361
- liquidatorStats: PublicKey;
362
- remainingAccounts: AccountMeta[];
363
- }): Promise<TransactionInstruction> {
364
- return await buildLiquidatePerpInstruction(args);
365
- }
366
-
367
- /**
368
- * Builds a `placePerpOrder` instruction, placing a single resting perp order.
369
- * Rejects immediate-or-cancel orders — use `buildPlaceAndTakePerpOrderInstruction`
370
- * or `buildPlaceAndMakePerpOrderInstruction` for IOC orders instead.
371
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
372
- * @param args.orderParams - an `OrderParams` object; `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`triggerPrice`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
373
- * @param args.state - the global `State` PDA.
374
- * @param args.user - the `User` account the order is placed on.
375
- * @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `place_perp_order` accounts.
376
- * @param args.authority - signer that must own or be a registered delegate of `user`.
377
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` for `orderParams.marketIndex`, plus the placing user's `RevenueShareEscrow` account if the order carries a `builderIdx` and builder codes are enabled.
378
- * @returns the unsigned `placePerpOrder` `TransactionInstruction`.
379
- */
380
- static async buildPlacePerpOrderInstruction(args: {
381
- program: VelocityProgram;
382
- orderParams: any;
383
- state: PublicKey;
384
- user: PublicKey;
385
- userStats: PublicKey;
386
- authority: PublicKey;
387
- remainingAccounts: AccountMeta[];
388
- }): Promise<TransactionInstruction> {
389
- return await buildPlacePerpOrderInstruction(args);
390
- }
391
-
392
- /**
393
- * Builds a `placeAndTakePerpOrder` instruction: places an order and immediately
394
- * attempts to fill it as a taker against the AMM and/or the supplied maker accounts.
395
- * `orderParams.postOnly` must be `PostOnlyParam.None` or the instruction throws. Any
396
- * portion left unfilled is auto-cancelled when the order is (or becomes, via
397
- * `optionalParams`) immediate-or-cancel.
398
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
399
- * @param args.orderParams - an `OrderParams` object; `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`triggerPrice`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
400
- * @param args.optionalParams - packed `u32` combining a `PlaceAndTakeOrderSuccessCondition` (fail the tx if not at least partially/fully filled) and an auction-duration percentage override; pass `null` for default behavior (no success-condition check, no override). Also forces IOC cancel-remainder semantics when non-null.
401
- * @param args.state - the global `State` PDA.
402
- * @param args.user - the taker's `User` account.
403
- * @param args.userStats - the taker's `UserStats` PDA.
404
- * @param args.authority - signer that must own or be a registered delegate of `user`.
405
- * @param args.remainingAccounts - writable perp market + oracle `AccountMeta[]` for `orderParams.marketIndex`, followed by maker/referrer `(User, UserStats)` pairs, followed by the taker's `RevenueShareEscrow` account if builder codes are enabled.
406
- * @returns the unsigned `placeAndTakePerpOrder` `TransactionInstruction`.
407
- */
408
- static async buildPlaceAndTakePerpOrderInstruction(args: {
409
- program: VelocityProgram;
410
- orderParams: any;
411
- optionalParams: number | null;
412
- state: PublicKey;
413
- user: PublicKey;
414
- userStats: PublicKey;
415
- authority: PublicKey;
416
- remainingAccounts: AccountMeta[];
417
- }): Promise<TransactionInstruction> {
418
- return await buildPlaceAndTakePerpOrderInstruction(args);
419
- }
420
-
421
- /**
422
- * Builds a `placeAndMakePerpOrder` instruction: posts an immediate-or-cancel,
423
- * post-only limit order for `user` and immediately fills it as the maker against
424
- * `taker`'s existing resting order. `orderParams` must be an IOC, post-only, `Limit`
425
- * order or the instruction throws. Any unfilled remainder of the just-placed maker
426
- * order is auto-cancelled.
427
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
428
- * @param args.orderParams - an `OrderParams` object; `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
429
- * @param args.takerOrderId - the on-chain order ID of `taker`'s resting order being filled.
430
- * @param args.state - the global `State` PDA.
431
- * @param args.user - the maker's `User` account.
432
- * @param args.userStats - the maker's `UserStats` PDA.
433
- * @param args.taker - the taker's `User` account (order owner being filled).
434
- * @param args.takerStats - the taker's `UserStats` PDA.
435
- * @param args.authority - signer that must own or be a registered delegate of `user` (the maker).
436
- * @param args.remainingAccounts - writable perp market + oracle `AccountMeta[]` for `orderParams.marketIndex`, followed by any additional maker/referrer `(User, UserStats)` pairs needed to fill `taker`'s order, followed by `taker`'s `RevenueShareEscrow` account if builder codes are enabled.
437
- * @returns the unsigned `placeAndMakePerpOrder` `TransactionInstruction`.
438
- */
439
- static async buildPlaceAndMakePerpOrderInstruction(args: {
440
- program: VelocityProgram;
441
- orderParams: any;
442
- takerOrderId: number;
443
- state: PublicKey;
444
- user: PublicKey;
445
- userStats: PublicKey;
446
- taker: PublicKey;
447
- takerStats: PublicKey;
448
- authority: PublicKey;
449
- remainingAccounts: AccountMeta[];
450
- }): Promise<TransactionInstruction> {
451
- return await buildPlaceAndMakePerpOrderInstruction(args);
452
- }
453
-
454
- /**
455
- * Builds a `cancelOrder` instruction for a single order.
456
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
457
- * @param args.orderId - the order to cancel, or `null` to cancel `user`'s most recently placed order (resolved on-chain via `get_last_order_id` — safe to use right after a `place*` instruction in the same transaction, since the on-chain order ID isn't known at build time).
458
- * @param args.state - the global `State` PDA.
459
- * @param args.user - the `User` account whose order is cancelled.
460
- * @param args.authority - signer that must own or be a registered delegate of `user`.
461
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive the cancelled order's auction/oracle-offset price.
462
- * @returns the unsigned `cancelOrder` `TransactionInstruction`.
463
- */
464
- static async buildCancelOrderInstruction(args: {
465
- program: VelocityProgram;
466
- orderId: number | null;
467
- state: PublicKey;
468
- user: PublicKey;
469
- authority: PublicKey;
470
- remainingAccounts: AccountMeta[];
471
- }): Promise<TransactionInstruction> {
472
- return await buildCancelOrderInstruction(args);
473
- }
474
-
475
- /**
476
- * Builds a `cancelOrderByUserId` instruction, cancelling the order matching the
477
- * caller-assigned `userOrderId` (the `OrderParams.userOrderId` tag set at placement)
478
- * rather than the program-assigned order ID.
479
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
480
- * @param args.userOrderId - the caller-assigned order tag (`u8`) supplied when the order was placed.
481
- * @param args.state - the global `State` PDA.
482
- * @param args.user - the `User` account whose order is cancelled.
483
- * @param args.authority - signer that must own or be a registered delegate of `user`.
484
- * @param args.oracle - accepted for forward-compatibility but not required by the current on-chain `cancel_order_by_user_id` accounts (only `state`/`user`/`authority` are used).
485
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive the cancelled order's auction/oracle-offset price.
486
- * @returns the unsigned `cancelOrderByUserId` `TransactionInstruction`.
487
- */
488
- static async buildCancelOrderByUserIdInstruction(args: {
489
- program: VelocityProgram;
490
- userOrderId: number;
491
- state: PublicKey;
492
- user: PublicKey;
493
- authority: PublicKey;
494
- oracle: PublicKey;
495
- remainingAccounts: AccountMeta[];
496
- }): Promise<TransactionInstruction> {
497
- return await buildCancelOrderByUserIdInstruction(args);
498
- }
499
-
500
- /**
501
- * Builds a `cancelOrdersByIds` instruction, cancelling multiple orders by their
502
- * program-assigned order IDs in one instruction.
503
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
504
- * @param args.orderIds - order IDs to cancel; passing `undefined` sends an empty list on-chain (cancels nothing).
505
- * @param args.state - the global `State` PDA.
506
- * @param args.user - the `User` account whose orders are cancelled.
507
- * @param args.authority - signer that must own or be a registered delegate of `user`.
508
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive the cancelled orders' auction/oracle-offset prices.
509
- * @returns the unsigned `cancelOrdersByIds` `TransactionInstruction`.
510
- */
511
- static async buildCancelOrdersByIdsInstruction(args: {
512
- program: VelocityProgram;
513
- orderIds: number[] | undefined;
514
- state: PublicKey;
515
- user: PublicKey;
516
- authority: PublicKey;
517
- remainingAccounts: AccountMeta[];
518
- }): Promise<TransactionInstruction> {
519
- return await buildCancelOrdersByIdsInstruction(args);
520
- }
521
-
522
- /**
523
- * Builds a `modifyOrder` instruction, mutating an existing resting order in place
524
- * (e.g. new price/size/trigger) rather than cancel-and-replace.
525
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
526
- * @param args.orderId - the order to modify, or `null`/`undefined` semantics are not accepted here — pass the program-assigned order ID (use `buildModifyOrderByUserIdInstruction` to target by caller-assigned tag instead).
527
- * @param args.modifyParams - a `ModifyOrderParams` object; any `baseAssetAmount`/`price`/`triggerPrice` overrides use BASE_PRECISION (1e9) / PRICE_PRECISION (1e6) respectively.
528
- * @param args.state - the global `State` PDA.
529
- * @param args.user - the `User` account whose order is modified.
530
- * @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `modify_order` accounts.
531
- * @param args.authority - signer that must own or be a registered delegate of `user`.
532
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` for the order's market.
533
- * @returns the unsigned `modifyOrder` `TransactionInstruction`.
534
- */
535
- static async buildModifyOrderInstruction(args: {
536
- program: VelocityProgram;
537
- orderId: number;
538
- modifyParams: any;
539
- state: PublicKey;
540
- user: PublicKey;
541
- userStats: PublicKey;
542
- authority: PublicKey;
543
- remainingAccounts: AccountMeta[];
544
- }): Promise<TransactionInstruction> {
545
- return await buildModifyOrderInstruction(args);
546
- }
547
-
548
- /**
549
- * Builds a `modifyOrderByUserId` instruction, same as `buildModifyOrderInstruction`
550
- * but targeting the order by its caller-assigned `userOrderId` tag.
551
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
552
- * @param args.userOrderId - the caller-assigned order tag (`u8`) supplied when the order was placed.
553
- * @param args.modifyParams - a `ModifyOrderParams` object; any `baseAssetAmount`/`price`/`triggerPrice` overrides use BASE_PRECISION (1e9) / PRICE_PRECISION (1e6) respectively.
554
- * @param args.state - the global `State` PDA.
555
- * @param args.user - the `User` account whose order is modified.
556
- * @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `modify_order_by_user_id` accounts.
557
- * @param args.authority - signer that must own or be a registered delegate of `user`.
558
- * @param args.remainingAccounts - oracle/market `AccountMeta[]` for the order's market.
559
- * @returns the unsigned `modifyOrderByUserId` `TransactionInstruction`.
560
- */
561
- static async buildModifyOrderByUserIdInstruction(args: {
562
- program: VelocityProgram;
563
- userOrderId: number;
564
- modifyParams: any;
565
- state: PublicKey;
566
- user: PublicKey;
567
- userStats: PublicKey;
568
- authority: PublicKey;
569
- remainingAccounts: AccountMeta[];
570
- }): Promise<TransactionInstruction> {
571
- return await buildModifyOrderByUserIdInstruction(args);
572
- }
573
-
574
- /**
575
- * Builds an `updateFundingRate` instruction. Fully permissionless keeper crank —
576
- * no signer is required at all; anyone can submit this to advance a perp market's
577
- * funding rate once its funding period has elapsed.
578
- * @param args.program - Anchor `Program<Velocity>` used to build the instruction.
579
- * @param args.perpMarketIndex - the perp market to update.
580
- * @param args.state - the global `State` PDA.
581
- * @param args.perpMarket - the target `PerpMarket` PDA.
582
- * @param args.oracle - the perp market's oracle account (must match `perpMarket.amm.oracle`).
583
- * @returns the unsigned `updateFundingRate` `TransactionInstruction`.
584
- */
585
- static async buildUpdateFundingRateInstruction(args: {
586
- program: VelocityProgram;
587
- perpMarketIndex: number;
588
- state: PublicKey;
589
- perpMarket: PublicKey;
590
- oracle: PublicKey;
591
- }): Promise<TransactionInstruction> {
592
- return await buildUpdateFundingRateInstruction(args);
593
- }
594
-
595
- /**
596
- * Placeholder for instruction builders.
597
- *
598
- * In follow-up refactors, VelocityClient methods like `getDepositInstruction`,
599
- * `getPlaceOrdersIx`, etc. will be moved here as pure builders.
600
- */
601
- static buildInstructions(
602
- _ctx: VelocityCoreContext
603
- ): TransactionInstruction[] {
604
- return [];
605
- }
606
- }
package/src/core/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export * from './VelocityCore';
2
- export * from './remainingAccounts';
3
- export * from './signedMsg';
4
- export * from './instructions/deposit';
5
- export * from './instructions/withdraw';
6
- export * from './instructions/orders';
7
- export * from './instructions/fill';
8
- export * from './instructions/trigger';
9
- export * from './instructions/settlement';
10
- export * from './instructions/liquidation';
11
- export * from './instructions/perpOrders';
12
- export * from './instructions/funding';