@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"address": "vELoC1audYbSYVRXn1vPaV8Axoa9oU6BYmNGZZBDZ1P",
|
|
3
3
|
"metadata": {
|
|
4
4
|
"name": "velocity",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.163.0",
|
|
6
6
|
"spec": "0.1.0",
|
|
7
7
|
"description": "Created with Anchor"
|
|
8
8
|
},
|
|
@@ -6376,6 +6376,33 @@
|
|
|
6376
6376
|
}
|
|
6377
6377
|
]
|
|
6378
6378
|
},
|
|
6379
|
+
{
|
|
6380
|
+
"name": "reset_equity_floor_breaker",
|
|
6381
|
+
"discriminator": [
|
|
6382
|
+
230,
|
|
6383
|
+
181,
|
|
6384
|
+
202,
|
|
6385
|
+
36,
|
|
6386
|
+
127,
|
|
6387
|
+
56,
|
|
6388
|
+
56,
|
|
6389
|
+
27
|
|
6390
|
+
],
|
|
6391
|
+
"accounts": [
|
|
6392
|
+
{
|
|
6393
|
+
"name": "admin",
|
|
6394
|
+
"signer": true
|
|
6395
|
+
},
|
|
6396
|
+
{
|
|
6397
|
+
"name": "state"
|
|
6398
|
+
},
|
|
6399
|
+
{
|
|
6400
|
+
"name": "user_stats",
|
|
6401
|
+
"writable": true
|
|
6402
|
+
}
|
|
6403
|
+
],
|
|
6404
|
+
"args": []
|
|
6405
|
+
},
|
|
6379
6406
|
{
|
|
6380
6407
|
"name": "reset_perp_market_amm_oracle_twap",
|
|
6381
6408
|
"discriminator": [
|
|
@@ -7734,6 +7761,10 @@
|
|
|
7734
7761
|
{
|
|
7735
7762
|
"name": "amount",
|
|
7736
7763
|
"type": "u64"
|
|
7764
|
+
},
|
|
7765
|
+
{
|
|
7766
|
+
"name": "equity_floor_delta",
|
|
7767
|
+
"type": "u64"
|
|
7737
7768
|
}
|
|
7738
7769
|
]
|
|
7739
7770
|
},
|
|
@@ -8216,6 +8247,39 @@
|
|
|
8216
8247
|
}
|
|
8217
8248
|
]
|
|
8218
8249
|
},
|
|
8250
|
+
{
|
|
8251
|
+
"name": "trip_equity_floor_breaker",
|
|
8252
|
+
"discriminator": [
|
|
8253
|
+
133,
|
|
8254
|
+
184,
|
|
8255
|
+
25,
|
|
8256
|
+
80,
|
|
8257
|
+
193,
|
|
8258
|
+
52,
|
|
8259
|
+
162,
|
|
8260
|
+
249
|
|
8261
|
+
],
|
|
8262
|
+
"accounts": [
|
|
8263
|
+
{
|
|
8264
|
+
"name": "state"
|
|
8265
|
+
},
|
|
8266
|
+
{
|
|
8267
|
+
"name": "keeper",
|
|
8268
|
+
"docs": [
|
|
8269
|
+
"Any signer may trip the breaker; the proof is the margin calculation."
|
|
8270
|
+
],
|
|
8271
|
+
"signer": true
|
|
8272
|
+
},
|
|
8273
|
+
{
|
|
8274
|
+
"name": "user"
|
|
8275
|
+
},
|
|
8276
|
+
{
|
|
8277
|
+
"name": "user_stats",
|
|
8278
|
+
"writable": true
|
|
8279
|
+
}
|
|
8280
|
+
],
|
|
8281
|
+
"args": []
|
|
8282
|
+
},
|
|
8219
8283
|
{
|
|
8220
8284
|
"name": "update_admin",
|
|
8221
8285
|
"discriminator": [
|
|
@@ -9431,7 +9495,10 @@
|
|
|
9431
9495
|
},
|
|
9432
9496
|
{
|
|
9433
9497
|
"name": "authority",
|
|
9434
|
-
"signer": true
|
|
9498
|
+
"signer": true,
|
|
9499
|
+
"relations": [
|
|
9500
|
+
"keeper_stats"
|
|
9501
|
+
]
|
|
9435
9502
|
}
|
|
9436
9503
|
],
|
|
9437
9504
|
"args": []
|
|
@@ -9605,6 +9672,38 @@
|
|
|
9605
9672
|
}
|
|
9606
9673
|
]
|
|
9607
9674
|
},
|
|
9675
|
+
{
|
|
9676
|
+
"name": "update_perp_market_bankruptcy_if_floor_pct",
|
|
9677
|
+
"discriminator": [
|
|
9678
|
+
192,
|
|
9679
|
+
2,
|
|
9680
|
+
229,
|
|
9681
|
+
220,
|
|
9682
|
+
243,
|
|
9683
|
+
115,
|
|
9684
|
+
121,
|
|
9685
|
+
84
|
|
9686
|
+
],
|
|
9687
|
+
"accounts": [
|
|
9688
|
+
{
|
|
9689
|
+
"name": "admin",
|
|
9690
|
+
"signer": true
|
|
9691
|
+
},
|
|
9692
|
+
{
|
|
9693
|
+
"name": "state"
|
|
9694
|
+
},
|
|
9695
|
+
{
|
|
9696
|
+
"name": "perp_market",
|
|
9697
|
+
"writable": true
|
|
9698
|
+
}
|
|
9699
|
+
],
|
|
9700
|
+
"args": [
|
|
9701
|
+
{
|
|
9702
|
+
"name": "bankruptcy_if_floor_pct",
|
|
9703
|
+
"type": "u32"
|
|
9704
|
+
}
|
|
9705
|
+
]
|
|
9706
|
+
},
|
|
9608
9707
|
{
|
|
9609
9708
|
"name": "update_perp_market_base_spread",
|
|
9610
9709
|
"discriminator": [
|
|
@@ -12221,6 +12320,38 @@
|
|
|
12221
12320
|
}
|
|
12222
12321
|
]
|
|
12223
12322
|
},
|
|
12323
|
+
{
|
|
12324
|
+
"name": "update_user_equity_floor",
|
|
12325
|
+
"discriminator": [
|
|
12326
|
+
49,
|
|
12327
|
+
87,
|
|
12328
|
+
139,
|
|
12329
|
+
119,
|
|
12330
|
+
136,
|
|
12331
|
+
239,
|
|
12332
|
+
186,
|
|
12333
|
+
104
|
|
12334
|
+
],
|
|
12335
|
+
"accounts": [
|
|
12336
|
+
{
|
|
12337
|
+
"name": "admin",
|
|
12338
|
+
"signer": true
|
|
12339
|
+
},
|
|
12340
|
+
{
|
|
12341
|
+
"name": "state"
|
|
12342
|
+
},
|
|
12343
|
+
{
|
|
12344
|
+
"name": "user",
|
|
12345
|
+
"writable": true
|
|
12346
|
+
}
|
|
12347
|
+
],
|
|
12348
|
+
"args": [
|
|
12349
|
+
{
|
|
12350
|
+
"name": "equity_floor",
|
|
12351
|
+
"type": "u64"
|
|
12352
|
+
}
|
|
12353
|
+
]
|
|
12354
|
+
},
|
|
12224
12355
|
{
|
|
12225
12356
|
"name": "update_user_idle",
|
|
12226
12357
|
"discriminator": [
|
|
@@ -16011,6 +16142,21 @@
|
|
|
16011
16142
|
"code": 6356,
|
|
16012
16143
|
"name": "InvalidNativePerpMarketAccount",
|
|
16013
16144
|
"msg": "Native dispatch: supplied market account is not a Velocity perp market"
|
|
16145
|
+
},
|
|
16146
|
+
{
|
|
16147
|
+
"code": 6357,
|
|
16148
|
+
"name": "IsolatedPositionDisabled",
|
|
16149
|
+
"msg": "Isolated positions are not enabled in this build"
|
|
16150
|
+
},
|
|
16151
|
+
{
|
|
16152
|
+
"code": 6358,
|
|
16153
|
+
"name": "EquityBelowFloor",
|
|
16154
|
+
"msg": "Account equity is below the user-set equity floor"
|
|
16155
|
+
},
|
|
16156
|
+
{
|
|
16157
|
+
"code": 6359,
|
|
16158
|
+
"name": "InvalidEquityFloorTransfer",
|
|
16159
|
+
"msg": "Invalid equity floor transfer between subaccounts"
|
|
16014
16160
|
}
|
|
16015
16161
|
],
|
|
16016
16162
|
"types": [
|
|
@@ -21026,20 +21172,21 @@
|
|
|
21026
21172
|
"type": "i8"
|
|
21027
21173
|
},
|
|
21028
21174
|
{
|
|
21029
|
-
"name": "
|
|
21175
|
+
"name": "bankruptcy_if_floor_pct",
|
|
21030
21176
|
"docs": [
|
|
21031
|
-
"
|
|
21032
|
-
"
|
|
21033
|
-
"
|
|
21034
|
-
"
|
|
21035
|
-
"
|
|
21177
|
+
"Floor on the unswept IF-fee carveout, as a percentage of open-interest",
|
|
21178
|
+
"notional (PERCENTAGE_PRECISION; 0 disables). The fee sweep's IF drain",
|
|
21179
|
+
"leaves `pending_if_fee` at (at least) this floor, so a standing",
|
|
21180
|
+
"first-loss tranche is always available to `resolve_perp_bankruptcy` —",
|
|
21181
|
+
"a permissionless sweep (or the inline sweep on any pnl settle) cannot",
|
|
21182
|
+
"drain the tranche below it ahead of a bankruptcy resolution. Notional",
|
|
21183
|
+
"is valued at the market's own oracle TWAP so a manipulated spot print",
|
|
21184
|
+
"can't crush the floor. Occupies the former 4-byte trailing padding",
|
|
21185
|
+
"before `market_stats` (same offset/alignment on all targets), so",
|
|
21186
|
+
"existing accounts read 0 = disabled until the admin sets it;",
|
|
21187
|
+
"new markets initialize to `DEFAULT_BANKRUPTCY_IF_FLOOR_PCT`."
|
|
21036
21188
|
],
|
|
21037
|
-
"type":
|
|
21038
|
-
"array": [
|
|
21039
|
-
"u8",
|
|
21040
|
-
4
|
|
21041
|
-
]
|
|
21042
|
-
}
|
|
21189
|
+
"type": "u32"
|
|
21043
21190
|
},
|
|
21044
21191
|
{
|
|
21045
21192
|
"name": "market_stats",
|
|
@@ -23715,7 +23862,26 @@
|
|
|
23715
23862
|
"type": {
|
|
23716
23863
|
"array": [
|
|
23717
23864
|
"u8",
|
|
23718
|
-
|
|
23865
|
+
3
|
|
23866
|
+
]
|
|
23867
|
+
}
|
|
23868
|
+
},
|
|
23869
|
+
{
|
|
23870
|
+
"name": "equity_floor",
|
|
23871
|
+
"docs": [
|
|
23872
|
+
"Minimum account equity (cross-margin total collateral) required for",
|
|
23873
|
+
"risk-increasing orders, fills, withdrawals and deposit transfers.",
|
|
23874
|
+
"Settable only by the warm/cold admin; 0 disables the check.",
|
|
23875
|
+
"precision: QUOTE_PRECISION"
|
|
23876
|
+
],
|
|
23877
|
+
"type": "u64"
|
|
23878
|
+
},
|
|
23879
|
+
{
|
|
23880
|
+
"name": "padding2",
|
|
23881
|
+
"type": {
|
|
23882
|
+
"array": [
|
|
23883
|
+
"u8",
|
|
23884
|
+
8
|
|
23719
23885
|
]
|
|
23720
23886
|
}
|
|
23721
23887
|
}
|
|
@@ -23904,12 +24070,22 @@
|
|
|
23904
24070
|
],
|
|
23905
24071
|
"type": "u8"
|
|
23906
24072
|
},
|
|
24073
|
+
{
|
|
24074
|
+
"name": "equity_breaker_tripped",
|
|
24075
|
+
"docs": [
|
|
24076
|
+
"Set by the permissionless `trip_equity_floor_breaker` instruction when",
|
|
24077
|
+
"any of the authority's subaccounts falls below its equity floor.",
|
|
24078
|
+
"While set, every subaccount of the authority rejects risk-increasing",
|
|
24079
|
+
"fills, withdrawals and transfers out. Cleared only by the warm admin."
|
|
24080
|
+
],
|
|
24081
|
+
"type": "u8"
|
|
24082
|
+
},
|
|
23907
24083
|
{
|
|
23908
24084
|
"name": "padding",
|
|
23909
24085
|
"type": {
|
|
23910
24086
|
"array": [
|
|
23911
24087
|
"u8",
|
|
23912
|
-
|
|
24088
|
+
62
|
|
23913
24089
|
]
|
|
23914
24090
|
}
|
|
23915
24091
|
}
|
|
@@ -12,6 +12,7 @@ import { WebsocketSubscription } from './WebsocketSubscription';
|
|
|
12
12
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
13
13
|
import { EventEmitter } from 'events';
|
|
14
14
|
import { grpcSubscription } from './grpcSubscription';
|
|
15
|
+
export declare const USER_LAST_ACTIVE_SLOT_OFFSET = 4448;
|
|
15
16
|
/**
|
|
16
17
|
* OrderSubscriber — maintains a live, in-memory map of every `User` account
|
|
17
18
|
* (and therefore every open order) on the program, refreshed via polling,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderSubscriber = void 0;
|
|
3
|
+
exports.OrderSubscriber = exports.USER_LAST_ACTIVE_SLOT_OFFSET = void 0;
|
|
4
4
|
const memcmp_1 = require("../memcmp");
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const buffer_1 = require("buffer");
|
|
@@ -20,8 +20,11 @@ const numericConstants_1 = require("../constants/numericConstants");
|
|
|
20
20
|
* was for the older 4376-byte layout; the current Velocity layout is 4496
|
|
21
21
|
* bytes, shifting this field +120 bytes. With the wrong offset this read 8
|
|
22
22
|
* zero-padding bytes, so the staleness guard rejected every post-load update.
|
|
23
|
+
* Exported so downstream `tryUpdateUserAccount` overrides (e.g. the keeper
|
|
24
|
+
* bots' filtered order subscriber) share the same offset instead of
|
|
25
|
+
* re-hardcoding it.
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
exports.USER_LAST_ACTIVE_SLOT_OFFSET = 4448;
|
|
25
28
|
/**
|
|
26
29
|
* OrderSubscriber — maintains a live, in-memory map of every `User` account
|
|
27
30
|
* (and therefore every open order) on the program, refreshed via polling,
|
|
@@ -124,6 +127,9 @@ class OrderSubscriber {
|
|
|
124
127
|
await this.velocityClient.connection._rpcRequest('getProgramAccounts', rpcRequestArgs);
|
|
125
128
|
const rpcResponseAndContext = rpcJSONResponse.result;
|
|
126
129
|
const slot = rpcResponseAndContext.context.slot;
|
|
130
|
+
if (!this.mostRecentSlot || slot > this.mostRecentSlot) {
|
|
131
|
+
this.mostRecentSlot = slot;
|
|
132
|
+
}
|
|
127
133
|
for (const programAccount of rpcResponseAndContext.value) {
|
|
128
134
|
const key = programAccount.pubkey.toString();
|
|
129
135
|
this.tryUpdateUserAccount(key, 'raw', programAccount.account.data, slot);
|
|
@@ -168,7 +174,7 @@ class OrderSubscriber {
|
|
|
168
174
|
if (dataType === 'raw') {
|
|
169
175
|
// @ts-ignore
|
|
170
176
|
const buffer = buffer_1.Buffer.from(data[0], data[1]);
|
|
171
|
-
const newLastActiveSlot = new anchor_1.BN(buffer.subarray(USER_LAST_ACTIVE_SLOT_OFFSET, USER_LAST_ACTIVE_SLOT_OFFSET + 8), undefined, 'le');
|
|
177
|
+
const newLastActiveSlot = new anchor_1.BN(buffer.subarray(exports.USER_LAST_ACTIVE_SLOT_OFFSET, exports.USER_LAST_ACTIVE_SLOT_OFFSET + 8), undefined, 'le');
|
|
172
178
|
if (slotAndUserAccount &&
|
|
173
179
|
slotAndUserAccount.userAccount.lastActiveSlot.gt(newLastActiveSlot)) {
|
|
174
180
|
return;
|
|
@@ -177,7 +183,7 @@ class OrderSubscriber {
|
|
|
177
183
|
}
|
|
178
184
|
else if (dataType === 'buffer') {
|
|
179
185
|
const buffer = data;
|
|
180
|
-
const newLastActiveSlot = new anchor_1.BN(buffer.subarray(USER_LAST_ACTIVE_SLOT_OFFSET, USER_LAST_ACTIVE_SLOT_OFFSET + 8), undefined, 'le');
|
|
186
|
+
const newLastActiveSlot = new anchor_1.BN(buffer.subarray(exports.USER_LAST_ACTIVE_SLOT_OFFSET, exports.USER_LAST_ACTIVE_SLOT_OFFSET + 8), undefined, 'le');
|
|
181
187
|
if (slotAndUserAccount &&
|
|
182
188
|
slotAndUserAccount.userAccount.lastActiveSlot.gt(newLastActiveSlot)) {
|
|
183
189
|
return;
|
|
@@ -127,6 +127,36 @@ class PythLazerSubscriber {
|
|
|
127
127
|
});
|
|
128
128
|
// Reset allSubscribedIds to rebuild with only stable feeds
|
|
129
129
|
this.allSubscribedIds = [];
|
|
130
|
+
// addMessageListener is global to the client (fires for every message,
|
|
131
|
+
// not scoped to a subscription), and each message carries its own
|
|
132
|
+
// subscriptionId — so one listener serves all subscriptions. Registering
|
|
133
|
+
// it per chunk would run every message once per chunk.
|
|
134
|
+
this.pythLazerClient.addMessageListener((message) => {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
this.receivingData = true;
|
|
137
|
+
clearTimeout(this.timeoutId);
|
|
138
|
+
switch (message.type) {
|
|
139
|
+
case 'json': {
|
|
140
|
+
if (message.value.type == 'streamUpdated') {
|
|
141
|
+
if ((_a = message.value.solana) === null || _a === void 0 ? void 0 : _a.data) {
|
|
142
|
+
this.feedIdChunkToPriceMessage.set(this.subscriptionIdsToFeedIdsHash.get(message.value.subscriptionId), message.value.solana.data);
|
|
143
|
+
}
|
|
144
|
+
if ((_b = message.value.parsed) === null || _b === void 0 ? void 0 : _b.priceFeeds) {
|
|
145
|
+
for (const priceFeed of message.value.parsed.priceFeeds) {
|
|
146
|
+
const price = Number(priceFeed.price) *
|
|
147
|
+
Math.pow(10, Number(priceFeed.exponent));
|
|
148
|
+
this.feedIdToPrice.set(priceFeed.priceFeedId, price);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
default: {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
this.setTimeout();
|
|
159
|
+
});
|
|
130
160
|
let subscriptionId = 1;
|
|
131
161
|
for (const priceFeedArray of this.priceFeedArrays) {
|
|
132
162
|
const filteredFeedIds = this.filterStableFeeds(priceFeedArray.priceFeedIds);
|
|
@@ -153,33 +183,13 @@ class PythLazerSubscriber {
|
|
|
153
183
|
this.marketIndextoPriceFeedIdChunk.delete(marketIndex);
|
|
154
184
|
}
|
|
155
185
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if ((_a = message.value.solana) === null || _a === void 0 ? void 0 : _a.data) {
|
|
164
|
-
this.feedIdChunkToPriceMessage.set(this.subscriptionIdsToFeedIdsHash.get(message.value.subscriptionId), message.value.solana.data);
|
|
165
|
-
}
|
|
166
|
-
if ((_b = message.value.parsed) === null || _b === void 0 ? void 0 : _b.priceFeeds) {
|
|
167
|
-
for (const priceFeed of message.value.parsed.priceFeeds) {
|
|
168
|
-
const price = Number(priceFeed.price) *
|
|
169
|
-
Math.pow(10, Number(priceFeed.exponent));
|
|
170
|
-
this.feedIdToPrice.set(priceFeed.priceFeedId, price);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
default: {
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
this.setTimeout();
|
|
181
|
-
});
|
|
182
|
-
this.pythLazerClient.send({
|
|
186
|
+
// Use subscribe() (not send()): subscribe() registers the request in
|
|
187
|
+
// the pool's subscriptions map so ResilientWebSocket replays it on
|
|
188
|
+
// every socket reconnect. send() fires once and is never replayed, so
|
|
189
|
+
// after the first heartbeat-timeout reconnect the socket streams
|
|
190
|
+
// nothing — forcing the watchdog to tear down the whole client and
|
|
191
|
+
// reopen numConnections fresh sockets. subscribe() recovers in place.
|
|
192
|
+
this.pythLazerClient.subscribe({
|
|
183
193
|
type: 'subscribe',
|
|
184
194
|
subscriptionId,
|
|
185
195
|
priceFeedIds: filteredFeedIds,
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -1205,6 +1205,8 @@ export type PerpMarketAccount = {
|
|
|
1205
1205
|
protocolLiquidationFee: number;
|
|
1206
1206
|
/** QUOTE_PRECISION (1e6); pnl-pool retention buffer the fee-sweep leaves untouched above `max(net_user_pnl, 0)` */
|
|
1207
1207
|
feePoolBufferTarget: BN;
|
|
1208
|
+
/** PERCENTAGE_PRECISION (1e6 = 100%); fraction of OI notional (at the oracle TWAP) the sweep leaves behind in `feeLedger.pendingIfFee` as a standing bankruptcy first-loss tranche; 0 disables */
|
|
1209
|
+
bankruptcyIfFloorPct: number;
|
|
1208
1210
|
/** MARGIN_PRECISION (1e4); scales margin ratio up for large positions */
|
|
1209
1211
|
imfFactor: number;
|
|
1210
1212
|
/** MARGIN_PRECISION (1e4); discounts positive-unrealized-pnl asset weight for large positions */
|
|
@@ -1642,6 +1644,8 @@ export type UserStatsAccount = {
|
|
|
1642
1644
|
authority: PublicKey;
|
|
1643
1645
|
ifStakedQuoteAssetAmount: BN;
|
|
1644
1646
|
delegatePermissions: number;
|
|
1647
|
+
/** non-zero when the permissionless `tripEquityFloorBreaker` fired: every subaccount of the authority rejects risk-increasing fills, withdrawals and transfers out until the warm admin resets */
|
|
1648
|
+
equityBreakerTripped: number;
|
|
1645
1649
|
};
|
|
1646
1650
|
/** Decoded mirror of the on-chain `User` (sub-account) zero-copy account. */
|
|
1647
1651
|
export type UserAccount = {
|
|
@@ -1684,6 +1688,8 @@ export type UserAccount = {
|
|
|
1684
1688
|
poolId: number;
|
|
1685
1689
|
/** bitmask, see `SpecialUserStatus` */
|
|
1686
1690
|
specialUserStatus: number;
|
|
1691
|
+
/** QUOTE_PRECISION (1e6); admin-set minimum cross-margin total collateral for risk-increasing orders, fills, withdrawals and transfers; 0 = disabled */
|
|
1692
|
+
equityFloor: BN;
|
|
1687
1693
|
};
|
|
1688
1694
|
/** A user's balance in one spot market. Decoded mirror of the on-chain `SpotPosition`. */
|
|
1689
1695
|
export type SpotPosition = {
|
package/lib/browser/user.d.ts
CHANGED
|
@@ -410,6 +410,21 @@ export declare class User {
|
|
|
410
410
|
* @returns Precision QUOTE_PRECISION (1e6).
|
|
411
411
|
*/
|
|
412
412
|
getTotalCollateral(marginCategory?: MarginCategory, strict?: boolean, includeOpenOrders?: boolean, liquidationBuffer?: BN, perpMarketIndex?: number): BN;
|
|
413
|
+
/**
|
|
414
|
+
* True when the account has an admin-set `equityFloor` and its cross-margin
|
|
415
|
+
* total collateral is below it. While below the floor, the program rejects
|
|
416
|
+
* risk-increasing order placement and fills, withdrawals, and transfers out
|
|
417
|
+
* of the account (`EquityBelowFloor`); reduce-only activity stays allowed.
|
|
418
|
+
* Mirrors `User::is_below_equity_floor` on-chain.
|
|
419
|
+
* @param strict Use TWAP-bounded oracle pricing, matching the withdraw path. Defaults to false.
|
|
420
|
+
*/
|
|
421
|
+
isBelowEquityFloor(strict?: boolean): boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Cross-margin total collateral in excess of the admin-set `equityFloor`,
|
|
424
|
+
* floored at zero (QUOTE_PRECISION). Unbounded (`null`) when no floor is set.
|
|
425
|
+
* @param strict Use TWAP-bounded oracle pricing. Defaults to false.
|
|
426
|
+
*/
|
|
427
|
+
getEquityAboveFloor(strict?: boolean): BN | null;
|
|
413
428
|
/**
|
|
414
429
|
* Builds the liquidation-buffer map to pass into margin calculations while
|
|
415
430
|
* a liquidation is in progress: `'cross'` is set to the state account's
|
|
@@ -909,9 +924,11 @@ export declare class User {
|
|
|
909
924
|
};
|
|
910
925
|
/**
|
|
911
926
|
* Returns the numerically-lowest (i.e. safest) contract/asset tier across
|
|
912
|
-
* the user's active positions — perp tiers from active perp positions
|
|
913
|
-
*
|
|
914
|
-
*
|
|
927
|
+
* the user's active positions — perp tiers from active perp positions
|
|
928
|
+
* (skipping zero-base positions whose only exposure is positive unsettled
|
|
929
|
+
* pnl: those are claims on the pnl pool, not liabilities), spot tiers only
|
|
930
|
+
* from spot **borrows** (deposits are skipped, since asset tier only
|
|
931
|
+
* restricts borrowing exposure). Defaults to `4` (the
|
|
915
932
|
* second-riskiest tier index) when the user has no positions of that kind —
|
|
916
933
|
* this is a permissive default intended for callers doing tier-safety
|
|
917
934
|
* comparisons (see `perpTierIsAsSafeAs` in `math/tiers`), not a claim that
|
package/lib/browser/user.js
CHANGED
|
@@ -898,6 +898,33 @@ class User {
|
|
|
898
898
|
}
|
|
899
899
|
return marginCalc.totalCollateral;
|
|
900
900
|
}
|
|
901
|
+
/**
|
|
902
|
+
* True when the account has an admin-set `equityFloor` and its cross-margin
|
|
903
|
+
* total collateral is below it. While below the floor, the program rejects
|
|
904
|
+
* risk-increasing order placement and fills, withdrawals, and transfers out
|
|
905
|
+
* of the account (`EquityBelowFloor`); reduce-only activity stays allowed.
|
|
906
|
+
* Mirrors `User::is_below_equity_floor` on-chain.
|
|
907
|
+
* @param strict Use TWAP-bounded oracle pricing, matching the withdraw path. Defaults to false.
|
|
908
|
+
*/
|
|
909
|
+
isBelowEquityFloor(strict = false) {
|
|
910
|
+
const equityFloor = this.getUserAccountOrThrow().equityFloor;
|
|
911
|
+
if (equityFloor.lte(numericConstants_1.ZERO)) {
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
return this.getTotalCollateral('Initial', strict).lt(equityFloor);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Cross-margin total collateral in excess of the admin-set `equityFloor`,
|
|
918
|
+
* floored at zero (QUOTE_PRECISION). Unbounded (`null`) when no floor is set.
|
|
919
|
+
* @param strict Use TWAP-bounded oracle pricing. Defaults to false.
|
|
920
|
+
*/
|
|
921
|
+
getEquityAboveFloor(strict = false) {
|
|
922
|
+
const equityFloor = this.getUserAccountOrThrow().equityFloor;
|
|
923
|
+
if (equityFloor.lte(numericConstants_1.ZERO)) {
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
return anchor_1.BN.max(this.getTotalCollateral('Initial', strict).sub(equityFloor), numericConstants_1.ZERO);
|
|
927
|
+
}
|
|
901
928
|
/**
|
|
902
929
|
* Builds the liquidation-buffer map to pass into margin calculations while
|
|
903
930
|
* a liquidation is in progress: `'cross'` is set to the state account's
|
|
@@ -2353,7 +2380,16 @@ class User {
|
|
|
2353
2380
|
const spotMarket = this.velocityClient.getSpotMarketAccountOrThrow(marketIndex);
|
|
2354
2381
|
// eslint-disable-next-line prefer-const
|
|
2355
2382
|
let { borrowLimit, withdrawLimit } = (0, spotBalance_2.calculateWithdrawLimit)(spotMarket, nowTs);
|
|
2356
|
-
|
|
2383
|
+
// the withdraw path enforces the equity floor on post-withdraw total
|
|
2384
|
+
// collateral, so equity above the floor caps free collateral here
|
|
2385
|
+
const equityAboveFloor = this.getEquityAboveFloor(true);
|
|
2386
|
+
if (equityAboveFloor !== null && equityAboveFloor.eq(numericConstants_1.ZERO)) {
|
|
2387
|
+
return numericConstants_1.ZERO;
|
|
2388
|
+
}
|
|
2389
|
+
let freeCollateral = this.getFreeCollateral();
|
|
2390
|
+
if (equityAboveFloor !== null) {
|
|
2391
|
+
freeCollateral = anchor_1.BN.min(freeCollateral, equityAboveFloor);
|
|
2392
|
+
}
|
|
2357
2393
|
const initialMarginRequirement = this.getInitialMarginRequirement();
|
|
2358
2394
|
const oracleData = this.getOracleDataForSpotMarket(marketIndex);
|
|
2359
2395
|
const { numeratorScale, denominatorScale } = spotMarket.decimals > 6
|
|
@@ -2583,9 +2619,11 @@ class User {
|
|
|
2583
2619
|
}
|
|
2584
2620
|
/**
|
|
2585
2621
|
* Returns the numerically-lowest (i.e. safest) contract/asset tier across
|
|
2586
|
-
* the user's active positions — perp tiers from active perp positions
|
|
2587
|
-
*
|
|
2588
|
-
*
|
|
2622
|
+
* the user's active positions — perp tiers from active perp positions
|
|
2623
|
+
* (skipping zero-base positions whose only exposure is positive unsettled
|
|
2624
|
+
* pnl: those are claims on the pnl pool, not liabilities), spot tiers only
|
|
2625
|
+
* from spot **borrows** (deposits are skipped, since asset tier only
|
|
2626
|
+
* restricts borrowing exposure). Defaults to `4` (the
|
|
2589
2627
|
* second-riskiest tier index) when the user has no positions of that kind —
|
|
2590
2628
|
* this is a permissive default intended for callers doing tier-safety
|
|
2591
2629
|
* comparisons (see `perpTierIsAsSafeAs` in `math/tiers`), not a claim that
|
|
@@ -2593,9 +2631,19 @@ class User {
|
|
|
2593
2631
|
* @returns Lower `perpTier`/`spotTier` numbers indicate a safer tier; see `math/tiers` (`getPerpMarketTierNumber`/`getSpotMarketTierNumber`) for the numbering.
|
|
2594
2632
|
*/
|
|
2595
2633
|
getSafestTiers() {
|
|
2634
|
+
var _a;
|
|
2596
2635
|
let safestPerpTier = 4;
|
|
2597
2636
|
let safestSpotTier = 4;
|
|
2598
2637
|
for (const perpPosition of this.getActivePerpPositions()) {
|
|
2638
|
+
// a zero-base position with positive unsettled pnl is a claim on the
|
|
2639
|
+
// market's pnl pool, not a liability (mirrors
|
|
2640
|
+
// calculate_user_safest_position_tiers in math/margin.rs)
|
|
2641
|
+
if (perpPosition.baseAssetAmount.eq(numericConstants_1.ZERO) &&
|
|
2642
|
+
!(0, position_1.hasOpenOrders)(perpPosition) &&
|
|
2643
|
+
!((_a = perpPosition.isolatedPositionScaledBalance) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO).gt(numericConstants_1.ZERO) &&
|
|
2644
|
+
perpPosition.quoteAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
2645
|
+
continue;
|
|
2646
|
+
}
|
|
2599
2647
|
safestPerpTier = Math.min(safestPerpTier, (0, tiers_1.getPerpMarketTierNumber)(this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex)));
|
|
2600
2648
|
}
|
|
2601
2649
|
for (const spotPosition of this.getActiveSpotPositions()) {
|