@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,64 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { BN } from '../../isomorphic/anchor';
|
|
7
|
-
import type { VelocityProgram } from '../../config';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Builds a `deposit` instruction, transferring tokens from `userTokenAccount` into the
|
|
11
|
-
* protocol's `spotMarketVault` and crediting `user`'s spot position. Any signer may fund
|
|
12
|
-
* someone else's `user` account (`authority` need not own/delegate for `user`) as long as
|
|
13
|
-
* `userTokenAccount` is owned by `authority`; on mainnet, a non-owner/non-delegate
|
|
14
|
-
* `authority` must additionally be on the on-chain external-depositor whitelist or the
|
|
15
|
-
* instruction throws.
|
|
16
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
17
|
-
* @param args.marketIndex - target spot market index.
|
|
18
|
-
* @param args.amount - deposit amount, in the spot market's mint's native token precision (e.g. 1e6 for a 6-decimal mint) — not a fixed SDK precision.
|
|
19
|
-
* @param args.reduceOnly - if true (or the market is reduce-only), caps the deposit to the user's current borrow balance so it can only repay a borrow.
|
|
20
|
-
* @param args.state - the global `State` PDA.
|
|
21
|
-
* @param args.spotMarket - the target `SpotMarket` PDA.
|
|
22
|
-
* @param args.spotMarketVault - the spot market's token vault PDA (transfer destination).
|
|
23
|
-
* @param args.user - the `User` account being credited.
|
|
24
|
-
* @param args.userStats - the depositing user's `UserStats` PDA.
|
|
25
|
-
* @param args.userTokenAccount - source token account; must share a mint with `spotMarketVault` and be owned by `authority`.
|
|
26
|
-
* @param args.authority - signer authorizing the token transfer.
|
|
27
|
-
* @param args.tokenProgram - the SPL Token or Token-2022 program owning the mint.
|
|
28
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` for `marketIndex`, plus the deposited mint account, plus any Token-2022 transfer-hook accounts.
|
|
29
|
-
* @returns the unsigned `deposit` `TransactionInstruction`.
|
|
30
|
-
*/
|
|
31
|
-
export async function buildDepositInstruction(args: {
|
|
32
|
-
program: VelocityProgram;
|
|
33
|
-
marketIndex: number;
|
|
34
|
-
amount: BN;
|
|
35
|
-
reduceOnly: boolean;
|
|
36
|
-
state: PublicKey;
|
|
37
|
-
spotMarket: PublicKey;
|
|
38
|
-
spotMarketVault: PublicKey;
|
|
39
|
-
user: PublicKey;
|
|
40
|
-
userStats: PublicKey;
|
|
41
|
-
userTokenAccount: PublicKey;
|
|
42
|
-
authority: PublicKey;
|
|
43
|
-
tokenProgram: PublicKey;
|
|
44
|
-
remainingAccounts: AccountMeta[];
|
|
45
|
-
}): Promise<TransactionInstruction> {
|
|
46
|
-
return await (args.program.instruction as any).deposit(
|
|
47
|
-
args.marketIndex,
|
|
48
|
-
args.amount,
|
|
49
|
-
args.reduceOnly,
|
|
50
|
-
{
|
|
51
|
-
accounts: {
|
|
52
|
-
state: args.state,
|
|
53
|
-
spotMarket: args.spotMarket,
|
|
54
|
-
spotMarketVault: args.spotMarketVault,
|
|
55
|
-
user: args.user,
|
|
56
|
-
userStats: args.userStats,
|
|
57
|
-
userTokenAccount: args.userTokenAccount,
|
|
58
|
-
authority: args.authority,
|
|
59
|
-
tokenProgram: args.tokenProgram,
|
|
60
|
-
},
|
|
61
|
-
remainingAccounts: args.remainingAccounts,
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { VelocityProgram } from '../../config';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Builds a `fillPerpOrder` instruction, matching a resting perp order against the AMM
|
|
10
|
-
* and/or the supplied maker accounts. Permissionless: `user` (the order owner) does not
|
|
11
|
-
* need to sign — only `authority` (owner/delegate of `filler`) does. Hardcodes the
|
|
12
|
-
* on-chain `makerOrderId` arg to `null` (no specific maker order is targeted; the
|
|
13
|
-
* program matches from whichever maker/referrer accounts are supplied).
|
|
14
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
15
|
-
* @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`).
|
|
16
|
-
* @param args.state - the global `State` PDA.
|
|
17
|
-
* @param args.filler - the keeper's `User` account that earns the filler reward.
|
|
18
|
-
* @param args.fillerStats - the filler's `UserStats` PDA.
|
|
19
|
-
* @param args.user - the order owner's `User` account (the taker being filled).
|
|
20
|
-
* @param args.userStats - the taker's `UserStats` PDA.
|
|
21
|
-
* @param args.authority - signer that must own or be a registered delegate of `filler`.
|
|
22
|
-
* @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.
|
|
23
|
-
* @returns the unsigned `fillPerpOrder` `TransactionInstruction`.
|
|
24
|
-
*/
|
|
25
|
-
export async function buildFillPerpOrderInstruction(args: {
|
|
26
|
-
program: VelocityProgram;
|
|
27
|
-
orderId: number | null;
|
|
28
|
-
state: PublicKey;
|
|
29
|
-
filler: PublicKey;
|
|
30
|
-
fillerStats: PublicKey;
|
|
31
|
-
user: PublicKey;
|
|
32
|
-
userStats: PublicKey;
|
|
33
|
-
authority: PublicKey;
|
|
34
|
-
remainingAccounts: AccountMeta[];
|
|
35
|
-
}): Promise<TransactionInstruction> {
|
|
36
|
-
return await (args.program.instruction as any).fillPerpOrder(
|
|
37
|
-
args.orderId,
|
|
38
|
-
null,
|
|
39
|
-
{
|
|
40
|
-
accounts: {
|
|
41
|
-
state: args.state,
|
|
42
|
-
filler: args.filler,
|
|
43
|
-
fillerStats: args.fillerStats,
|
|
44
|
-
user: args.user,
|
|
45
|
-
userStats: args.userStats,
|
|
46
|
-
authority: args.authority,
|
|
47
|
-
},
|
|
48
|
-
remainingAccounts: args.remainingAccounts,
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
import type { VelocityProgram } from '../../config';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Builds an `updateFundingRate` instruction. Fully permissionless keeper crank — no
|
|
6
|
-
* signer is required at all; anyone can submit this to advance a perp market's funding
|
|
7
|
-
* rate once its funding period has elapsed. Throws `FundingWasNotUpdated` on-chain if
|
|
8
|
-
* called before the market's funding period has elapsed.
|
|
9
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
10
|
-
* @param args.perpMarketIndex - the perp market to update.
|
|
11
|
-
* @param args.state - the global `State` PDA.
|
|
12
|
-
* @param args.perpMarket - the target `PerpMarket` PDA.
|
|
13
|
-
* @param args.oracle - the perp market's oracle account (must match `perpMarket.amm.oracle`).
|
|
14
|
-
* @returns the unsigned `updateFundingRate` `TransactionInstruction`.
|
|
15
|
-
*/
|
|
16
|
-
export async function buildUpdateFundingRateInstruction(args: {
|
|
17
|
-
program: VelocityProgram;
|
|
18
|
-
perpMarketIndex: number;
|
|
19
|
-
state: PublicKey;
|
|
20
|
-
perpMarket: PublicKey;
|
|
21
|
-
oracle: PublicKey;
|
|
22
|
-
}): Promise<TransactionInstruction> {
|
|
23
|
-
return await (args.program.instruction as any).updateFundingRate(
|
|
24
|
-
args.perpMarketIndex,
|
|
25
|
-
{
|
|
26
|
-
accounts: {
|
|
27
|
-
state: args.state,
|
|
28
|
-
perpMarket: args.perpMarket,
|
|
29
|
-
oracle: args.oracle,
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { VelocityProgram } from '../../config';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Builds a `liquidatePerp` instruction, letting `liquidator` take over (part of) an
|
|
10
|
-
* under-margined perp position from `user`. `user` does not need to sign; `authority`
|
|
11
|
-
* must own or be a delegate of `liquidator`, and `liquidator` must differ from `user`
|
|
12
|
-
* (self-liquidation throws `UserCantLiquidateThemself`).
|
|
13
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
14
|
-
* @param args.marketIndex - the perp market being liquidated.
|
|
15
|
-
* @param args.maxBaseAssetAmount - maximum base amount the liquidator is willing to take on, BASE_PRECISION (1e9).
|
|
16
|
-
* @param args.limitPrice - worst acceptable execution price, PRICE_PRECISION (1e6), or `null` for no limit.
|
|
17
|
-
* @param args.state - the global `State` PDA.
|
|
18
|
-
* @param args.authority - signer that must own or be a registered delegate of `liquidator`.
|
|
19
|
-
* @param args.user - the `User` account being liquidated.
|
|
20
|
-
* @param args.userStats - the liquidated user's `UserStats` PDA.
|
|
21
|
-
* @param args.liquidator - the `User` account taking over the position; must not equal `user`.
|
|
22
|
-
* @param args.liquidatorStats - the liquidator's `UserStats` PDA.
|
|
23
|
-
* @param args.remainingAccounts - writable perp market + oracle `AccountMeta[]` for `marketIndex`.
|
|
24
|
-
* @returns the unsigned `liquidatePerp` `TransactionInstruction`.
|
|
25
|
-
*/
|
|
26
|
-
export async function buildLiquidatePerpInstruction(args: {
|
|
27
|
-
program: VelocityProgram;
|
|
28
|
-
marketIndex: number;
|
|
29
|
-
maxBaseAssetAmount: any;
|
|
30
|
-
limitPrice: any | null;
|
|
31
|
-
state: PublicKey;
|
|
32
|
-
authority: PublicKey;
|
|
33
|
-
user: PublicKey;
|
|
34
|
-
userStats: PublicKey;
|
|
35
|
-
liquidator: PublicKey;
|
|
36
|
-
liquidatorStats: PublicKey;
|
|
37
|
-
remainingAccounts: AccountMeta[];
|
|
38
|
-
}): Promise<TransactionInstruction> {
|
|
39
|
-
return await (args.program.instruction as any).liquidatePerp(
|
|
40
|
-
args.marketIndex,
|
|
41
|
-
args.maxBaseAssetAmount,
|
|
42
|
-
args.limitPrice,
|
|
43
|
-
{
|
|
44
|
-
accounts: {
|
|
45
|
-
state: args.state,
|
|
46
|
-
authority: args.authority,
|
|
47
|
-
user: args.user,
|
|
48
|
-
userStats: args.userStats,
|
|
49
|
-
liquidator: args.liquidator,
|
|
50
|
-
liquidatorStats: args.liquidatorStats,
|
|
51
|
-
},
|
|
52
|
-
remainingAccounts: args.remainingAccounts,
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { VelocityProgram } from '../../config';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Builds a `placeOrders` instruction, placing a batch of up to 32 perp and/or spot
|
|
10
|
-
* orders in one instruction. None of the orders may be immediate-or-cancel — IOC orders
|
|
11
|
-
* are only valid via `placeAndTake`/`placeAndMake` — or the instruction throws.
|
|
12
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
13
|
-
* @param args.formattedParams - array of `OrderParams`: `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`triggerPrice`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
|
|
14
|
-
* @param args.state - the global `State` PDA.
|
|
15
|
-
* @param args.user - the `User` account the orders are placed on; `authority` must own or be a delegate of it.
|
|
16
|
-
* @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `place_orders` accounts (only `state`/`user`/`authority` are used).
|
|
17
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
18
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` covering every order's market, plus the placing user's `RevenueShareEscrow` account when any order carries a `builderIdx` and builder codes are enabled protocol-wide.
|
|
19
|
-
* @returns the unsigned `placeOrders` `TransactionInstruction`.
|
|
20
|
-
*/
|
|
21
|
-
export async function buildPlaceOrdersInstruction(args: {
|
|
22
|
-
program: VelocityProgram;
|
|
23
|
-
formattedParams: any[];
|
|
24
|
-
state: PublicKey;
|
|
25
|
-
user: PublicKey;
|
|
26
|
-
userStats: PublicKey;
|
|
27
|
-
authority: PublicKey;
|
|
28
|
-
remainingAccounts: AccountMeta[];
|
|
29
|
-
}): Promise<TransactionInstruction> {
|
|
30
|
-
return await (args.program.instruction as any).placeOrders(
|
|
31
|
-
args.formattedParams,
|
|
32
|
-
{
|
|
33
|
-
accounts: {
|
|
34
|
-
state: args.state,
|
|
35
|
-
user: args.user,
|
|
36
|
-
userStats: args.userStats,
|
|
37
|
-
authority: args.authority,
|
|
38
|
-
},
|
|
39
|
-
remainingAccounts: args.remainingAccounts,
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Builds a `cancelOrders` instruction, cancelling every open order on `user` that
|
|
46
|
-
* matches all of the given (optional) filters. `null`/`undefined` on a filter means
|
|
47
|
-
* "don't filter on this dimension" — leaving all three `null` cancels every open order.
|
|
48
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
49
|
-
* @param args.marketType - only cancel orders of this `MarketType` (`Perp`/`Spot`), or `null` for both.
|
|
50
|
-
* @param args.marketIndex - only cancel orders on this market index, or `null` for all markets.
|
|
51
|
-
* @param args.direction - only cancel orders with this `PositionDirection`, or `null` for both.
|
|
52
|
-
* @param args.user - the `User` account whose orders are cancelled.
|
|
53
|
-
* @param args.state - the global `State` PDA.
|
|
54
|
-
* @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `cancel_orders` accounts (only `state`/`user`/`authority` are used).
|
|
55
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
56
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive auction/oracle-offset prices for the cancelled orders.
|
|
57
|
-
* @returns the unsigned `cancelOrders` `TransactionInstruction`.
|
|
58
|
-
*/
|
|
59
|
-
export async function buildCancelOrdersInstruction(args: {
|
|
60
|
-
program: VelocityProgram;
|
|
61
|
-
marketType: any;
|
|
62
|
-
marketIndex: number | null;
|
|
63
|
-
direction: any;
|
|
64
|
-
user: PublicKey;
|
|
65
|
-
state: PublicKey;
|
|
66
|
-
userStats: PublicKey;
|
|
67
|
-
authority: PublicKey;
|
|
68
|
-
remainingAccounts: AccountMeta[];
|
|
69
|
-
}): Promise<TransactionInstruction> {
|
|
70
|
-
return await (args.program.instruction as any).cancelOrders(
|
|
71
|
-
args.marketType,
|
|
72
|
-
args.marketIndex,
|
|
73
|
-
args.direction,
|
|
74
|
-
{
|
|
75
|
-
accounts: {
|
|
76
|
-
state: args.state,
|
|
77
|
-
user: args.user,
|
|
78
|
-
userStats: args.userStats,
|
|
79
|
-
authority: args.authority,
|
|
80
|
-
},
|
|
81
|
-
remainingAccounts: args.remainingAccounts,
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { VelocityProgram } from '../../config';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Builds a `placePerpOrder` instruction, placing a single resting perp order. Rejects
|
|
10
|
-
* immediate-or-cancel orders (`InvalidOrderIOC`) — use `buildPlaceAndTakePerpOrderInstruction`
|
|
11
|
-
* or `buildPlaceAndMakePerpOrderInstruction` for IOC orders instead.
|
|
12
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
13
|
-
* @param args.orderParams - an `OrderParams` object; `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`triggerPrice`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
|
|
14
|
-
* @param args.state - the global `State` PDA.
|
|
15
|
-
* @param args.user - the `User` account the order is placed on.
|
|
16
|
-
* @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `place_perp_order` accounts.
|
|
17
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
18
|
-
* @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 protocol-wide.
|
|
19
|
-
* @returns the unsigned `placePerpOrder` `TransactionInstruction`.
|
|
20
|
-
*/
|
|
21
|
-
export async function buildPlacePerpOrderInstruction(args: {
|
|
22
|
-
program: VelocityProgram;
|
|
23
|
-
orderParams: any;
|
|
24
|
-
state: PublicKey;
|
|
25
|
-
user: PublicKey;
|
|
26
|
-
userStats: PublicKey;
|
|
27
|
-
authority: PublicKey;
|
|
28
|
-
remainingAccounts: AccountMeta[];
|
|
29
|
-
}): Promise<TransactionInstruction> {
|
|
30
|
-
return await (args.program.instruction as any).placePerpOrder(
|
|
31
|
-
args.orderParams,
|
|
32
|
-
{
|
|
33
|
-
accounts: {
|
|
34
|
-
state: args.state,
|
|
35
|
-
user: args.user,
|
|
36
|
-
userStats: args.userStats,
|
|
37
|
-
authority: args.authority,
|
|
38
|
-
},
|
|
39
|
-
remainingAccounts: args.remainingAccounts,
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Builds a `placeAndTakePerpOrder` instruction: places an order and immediately attempts
|
|
46
|
-
* to fill it as a taker against the AMM and/or the supplied maker accounts.
|
|
47
|
-
* `orderParams.postOnly` must be `PostOnlyParam.None` (`InvalidOrderPostOnly` otherwise).
|
|
48
|
-
* Any portion left unfilled is auto-cancelled when the order is (or becomes, via
|
|
49
|
-
* `optionalParams`) immediate-or-cancel.
|
|
50
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
51
|
-
* @param args.orderParams - an `OrderParams` object; `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`triggerPrice`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
|
|
52
|
-
* @param args.optionalParams - packed `u32` combining a `PlaceAndTakeOrderSuccessCondition` (fail the tx if not at least partially/fully filled) and an auction-duration percentage override; `null` for default behavior. Passing any non-null value also forces IOC cancel-remainder semantics.
|
|
53
|
-
* @param args.state - the global `State` PDA.
|
|
54
|
-
* @param args.user - the taker's `User` account.
|
|
55
|
-
* @param args.userStats - the taker's `UserStats` PDA.
|
|
56
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
57
|
-
* @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.
|
|
58
|
-
* @returns the unsigned `placeAndTakePerpOrder` `TransactionInstruction`.
|
|
59
|
-
*/
|
|
60
|
-
export async function buildPlaceAndTakePerpOrderInstruction(args: {
|
|
61
|
-
program: VelocityProgram;
|
|
62
|
-
orderParams: any;
|
|
63
|
-
optionalParams: number | null;
|
|
64
|
-
state: PublicKey;
|
|
65
|
-
user: PublicKey;
|
|
66
|
-
userStats: PublicKey;
|
|
67
|
-
authority: PublicKey;
|
|
68
|
-
remainingAccounts: AccountMeta[];
|
|
69
|
-
}): Promise<TransactionInstruction> {
|
|
70
|
-
return await args.program.instruction.placeAndTakePerpOrder(
|
|
71
|
-
args.orderParams,
|
|
72
|
-
args.optionalParams,
|
|
73
|
-
{
|
|
74
|
-
accounts: {
|
|
75
|
-
state: args.state,
|
|
76
|
-
user: args.user,
|
|
77
|
-
userStats: args.userStats,
|
|
78
|
-
authority: args.authority,
|
|
79
|
-
},
|
|
80
|
-
remainingAccounts: args.remainingAccounts,
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Builds a `placeAndMakePerpOrder` instruction: posts an immediate-or-cancel, post-only
|
|
87
|
-
* `Limit` order for `user` and immediately fills it as the maker against `taker`'s
|
|
88
|
-
* existing resting order (`InvalidOrderIOCPostOnly` if `orderParams` isn't IOC + post-only
|
|
89
|
-
* + `Limit`). Any unfilled remainder of the just-placed maker order is auto-cancelled.
|
|
90
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
91
|
-
* @param args.orderParams - an `OrderParams` object; `baseAssetAmount` is BASE_PRECISION (1e9), `price`/`oraclePriceOffset` are PRICE_PRECISION (1e6).
|
|
92
|
-
* @param args.takerOrderId - the on-chain order ID of `taker`'s resting order being filled.
|
|
93
|
-
* @param args.state - the global `State` PDA.
|
|
94
|
-
* @param args.user - the maker's `User` account.
|
|
95
|
-
* @param args.userStats - the maker's `UserStats` PDA.
|
|
96
|
-
* @param args.taker - the taker's `User` account (order owner being filled).
|
|
97
|
-
* @param args.takerStats - the taker's `UserStats` PDA.
|
|
98
|
-
* @param args.authority - signer that must own or be a registered delegate of `user` (the maker).
|
|
99
|
-
* @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.
|
|
100
|
-
* @returns the unsigned `placeAndMakePerpOrder` `TransactionInstruction`.
|
|
101
|
-
*/
|
|
102
|
-
export async function buildPlaceAndMakePerpOrderInstruction(args: {
|
|
103
|
-
program: VelocityProgram;
|
|
104
|
-
orderParams: any;
|
|
105
|
-
takerOrderId: number;
|
|
106
|
-
state: PublicKey;
|
|
107
|
-
user: PublicKey;
|
|
108
|
-
userStats: PublicKey;
|
|
109
|
-
taker: PublicKey;
|
|
110
|
-
takerStats: PublicKey;
|
|
111
|
-
authority: PublicKey;
|
|
112
|
-
remainingAccounts: AccountMeta[];
|
|
113
|
-
}): Promise<TransactionInstruction> {
|
|
114
|
-
return await args.program.instruction.placeAndMakePerpOrder(
|
|
115
|
-
args.orderParams,
|
|
116
|
-
args.takerOrderId,
|
|
117
|
-
{
|
|
118
|
-
accounts: {
|
|
119
|
-
state: args.state,
|
|
120
|
-
user: args.user,
|
|
121
|
-
userStats: args.userStats,
|
|
122
|
-
taker: args.taker,
|
|
123
|
-
takerStats: args.takerStats,
|
|
124
|
-
authority: args.authority,
|
|
125
|
-
},
|
|
126
|
-
remainingAccounts: args.remainingAccounts,
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Build a raw `cancelOrder` instruction.
|
|
133
|
-
*
|
|
134
|
-
* Pass `orderId: null` to cancel the user's most recently placed order. The program
|
|
135
|
-
* resolves a `null` ID on-chain via `get_last_order_id`, which makes this safe to use
|
|
136
|
-
* in a multi-instruction transaction where a place instruction precedes the cancel and
|
|
137
|
-
* the program-assigned order ID is not yet known at build time — e.g.:
|
|
138
|
-
*
|
|
139
|
-
* [placePerpOrder] → [cancelOrder(orderId: null)]
|
|
140
|
-
*
|
|
141
|
-
* The on-chain `order_id` counter is a monotonically incrementing u32 on the user
|
|
142
|
-
* account, so `get_last_order_id` reliably points to the order placed in the preceding
|
|
143
|
-
* instruction of the same transaction.
|
|
144
|
-
*
|
|
145
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
146
|
-
* @param args.orderId - the order to cancel, or `null` per the above.
|
|
147
|
-
* @param args.state - the global `State` PDA.
|
|
148
|
-
* @param args.user - the `User` account whose order is cancelled.
|
|
149
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
150
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive the cancelled order's auction/oracle-offset price.
|
|
151
|
-
* @returns the unsigned `cancelOrder` `TransactionInstruction`.
|
|
152
|
-
*/
|
|
153
|
-
export async function buildCancelOrderInstruction(args: {
|
|
154
|
-
program: VelocityProgram;
|
|
155
|
-
orderId: number | null;
|
|
156
|
-
state: PublicKey;
|
|
157
|
-
user: PublicKey;
|
|
158
|
-
authority: PublicKey;
|
|
159
|
-
remainingAccounts: AccountMeta[];
|
|
160
|
-
}): Promise<TransactionInstruction> {
|
|
161
|
-
return await args.program.instruction.cancelOrder(args.orderId, {
|
|
162
|
-
accounts: {
|
|
163
|
-
state: args.state,
|
|
164
|
-
user: args.user,
|
|
165
|
-
authority: args.authority,
|
|
166
|
-
},
|
|
167
|
-
remainingAccounts: args.remainingAccounts,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Builds a `cancelOrderByUserId` instruction, cancelling the order matching the
|
|
173
|
-
* caller-assigned `userOrderId` (the `OrderParams.userOrderId` tag set at placement)
|
|
174
|
-
* rather than the program-assigned order ID.
|
|
175
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
176
|
-
* @param args.userOrderId - the caller-assigned order tag (`u8`) supplied when the order was placed.
|
|
177
|
-
* @param args.state - the global `State` PDA.
|
|
178
|
-
* @param args.user - the `User` account whose order is cancelled.
|
|
179
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
180
|
-
* @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).
|
|
181
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive the cancelled order's auction/oracle-offset price.
|
|
182
|
-
* @returns the unsigned `cancelOrderByUserId` `TransactionInstruction`.
|
|
183
|
-
*/
|
|
184
|
-
export async function buildCancelOrderByUserIdInstruction(args: {
|
|
185
|
-
program: VelocityProgram;
|
|
186
|
-
userOrderId: number;
|
|
187
|
-
state: PublicKey;
|
|
188
|
-
user: PublicKey;
|
|
189
|
-
authority: PublicKey;
|
|
190
|
-
oracle: PublicKey;
|
|
191
|
-
remainingAccounts: AccountMeta[];
|
|
192
|
-
}): Promise<TransactionInstruction> {
|
|
193
|
-
return await (args.program.instruction as any).cancelOrderByUserId(
|
|
194
|
-
args.userOrderId,
|
|
195
|
-
{
|
|
196
|
-
accounts: {
|
|
197
|
-
state: args.state,
|
|
198
|
-
user: args.user,
|
|
199
|
-
authority: args.authority,
|
|
200
|
-
oracle: args.oracle,
|
|
201
|
-
},
|
|
202
|
-
remainingAccounts: args.remainingAccounts,
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Builds a `cancelOrdersByIds` instruction, cancelling multiple orders by their
|
|
209
|
-
* program-assigned order IDs in one instruction (loops `cancel_order_by_order_id`
|
|
210
|
-
* on-chain, one order at a time — an order ID that no longer exists is silently
|
|
211
|
-
* skipped rather than failing the whole instruction).
|
|
212
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
213
|
-
* @param args.orderIds - order IDs to cancel; passing `undefined` sends an empty list on-chain (cancels nothing).
|
|
214
|
-
* @param args.state - the global `State` PDA.
|
|
215
|
-
* @param args.user - the `User` account whose orders are cancelled.
|
|
216
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
217
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` needed to re-derive the cancelled orders' auction/oracle-offset prices.
|
|
218
|
-
* @returns the unsigned `cancelOrdersByIds` `TransactionInstruction`.
|
|
219
|
-
*/
|
|
220
|
-
export async function buildCancelOrdersByIdsInstruction(args: {
|
|
221
|
-
program: VelocityProgram;
|
|
222
|
-
orderIds: number[] | undefined;
|
|
223
|
-
state: PublicKey;
|
|
224
|
-
user: PublicKey;
|
|
225
|
-
authority: PublicKey;
|
|
226
|
-
remainingAccounts: AccountMeta[];
|
|
227
|
-
}): Promise<TransactionInstruction> {
|
|
228
|
-
return await args.program.instruction.cancelOrdersByIds(args.orderIds, {
|
|
229
|
-
accounts: {
|
|
230
|
-
state: args.state,
|
|
231
|
-
user: args.user,
|
|
232
|
-
authority: args.authority,
|
|
233
|
-
},
|
|
234
|
-
remainingAccounts: args.remainingAccounts,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Builds a `modifyOrder` instruction, mutating an existing resting order in place (e.g.
|
|
240
|
-
* new price/size/trigger) rather than cancel-and-replace.
|
|
241
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
242
|
-
* @param args.orderId - the program-assigned order ID to modify (use `buildModifyOrderByUserIdInstruction` to target by the caller-assigned tag instead).
|
|
243
|
-
* @param args.modifyParams - a `ModifyOrderParams` object; any `baseAssetAmount`/`price`/`triggerPrice` overrides use BASE_PRECISION (1e9) / PRICE_PRECISION (1e6) respectively.
|
|
244
|
-
* @param args.state - the global `State` PDA.
|
|
245
|
-
* @param args.user - the `User` account whose order is modified.
|
|
246
|
-
* @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `modify_order` accounts.
|
|
247
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
248
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` for the order's market.
|
|
249
|
-
* @returns the unsigned `modifyOrder` `TransactionInstruction`.
|
|
250
|
-
*/
|
|
251
|
-
export async function buildModifyOrderInstruction(args: {
|
|
252
|
-
program: VelocityProgram;
|
|
253
|
-
orderId: number;
|
|
254
|
-
modifyParams: any;
|
|
255
|
-
state: PublicKey;
|
|
256
|
-
user: PublicKey;
|
|
257
|
-
userStats: PublicKey;
|
|
258
|
-
authority: PublicKey;
|
|
259
|
-
remainingAccounts: AccountMeta[];
|
|
260
|
-
}): Promise<TransactionInstruction> {
|
|
261
|
-
return await (args.program.instruction as any).modifyOrder(
|
|
262
|
-
args.orderId,
|
|
263
|
-
args.modifyParams,
|
|
264
|
-
{
|
|
265
|
-
accounts: {
|
|
266
|
-
state: args.state,
|
|
267
|
-
user: args.user,
|
|
268
|
-
userStats: args.userStats,
|
|
269
|
-
authority: args.authority,
|
|
270
|
-
},
|
|
271
|
-
remainingAccounts: args.remainingAccounts,
|
|
272
|
-
}
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Builds a `modifyOrderByUserId` instruction, same as `buildModifyOrderInstruction` but
|
|
278
|
-
* targeting the order by its caller-assigned `userOrderId` tag.
|
|
279
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
280
|
-
* @param args.userOrderId - the caller-assigned order tag (`u8`) supplied when the order was placed.
|
|
281
|
-
* @param args.modifyParams - a `ModifyOrderParams` object; any `baseAssetAmount`/`price`/`triggerPrice` overrides use BASE_PRECISION (1e9) / PRICE_PRECISION (1e6) respectively.
|
|
282
|
-
* @param args.state - the global `State` PDA.
|
|
283
|
-
* @param args.user - the `User` account whose order is modified.
|
|
284
|
-
* @param args.userStats - accepted for forward-compatibility but not required by the current on-chain `modify_order_by_user_id` accounts.
|
|
285
|
-
* @param args.authority - signer that must own or be a registered delegate of `user`.
|
|
286
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` for the order's market.
|
|
287
|
-
* @returns the unsigned `modifyOrderByUserId` `TransactionInstruction`.
|
|
288
|
-
*/
|
|
289
|
-
export async function buildModifyOrderByUserIdInstruction(args: {
|
|
290
|
-
program: VelocityProgram;
|
|
291
|
-
userOrderId: number;
|
|
292
|
-
modifyParams: any;
|
|
293
|
-
state: PublicKey;
|
|
294
|
-
user: PublicKey;
|
|
295
|
-
userStats: PublicKey;
|
|
296
|
-
authority: PublicKey;
|
|
297
|
-
remainingAccounts: AccountMeta[];
|
|
298
|
-
}): Promise<TransactionInstruction> {
|
|
299
|
-
return await (args.program.instruction as any).modifyOrderByUserId(
|
|
300
|
-
args.userOrderId,
|
|
301
|
-
args.modifyParams,
|
|
302
|
-
{
|
|
303
|
-
accounts: {
|
|
304
|
-
state: args.state,
|
|
305
|
-
user: args.user,
|
|
306
|
-
userStats: args.userStats,
|
|
307
|
-
authority: args.authority,
|
|
308
|
-
},
|
|
309
|
-
remainingAccounts: args.remainingAccounts,
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { VelocityProgram } from '../../config';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Builds a `settlePnl` instruction, settling `user`'s realized (or, if the market is in
|
|
10
|
-
* `Settlement` status, expired) perp PnL on `marketIndex` against the quote spot market
|
|
11
|
-
* vault. Fully permissionless: `authority` does not need to own or be a delegate of
|
|
12
|
-
* `user` — any signer can crank this.
|
|
13
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
14
|
-
* @param args.marketIndex - the perp market whose position PnL is settled.
|
|
15
|
-
* @param args.state - the global `State` PDA.
|
|
16
|
-
* @param args.authority - any signer; not required to own `user`.
|
|
17
|
-
* @param args.user - the `User` account being settled.
|
|
18
|
-
* @param args.spotMarketVault - the quote (market index 0) spot market's token vault PDA.
|
|
19
|
-
* @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.
|
|
20
|
-
* @returns the unsigned `settlePnl` `TransactionInstruction`.
|
|
21
|
-
*/
|
|
22
|
-
export async function buildSettlePnlInstruction(args: {
|
|
23
|
-
program: VelocityProgram;
|
|
24
|
-
marketIndex: number;
|
|
25
|
-
state: PublicKey;
|
|
26
|
-
authority: PublicKey;
|
|
27
|
-
user: PublicKey;
|
|
28
|
-
spotMarketVault: PublicKey;
|
|
29
|
-
remainingAccounts: AccountMeta[];
|
|
30
|
-
}): Promise<TransactionInstruction> {
|
|
31
|
-
return await (args.program.instruction as any).settlePnl(args.marketIndex, {
|
|
32
|
-
accounts: {
|
|
33
|
-
state: args.state,
|
|
34
|
-
authority: args.authority,
|
|
35
|
-
user: args.user,
|
|
36
|
-
spotMarketVault: args.spotMarketVault,
|
|
37
|
-
},
|
|
38
|
-
remainingAccounts: args.remainingAccounts,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AccountMeta,
|
|
3
|
-
PublicKey,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
} from '@solana/web3.js';
|
|
6
|
-
import type { VelocityProgram } from '../../config';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Builds a `triggerOrder` instruction, flipping a resting trigger order (stop-loss /
|
|
10
|
-
* take-profit) into a fillable order once its trigger condition is met against the
|
|
11
|
-
* oracle price. Permissionless: `user` (the order owner) does not need to sign — only
|
|
12
|
-
* `authority` (owner/delegate of `filler`) does. Does not fill the order itself; a
|
|
13
|
-
* subsequent `fillPerpOrder` (or a `placeAndTake`) is needed to execute it.
|
|
14
|
-
* @param args.program - Anchor `Program<Velocity>` used to build the instruction.
|
|
15
|
-
* @param args.orderId - the trigger order's on-chain order ID.
|
|
16
|
-
* @param args.state - the global `State` PDA.
|
|
17
|
-
* @param args.filler - the keeper's `User` account submitting the trigger.
|
|
18
|
-
* @param args.user - the order owner's `User` account.
|
|
19
|
-
* @param args.authority - signer that must own or be a registered delegate of `filler`.
|
|
20
|
-
* @param args.remainingAccounts - oracle/market `AccountMeta[]` for the order's market.
|
|
21
|
-
* @returns the unsigned `triggerOrder` `TransactionInstruction`.
|
|
22
|
-
*/
|
|
23
|
-
export async function buildTriggerOrderInstruction(args: {
|
|
24
|
-
program: VelocityProgram;
|
|
25
|
-
orderId: number;
|
|
26
|
-
state: PublicKey;
|
|
27
|
-
filler: PublicKey;
|
|
28
|
-
user: PublicKey;
|
|
29
|
-
authority: PublicKey;
|
|
30
|
-
remainingAccounts: AccountMeta[];
|
|
31
|
-
}): Promise<TransactionInstruction> {
|
|
32
|
-
return await (args.program.instruction as any).triggerOrder(args.orderId, {
|
|
33
|
-
accounts: {
|
|
34
|
-
state: args.state,
|
|
35
|
-
filler: args.filler,
|
|
36
|
-
user: args.user,
|
|
37
|
-
authority: args.authority,
|
|
38
|
-
},
|
|
39
|
-
remainingAccounts: args.remainingAccounts,
|
|
40
|
-
});
|
|
41
|
-
}
|