@drift-labs/sdk 2.97.0-beta.21 → 2.97.0-beta.23
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/VERSION +1 -1
- package/bun.lockb +0 -0
- package/lib/{accounts → browser/accounts}/bulkAccountLoader.d.ts +1 -0
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +16 -0
- package/lib/browser/accounts/grpcAccountSubscriber.js +154 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.js +97 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +171 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.js +28 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.js +28 -0
- package/lib/{accounts → browser/accounts}/types.d.ts +8 -0
- package/lib/{accounts → browser/accounts}/webSocketAccountSubscriber.d.ts +2 -1
- package/lib/{accounts → browser/accounts}/webSocketDriftClientAccountSubscriber.d.ts +3 -3
- package/lib/{accounts → browser/accounts}/webSocketProgramAccountSubscriber.d.ts +2 -1
- package/lib/{addresses → browser/addresses}/pda.d.ts +1 -0
- package/lib/{addresses → browser/addresses}/pda.js +8 -1
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
- package/lib/{auctionSubscriber → browser/auctionSubscriber}/index.d.ts +1 -0
- package/lib/browser/auctionSubscriber/index.js +19 -0
- package/lib/{auctionSubscriber → browser/auctionSubscriber}/types.d.ts +2 -0
- package/lib/{bankrun → browser/bankrun}/bankrunConnection.d.ts +1 -0
- package/lib/{decode → browser/decode}/phoenix.d.ts +1 -0
- package/lib/{decode → browser/decode}/user.d.ts +1 -0
- package/lib/{dlob → browser/dlob}/DLOBOrders.d.ts +1 -0
- package/lib/{driftClient.d.ts → browser/driftClient.d.ts} +11 -5
- package/lib/{driftClient.js → browser/driftClient.js} +132 -34
- package/lib/{driftClientConfig.d.ts → browser/driftClientConfig.d.ts} +6 -1
- package/lib/{idl → browser/idl}/drift.json +256 -0
- package/lib/browser/isomorphic/grpc.browser.d.ts +1 -0
- package/lib/browser/isomorphic/grpc.browser.js +8 -0
- package/lib/browser/isomorphic/grpc.d.ts +1 -0
- package/lib/browser/isomorphic/grpc.js +8 -0
- package/lib/browser/isomorphic/grpc.node.d.ts +5 -0
- package/lib/{math → browser/math}/oracles.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/prelaunchOracleClient.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/pythClient.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/pythPullClient.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/quoteAssetOracleClient.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/switchboardClient.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/switchboardOnDemandClient.d.ts +1 -0
- package/lib/{oracles → browser/oracles}/types.d.ts +1 -0
- package/lib/{orderSubscriber → browser/orderSubscriber}/OrderSubscriber.d.ts +3 -1
- package/lib/{orderSubscriber → browser/orderSubscriber}/OrderSubscriber.js +18 -4
- package/lib/browser/orderSubscriber/grpcSubscription.d.ts +22 -0
- package/lib/browser/orderSubscriber/grpcSubscription.js +66 -0
- package/lib/{orderSubscriber → browser/orderSubscriber}/types.d.ts +9 -0
- package/lib/{token → browser/token}/index.d.ts +1 -0
- package/lib/{tx → browser/tx}/baseTxSender.d.ts +1 -0
- package/lib/{tx → browser/tx}/fastSingleTxSender.d.ts +1 -0
- package/lib/{tx → browser/tx}/forwardOnlyTxSender.d.ts +1 -0
- package/lib/{tx → browser/tx}/retryTxSender.d.ts +1 -0
- package/lib/{tx → browser/tx}/types.d.ts +1 -0
- package/lib/{tx → browser/tx}/whileValidTxSender.d.ts +1 -0
- package/lib/{types.d.ts → browser/types.d.ts} +20 -0
- package/lib/{user.js → browser/user.js} +11 -4
- package/lib/{userConfig.d.ts → browser/userConfig.d.ts} +6 -1
- package/lib/{userMap → browser/userMap}/WebsocketSubscription.d.ts +1 -0
- package/lib/browser/userMap/grpcSubscription.d.ts +24 -0
- package/lib/browser/userMap/grpcSubscription.js +40 -0
- package/lib/{userMap → browser/userMap}/userMap.js +17 -1
- package/lib/{userMap → browser/userMap}/userMapConfig.d.ts +6 -0
- package/lib/{userStats.js → browser/userStats.js} +11 -4
- package/lib/{userStatsConfig.d.ts → browser/userStatsConfig.d.ts} +6 -0
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/basicUserAccountSubscriber.js +38 -0
- package/lib/node/accounts/bulkAccountLoader.d.ts +37 -0
- package/lib/node/accounts/bulkAccountLoader.js +222 -0
- package/lib/node/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/node/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/node/accounts/bulkUserSubscription.d.ts +7 -0
- package/lib/node/accounts/bulkUserSubscription.js +21 -0
- package/lib/node/accounts/fetch.d.ts +6 -0
- package/lib/node/accounts/fetch.js +30 -0
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +16 -0
- package/lib/node/accounts/grpcAccountSubscriber.js +154 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +97 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +171 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.js +28 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.js +28 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.js +48 -0
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +415 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.js +78 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.js +78 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.js +102 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +94 -0
- package/lib/node/accounts/testBulkAccountLoader.d.ts +4 -0
- package/lib/node/accounts/testBulkAccountLoader.js +45 -0
- package/lib/node/accounts/types.d.ts +155 -0
- package/lib/node/accounts/types.js +16 -0
- package/lib/node/accounts/utils.d.ts +8 -0
- package/lib/node/accounts/utils.js +39 -0
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/webSocketAccountSubscriber.js +149 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +352 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +34 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.js +127 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.js +61 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
- package/lib/node/addresses/marketAddresses.d.ts +2 -0
- package/lib/node/addresses/marketAddresses.js +15 -0
- package/lib/node/addresses/pda.d.ts +30 -0
- package/lib/node/addresses/pda.js +193 -0
- package/lib/node/adminClient.d.ts +202 -0
- package/lib/node/adminClient.js +1826 -0
- package/lib/node/assert/assert.d.ts +1 -0
- package/lib/node/assert/assert.js +9 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +14 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.js +32 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
- package/lib/node/auctionSubscriber/index.d.ts +3 -0
- package/lib/node/auctionSubscriber/index.js +19 -0
- package/lib/node/auctionSubscriber/types.d.ts +14 -0
- package/lib/node/auctionSubscriber/types.js +2 -0
- package/lib/node/bankrun/bankrunConnection.d.ts +74 -0
- package/lib/node/bankrun/bankrunConnection.js +318 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +89 -0
- package/lib/node/blockhashSubscriber/index.d.ts +1 -0
- package/lib/node/blockhashSubscriber/index.js +17 -0
- package/lib/node/blockhashSubscriber/types.d.ts +7 -0
- package/lib/node/blockhashSubscriber/types.js +2 -0
- package/lib/node/clock/clockSubscriber.d.ts +31 -0
- package/lib/node/clock/clockSubscriber.js +80 -0
- package/lib/node/config.d.ts +58 -0
- package/lib/node/config.js +126 -0
- package/lib/node/constants/numericConstants.d.ts +71 -0
- package/lib/node/constants/numericConstants.js +75 -0
- package/lib/node/constants/perpMarkets.d.ts +19 -0
- package/lib/node/constants/perpMarkets.js +868 -0
- package/lib/node/constants/spotMarkets.d.ts +23 -0
- package/lib/node/constants/spotMarkets.js +361 -0
- package/lib/node/constants/txConstants.d.ts +1 -0
- package/lib/node/constants/txConstants.js +4 -0
- package/lib/node/decode/phoenix.d.ts +7 -0
- package/lib/node/decode/phoenix.js +159 -0
- package/lib/node/decode/user.d.ts +4 -0
- package/lib/node/decode/user.js +339 -0
- package/lib/node/dlob/DLOB.d.ts +166 -0
- package/lib/node/dlob/DLOB.js +1142 -0
- package/lib/node/dlob/DLOBApiClient.d.ts +14 -0
- package/lib/node/dlob/DLOBApiClient.js +34 -0
- package/lib/node/dlob/DLOBNode.d.ts +57 -0
- package/lib/node/dlob/DLOBNode.js +86 -0
- package/lib/node/dlob/DLOBOrders.d.ts +17 -0
- package/lib/node/dlob/DLOBOrders.js +40 -0
- package/lib/node/dlob/DLOBSubscriber.d.ts +54 -0
- package/lib/node/dlob/DLOBSubscriber.js +139 -0
- package/lib/node/dlob/NodeList.d.ts +27 -0
- package/lib/node/dlob/NodeList.js +141 -0
- package/lib/node/dlob/dlobIdl.json +248 -0
- package/lib/node/dlob/orderBookLevels.d.ts +72 -0
- package/lib/node/dlob/orderBookLevels.js +438 -0
- package/lib/node/dlob/types.d.ts +18 -0
- package/lib/node/dlob/types.js +2 -0
- package/lib/node/driftClient.d.ts +820 -0
- package/lib/node/driftClient.js +4487 -0
- package/lib/node/driftClientConfig.d.ts +49 -0
- package/lib/node/driftClientConfig.js +2 -0
- package/lib/node/events/eventList.d.ts +22 -0
- package/lib/node/events/eventList.js +80 -0
- package/lib/node/events/eventSubscriber.d.ts +46 -0
- package/lib/node/events/eventSubscriber.js +223 -0
- package/lib/node/events/eventsServerLogProvider.d.ts +21 -0
- package/lib/node/events/eventsServerLogProvider.js +121 -0
- package/lib/node/events/fetchLogs.d.ts +25 -0
- package/lib/node/events/fetchLogs.js +99 -0
- package/lib/node/events/parse.d.ts +6 -0
- package/lib/node/events/parse.js +106 -0
- package/lib/node/events/pollingLogProvider.d.ts +17 -0
- package/lib/node/events/pollingLogProvider.js +58 -0
- package/lib/node/events/sort.d.ts +2 -0
- package/lib/node/events/sort.js +24 -0
- package/lib/node/events/txEventCache.d.ts +24 -0
- package/lib/node/events/txEventCache.js +71 -0
- package/lib/node/events/types.d.ts +77 -0
- package/lib/node/events/types.js +30 -0
- package/lib/node/events/webSocketLogProvider.d.ts +24 -0
- package/lib/node/events/webSocketLogProvider.js +96 -0
- package/lib/node/factory/bigNum.d.ts +122 -0
- package/lib/node/factory/bigNum.js +457 -0
- package/lib/node/factory/oracleClient.d.ts +5 -0
- package/lib/node/factory/oracleClient.js +52 -0
- package/lib/node/idl/drift.json +13651 -0
- package/lib/node/idl/openbook.json +3854 -0
- package/lib/node/idl/pyth_solana_receiver.json +628 -0
- package/lib/node/idl/switchboard.json +8354 -0
- package/lib/node/idl/switchboard_on_demand_30.json +4541 -0
- package/lib/node/idl/token_faucet.json +142 -0
- package/lib/node/index.d.ts +112 -0
- package/lib/node/index.js +134 -0
- package/lib/node/isomorphic/grpc.browser.d.ts +1 -0
- package/lib/node/isomorphic/grpc.d.ts +1 -0
- package/lib/node/isomorphic/grpc.js +17 -0
- package/lib/node/isomorphic/grpc.node.d.ts +5 -0
- package/lib/node/isomorphic/grpc.node.js +17 -0
- package/lib/node/jupiter/jupiterClient.d.ts +296 -0
- package/lib/node/jupiter/jupiterClient.js +178 -0
- package/lib/node/keypair.d.ts +2 -0
- package/lib/node/keypair.js +28 -0
- package/lib/node/marinade/index.d.ts +12 -0
- package/lib/node/marinade/index.js +36 -0
- package/lib/node/marinade/types.d.ts +1963 -0
- package/lib/node/marinade/types.js +1965 -0
- package/lib/node/math/amm.d.ts +98 -0
- package/lib/node/math/amm.js +626 -0
- package/lib/node/math/auction.d.ts +23 -0
- package/lib/node/math/auction.js +127 -0
- package/lib/node/math/bankruptcy.d.ts +2 -0
- package/lib/node/math/bankruptcy.js +31 -0
- package/lib/node/math/conversion.d.ts +2 -0
- package/lib/node/math/conversion.js +11 -0
- package/lib/node/math/exchangeStatus.d.ts +6 -0
- package/lib/node/math/exchangeStatus.js +77 -0
- package/lib/node/math/fuel.d.ts +6 -0
- package/lib/node/math/fuel.js +55 -0
- package/lib/node/math/funding.d.ts +34 -0
- package/lib/node/math/funding.js +209 -0
- package/lib/node/math/insurance.d.ts +7 -0
- package/lib/node/math/insurance.js +73 -0
- package/lib/node/math/margin.d.ts +39 -0
- package/lib/node/math/margin.js +184 -0
- package/lib/node/math/market.d.ts +39 -0
- package/lib/node/math/market.js +163 -0
- package/lib/node/math/oracles.d.ts +14 -0
- package/lib/node/math/oracles.js +134 -0
- package/lib/node/math/orders.d.ts +23 -0
- package/lib/node/math/orders.js +216 -0
- package/lib/node/math/position.d.ts +54 -0
- package/lib/node/math/position.js +198 -0
- package/lib/node/math/repeg.d.ts +22 -0
- package/lib/node/math/repeg.js +164 -0
- package/lib/node/math/spotBalance.d.ts +83 -0
- package/lib/node/math/spotBalance.js +373 -0
- package/lib/node/math/spotMarket.d.ts +11 -0
- package/lib/node/math/spotMarket.js +49 -0
- package/lib/node/math/spotPosition.d.ts +19 -0
- package/lib/node/math/spotPosition.js +78 -0
- package/lib/node/math/state.d.ts +5 -0
- package/lib/node/math/state.js +30 -0
- package/lib/node/math/superStake.d.ts +167 -0
- package/lib/node/math/superStake.js +306 -0
- package/lib/node/math/tiers.d.ts +4 -0
- package/lib/node/math/tiers.js +52 -0
- package/lib/node/math/trade.d.ts +117 -0
- package/lib/node/math/trade.js +637 -0
- package/lib/node/math/utils.d.ts +23 -0
- package/lib/node/math/utils.js +112 -0
- package/lib/node/memcmp.d.ts +7 -0
- package/lib/node/memcmp.js +63 -0
- package/lib/node/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
- package/lib/node/openbook/openbookV2FulfillmentConfigMap.js +17 -0
- package/lib/node/openbook/openbookV2Subscriber.d.ts +36 -0
- package/lib/node/openbook/openbookV2Subscriber.js +104 -0
- package/lib/node/oracles/oracleClientCache.d.ts +9 -0
- package/lib/node/oracles/oracleClientCache.js +19 -0
- package/lib/node/oracles/prelaunchOracleClient.d.ts +12 -0
- package/lib/node/oracles/prelaunchOracleClient.js +24 -0
- package/lib/node/oracles/pythClient.d.ts +15 -0
- package/lib/node/oracles/pythClient.js +52 -0
- package/lib/node/oracles/pythPullClient.d.ts +19 -0
- package/lib/node/oracles/pythPullClient.js +60 -0
- package/lib/node/oracles/quoteAssetOracleClient.d.ts +10 -0
- package/lib/node/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/node/oracles/strictOraclePrice.d.ts +9 -0
- package/lib/node/oracles/strictOraclePrice.js +17 -0
- package/lib/node/oracles/switchboardClient.d.ts +12 -0
- package/lib/node/oracles/switchboardClient.js +40 -0
- package/lib/node/oracles/switchboardOnDemandClient.d.ts +12 -0
- package/lib/node/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/node/oracles/types.d.ts +23 -0
- package/lib/node/oracles/types.js +2 -0
- package/lib/node/orderParams.d.ts +29 -0
- package/lib/node/orderParams.js +44 -0
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +42 -0
- package/lib/node/orderSubscriber/OrderSubscriber.js +179 -0
- package/lib/node/orderSubscriber/PollingSubscription.d.ts +12 -0
- package/lib/node/orderSubscriber/PollingSubscription.js +23 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.d.ts +23 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.js +67 -0
- package/lib/node/orderSubscriber/grpcSubscription.d.ts +22 -0
- package/lib/node/orderSubscriber/grpcSubscription.js +66 -0
- package/lib/node/orderSubscriber/index.d.ts +2 -0
- package/lib/{auctionSubscriber → node/orderSubscriber}/index.js +1 -1
- package/lib/node/orderSubscriber/types.d.ts +34 -0
- package/lib/node/orderSubscriber/types.js +2 -0
- package/lib/node/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/node/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/node/phoenix/phoenixSubscriber.d.ts +41 -0
- package/lib/node/phoenix/phoenixSubscriber.js +152 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.js +16 -0
- package/lib/node/priorityFee/averageStrategy.d.ts +5 -0
- package/lib/node/priorityFee/averageStrategy.js +11 -0
- package/lib/node/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
- package/lib/node/priorityFee/driftPriorityFeeMethod.js +26 -0
- package/lib/node/priorityFee/ewmaStrategy.d.ts +11 -0
- package/lib/node/priorityFee/ewmaStrategy.js +33 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.js +46 -0
- package/lib/node/priorityFee/index.d.ts +11 -0
- package/lib/node/priorityFee/index.js +27 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.js +17 -0
- package/lib/node/priorityFee/maxStrategy.d.ts +7 -0
- package/lib/node/priorityFee/maxStrategy.js +9 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +46 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.js +188 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +88 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.js +21 -0
- package/lib/node/priorityFee/types.d.ts +31 -0
- package/lib/node/priorityFee/types.js +10 -0
- package/lib/node/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/node/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/node/serum/serumSubscriber.d.ts +32 -0
- package/lib/node/serum/serumSubscriber.js +107 -0
- package/lib/node/serum/types.d.ts +13 -0
- package/lib/node/serum/types.js +2 -0
- package/lib/node/slot/SlotSubscriber.d.ts +27 -0
- package/lib/node/slot/SlotSubscriber.js +71 -0
- package/lib/node/testClient.d.ts +8 -0
- package/lib/node/testClient.js +23 -0
- package/lib/node/token/index.d.ts +5 -0
- package/lib/node/token/index.js +15 -0
- package/lib/node/tokenFaucet.d.ts +41 -0
- package/lib/node/tokenFaucet.js +188 -0
- package/lib/node/tx/baseTxSender.d.ts +55 -0
- package/lib/node/tx/baseTxSender.js +288 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
- package/lib/node/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/node/tx/blockhashFetcher/types.js +2 -0
- package/lib/node/tx/fastSingleTxSender.d.ts +40 -0
- package/lib/node/tx/fastSingleTxSender.js +85 -0
- package/lib/node/tx/forwardOnlyTxSender.d.ts +36 -0
- package/lib/node/tx/forwardOnlyTxSender.js +91 -0
- package/lib/node/tx/priorityFeeCalculator.d.ts +44 -0
- package/lib/node/tx/priorityFeeCalculator.js +85 -0
- package/lib/node/tx/reportTransactionError.d.ts +20 -0
- package/lib/node/tx/reportTransactionError.js +103 -0
- package/lib/node/tx/retryTxSender.d.ts +36 -0
- package/lib/node/tx/retryTxSender.js +85 -0
- package/lib/node/tx/txHandler.d.ts +154 -0
- package/lib/node/tx/txHandler.js +453 -0
- package/lib/node/tx/txParamProcessor.d.ts +25 -0
- package/lib/node/tx/txParamProcessor.js +88 -0
- package/lib/node/tx/types.d.ts +29 -0
- package/lib/node/tx/types.js +20 -0
- package/lib/node/tx/utils.d.ts +2 -0
- package/lib/node/tx/utils.js +10 -0
- package/lib/node/tx/whileValidTxSender.d.ts +43 -0
- package/lib/node/tx/whileValidTxSender.js +165 -0
- package/lib/node/types.d.ts +1351 -0
- package/lib/node/types.js +347 -0
- package/lib/node/user.d.ts +411 -0
- package/lib/node/user.js +2161 -0
- package/lib/node/userConfig.d.ts +26 -0
- package/lib/node/userConfig.js +2 -0
- package/lib/node/userMap/PollingSubscription.d.ts +16 -0
- package/lib/node/userMap/PollingSubscription.js +30 -0
- package/lib/node/userMap/WebsocketSubscription.d.ts +25 -0
- package/lib/node/userMap/WebsocketSubscription.js +41 -0
- package/lib/node/userMap/grpcSubscription.d.ts +24 -0
- package/lib/node/userMap/grpcSubscription.js +40 -0
- package/lib/node/userMap/userMap.d.ts +88 -0
- package/lib/node/userMap/userMap.js +455 -0
- package/lib/node/userMap/userMapConfig.d.ts +37 -0
- package/lib/node/userMap/userMapConfig.js +2 -0
- package/lib/node/userMap/userStatsMap.d.ts +46 -0
- package/lib/node/userMap/userStatsMap.js +165 -0
- package/lib/node/userName.d.ts +5 -0
- package/lib/node/userName.js +21 -0
- package/lib/node/userStats.d.ts +19 -0
- package/lib/node/userStats.js +65 -0
- package/lib/node/userStatsConfig.d.ts +25 -0
- package/lib/node/userStatsConfig.js +2 -0
- package/lib/node/util/TransactionConfirmationManager.d.ts +16 -0
- package/lib/node/util/TransactionConfirmationManager.js +174 -0
- package/lib/node/util/chainClock.d.ts +17 -0
- package/lib/node/util/chainClock.js +29 -0
- package/lib/node/util/computeUnits.d.ts +8 -0
- package/lib/node/util/computeUnits.js +46 -0
- package/lib/node/util/promiseTimeout.d.ts +1 -0
- package/lib/node/util/promiseTimeout.js +14 -0
- package/lib/node/util/pythPullOracleUtils.d.ts +2 -0
- package/lib/node/util/pythPullOracleUtils.js +15 -0
- package/lib/node/util/tps.d.ts +2 -0
- package/lib/node/util/tps.js +16 -0
- package/lib/node/wallet.d.ts +11 -0
- package/lib/node/wallet.js +32 -0
- package/package.json +8 -4
- package/scripts/postbuild.js +61 -0
- package/src/accounts/grpcAccountSubscriber.ts +160 -0
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +197 -0
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +56 -0
- package/src/accounts/grpcProgramAccountSubscriber.ts +190 -0
- package/src/accounts/grpcUserAccountSubscriber.ts +48 -0
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +50 -0
- package/src/accounts/types.ts +8 -0
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +3 -3
- package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
- package/src/addresses/pda.ts +13 -0
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +70 -0
- package/src/auctionSubscriber/index.ts +1 -0
- package/src/auctionSubscriber/types.ts +2 -0
- package/src/driftClient.ts +175 -24
- package/src/driftClientConfig.ts +7 -1
- package/src/idl/drift.json +256 -0
- package/src/isomorphic/README.md +19 -0
- package/src/isomorphic/grpc.browser.ts +4 -0
- package/src/isomorphic/grpc.node.ts +23 -0
- package/src/isomorphic/grpc.ts +1 -0
- package/src/orderSubscriber/OrderSubscriber.ts +14 -1
- package/src/orderSubscriber/grpcSubscription.ts +121 -0
- package/src/orderSubscriber/types.ts +10 -0
- package/src/types.ts +23 -0
- package/src/user.ts +11 -0
- package/src/userConfig.ts +7 -1
- package/src/userMap/grpcSubscription.ts +78 -0
- package/src/userMap/userMap.ts +21 -2
- package/src/userMap/userMapConfig.ts +7 -0
- package/src/userStats.ts +11 -0
- package/src/userStatsConfig.ts +7 -0
- package/tsconfig.browser.json +13 -0
- package/tsconfig.json +1 -1
- /package/lib/{accounts → browser/accounts}/basicUserAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/basicUserAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/bulkAccountLoader.js +0 -0
- /package/lib/{accounts → browser/accounts}/bulkUserStatsSubscription.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/bulkUserStatsSubscription.js +0 -0
- /package/lib/{accounts → browser/accounts}/bulkUserSubscription.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/bulkUserSubscription.js +0 -0
- /package/lib/{accounts → browser/accounts}/fetch.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/fetch.js +0 -0
- /package/lib/{accounts → browser/accounts}/oneShotUserAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/oneShotUserAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/pollingDriftClientAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/pollingDriftClientAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/pollingInsuranceFundStakeAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/pollingInsuranceFundStakeAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/pollingOracleAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/pollingOracleAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/pollingTokenAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/pollingTokenAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/pollingUserAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/pollingUserAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/pollingUserStatsAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/pollingUserStatsAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/testBulkAccountLoader.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/testBulkAccountLoader.js +0 -0
- /package/lib/{accounts → browser/accounts}/types.js +0 -0
- /package/lib/{accounts → browser/accounts}/utils.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/utils.js +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketDriftClientAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketInsuranceFundStakeAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketInsuranceFundStakeAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketProgramAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketUserAccountSubscriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketUserAccountSubscriber.js +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketUserStatsAccountSubsriber.d.ts +0 -0
- /package/lib/{accounts → browser/accounts}/webSocketUserStatsAccountSubsriber.js +0 -0
- /package/lib/{addresses → browser/addresses}/marketAddresses.d.ts +0 -0
- /package/lib/{addresses → browser/addresses}/marketAddresses.js +0 -0
- /package/lib/{adminClient.d.ts → browser/adminClient.d.ts} +0 -0
- /package/lib/{adminClient.js → browser/adminClient.js} +0 -0
- /package/lib/{assert → browser/assert}/assert.d.ts +0 -0
- /package/lib/{assert → browser/assert}/assert.js +0 -0
- /package/lib/{auctionSubscriber → browser/auctionSubscriber}/auctionSubscriber.d.ts +0 -0
- /package/lib/{auctionSubscriber → browser/auctionSubscriber}/auctionSubscriber.js +0 -0
- /package/lib/{auctionSubscriber → browser/auctionSubscriber}/types.js +0 -0
- /package/lib/{bankrun → browser/bankrun}/bankrunConnection.js +0 -0
- /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/BlockhashSubscriber.d.ts +0 -0
- /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/BlockhashSubscriber.js +0 -0
- /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/index.d.ts +0 -0
- /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/index.js +0 -0
- /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/types.d.ts +0 -0
- /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/types.js +0 -0
- /package/lib/{clock → browser/clock}/clockSubscriber.d.ts +0 -0
- /package/lib/{clock → browser/clock}/clockSubscriber.js +0 -0
- /package/lib/{config.d.ts → browser/config.d.ts} +0 -0
- /package/lib/{config.js → browser/config.js} +0 -0
- /package/lib/{constants → browser/constants}/numericConstants.d.ts +0 -0
- /package/lib/{constants → browser/constants}/numericConstants.js +0 -0
- /package/lib/{constants → browser/constants}/perpMarkets.d.ts +0 -0
- /package/lib/{constants → browser/constants}/perpMarkets.js +0 -0
- /package/lib/{constants → browser/constants}/spotMarkets.d.ts +0 -0
- /package/lib/{constants → browser/constants}/spotMarkets.js +0 -0
- /package/lib/{constants → browser/constants}/txConstants.d.ts +0 -0
- /package/lib/{constants → browser/constants}/txConstants.js +0 -0
- /package/lib/{decode → browser/decode}/phoenix.js +0 -0
- /package/lib/{decode → browser/decode}/user.js +0 -0
- /package/lib/{dlob → browser/dlob}/DLOB.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/DLOB.js +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBApiClient.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBApiClient.js +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBNode.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBNode.js +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBOrders.js +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBSubscriber.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/DLOBSubscriber.js +0 -0
- /package/lib/{dlob → browser/dlob}/NodeList.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/NodeList.js +0 -0
- /package/lib/{dlob → browser/dlob}/dlobIdl.json +0 -0
- /package/lib/{dlob → browser/dlob}/orderBookLevels.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/orderBookLevels.js +0 -0
- /package/lib/{dlob → browser/dlob}/types.d.ts +0 -0
- /package/lib/{dlob → browser/dlob}/types.js +0 -0
- /package/lib/{driftClientConfig.js → browser/driftClientConfig.js} +0 -0
- /package/lib/{events → browser/events}/eventList.d.ts +0 -0
- /package/lib/{events → browser/events}/eventList.js +0 -0
- /package/lib/{events → browser/events}/eventSubscriber.d.ts +0 -0
- /package/lib/{events → browser/events}/eventSubscriber.js +0 -0
- /package/lib/{events → browser/events}/eventsServerLogProvider.d.ts +0 -0
- /package/lib/{events → browser/events}/eventsServerLogProvider.js +0 -0
- /package/lib/{events → browser/events}/fetchLogs.d.ts +0 -0
- /package/lib/{events → browser/events}/fetchLogs.js +0 -0
- /package/lib/{events → browser/events}/parse.d.ts +0 -0
- /package/lib/{events → browser/events}/parse.js +0 -0
- /package/lib/{events → browser/events}/pollingLogProvider.d.ts +0 -0
- /package/lib/{events → browser/events}/pollingLogProvider.js +0 -0
- /package/lib/{events → browser/events}/sort.d.ts +0 -0
- /package/lib/{events → browser/events}/sort.js +0 -0
- /package/lib/{events → browser/events}/txEventCache.d.ts +0 -0
- /package/lib/{events → browser/events}/txEventCache.js +0 -0
- /package/lib/{events → browser/events}/types.d.ts +0 -0
- /package/lib/{events → browser/events}/types.js +0 -0
- /package/lib/{events → browser/events}/webSocketLogProvider.d.ts +0 -0
- /package/lib/{events → browser/events}/webSocketLogProvider.js +0 -0
- /package/lib/{factory → browser/factory}/bigNum.d.ts +0 -0
- /package/lib/{factory → browser/factory}/bigNum.js +0 -0
- /package/lib/{factory → browser/factory}/oracleClient.d.ts +0 -0
- /package/lib/{factory → browser/factory}/oracleClient.js +0 -0
- /package/lib/{idl → browser/idl}/openbook.json +0 -0
- /package/lib/{idl → browser/idl}/pyth_solana_receiver.json +0 -0
- /package/lib/{idl → browser/idl}/switchboard.json +0 -0
- /package/lib/{idl → browser/idl}/switchboard_on_demand_30.json +0 -0
- /package/lib/{idl → browser/idl}/token_faucet.json +0 -0
- /package/lib/{index.d.ts → browser/index.d.ts} +0 -0
- /package/lib/{index.js → browser/index.js} +0 -0
- /package/lib/{jupiter → browser/jupiter}/jupiterClient.d.ts +0 -0
- /package/lib/{jupiter → browser/jupiter}/jupiterClient.js +0 -0
- /package/lib/{keypair.d.ts → browser/keypair.d.ts} +0 -0
- /package/lib/{keypair.js → browser/keypair.js} +0 -0
- /package/lib/{marinade → browser/marinade}/index.d.ts +0 -0
- /package/lib/{marinade → browser/marinade}/index.js +0 -0
- /package/lib/{marinade → browser/marinade}/types.d.ts +0 -0
- /package/lib/{marinade → browser/marinade}/types.js +0 -0
- /package/lib/{math → browser/math}/amm.d.ts +0 -0
- /package/lib/{math → browser/math}/amm.js +0 -0
- /package/lib/{math → browser/math}/auction.d.ts +0 -0
- /package/lib/{math → browser/math}/auction.js +0 -0
- /package/lib/{math → browser/math}/bankruptcy.d.ts +0 -0
- /package/lib/{math → browser/math}/bankruptcy.js +0 -0
- /package/lib/{math → browser/math}/conversion.d.ts +0 -0
- /package/lib/{math → browser/math}/conversion.js +0 -0
- /package/lib/{math → browser/math}/exchangeStatus.d.ts +0 -0
- /package/lib/{math → browser/math}/exchangeStatus.js +0 -0
- /package/lib/{math → browser/math}/fuel.d.ts +0 -0
- /package/lib/{math → browser/math}/fuel.js +0 -0
- /package/lib/{math → browser/math}/funding.d.ts +0 -0
- /package/lib/{math → browser/math}/funding.js +0 -0
- /package/lib/{math → browser/math}/insurance.d.ts +0 -0
- /package/lib/{math → browser/math}/insurance.js +0 -0
- /package/lib/{math → browser/math}/margin.d.ts +0 -0
- /package/lib/{math → browser/math}/margin.js +0 -0
- /package/lib/{math → browser/math}/market.d.ts +0 -0
- /package/lib/{math → browser/math}/market.js +0 -0
- /package/lib/{math → browser/math}/oracles.js +0 -0
- /package/lib/{math → browser/math}/orders.d.ts +0 -0
- /package/lib/{math → browser/math}/orders.js +0 -0
- /package/lib/{math → browser/math}/position.d.ts +0 -0
- /package/lib/{math → browser/math}/position.js +0 -0
- /package/lib/{math → browser/math}/repeg.d.ts +0 -0
- /package/lib/{math → browser/math}/repeg.js +0 -0
- /package/lib/{math → browser/math}/spotBalance.d.ts +0 -0
- /package/lib/{math → browser/math}/spotBalance.js +0 -0
- /package/lib/{math → browser/math}/spotMarket.d.ts +0 -0
- /package/lib/{math → browser/math}/spotMarket.js +0 -0
- /package/lib/{math → browser/math}/spotPosition.d.ts +0 -0
- /package/lib/{math → browser/math}/spotPosition.js +0 -0
- /package/lib/{math → browser/math}/state.d.ts +0 -0
- /package/lib/{math → browser/math}/state.js +0 -0
- /package/lib/{math → browser/math}/superStake.d.ts +0 -0
- /package/lib/{math → browser/math}/superStake.js +0 -0
- /package/lib/{math → browser/math}/tiers.d.ts +0 -0
- /package/lib/{math → browser/math}/tiers.js +0 -0
- /package/lib/{math → browser/math}/trade.d.ts +0 -0
- /package/lib/{math → browser/math}/trade.js +0 -0
- /package/lib/{math → browser/math}/utils.d.ts +0 -0
- /package/lib/{math → browser/math}/utils.js +0 -0
- /package/lib/{memcmp.d.ts → browser/memcmp.d.ts} +0 -0
- /package/lib/{memcmp.js → browser/memcmp.js} +0 -0
- /package/lib/{openbook → browser/openbook}/openbookV2FulfillmentConfigMap.d.ts +0 -0
- /package/lib/{openbook → browser/openbook}/openbookV2FulfillmentConfigMap.js +0 -0
- /package/lib/{openbook → browser/openbook}/openbookV2Subscriber.d.ts +0 -0
- /package/lib/{openbook → browser/openbook}/openbookV2Subscriber.js +0 -0
- /package/lib/{oracles → browser/oracles}/oracleClientCache.d.ts +0 -0
- /package/lib/{oracles → browser/oracles}/oracleClientCache.js +0 -0
- /package/lib/{oracles → browser/oracles}/prelaunchOracleClient.js +0 -0
- /package/lib/{oracles → browser/oracles}/pythClient.js +0 -0
- /package/lib/{oracles → browser/oracles}/pythPullClient.js +0 -0
- /package/lib/{oracles → browser/oracles}/quoteAssetOracleClient.js +0 -0
- /package/lib/{oracles → browser/oracles}/strictOraclePrice.d.ts +0 -0
- /package/lib/{oracles → browser/oracles}/strictOraclePrice.js +0 -0
- /package/lib/{oracles → browser/oracles}/switchboardClient.js +0 -0
- /package/lib/{oracles → browser/oracles}/switchboardOnDemandClient.js +0 -0
- /package/lib/{oracles → browser/oracles}/types.js +0 -0
- /package/lib/{orderParams.d.ts → browser/orderParams.d.ts} +0 -0
- /package/lib/{orderParams.js → browser/orderParams.js} +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/PollingSubscription.d.ts +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/PollingSubscription.js +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/WebsocketSubscription.d.ts +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/WebsocketSubscription.js +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/index.d.ts +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/index.js +0 -0
- /package/lib/{orderSubscriber → browser/orderSubscriber}/types.js +0 -0
- /package/lib/{phoenix → browser/phoenix}/phoenixFulfillmentConfigMap.d.ts +0 -0
- /package/lib/{phoenix → browser/phoenix}/phoenixFulfillmentConfigMap.js +0 -0
- /package/lib/{phoenix → browser/phoenix}/phoenixSubscriber.d.ts +0 -0
- /package/lib/{phoenix → browser/phoenix}/phoenixSubscriber.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/averageOverSlotsStrategy.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/averageOverSlotsStrategy.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/averageStrategy.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/averageStrategy.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/driftPriorityFeeMethod.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/driftPriorityFeeMethod.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/ewmaStrategy.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/ewmaStrategy.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/heliusPriorityFeeMethod.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/heliusPriorityFeeMethod.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/index.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/index.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/maxOverSlotsStrategy.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/maxOverSlotsStrategy.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/maxStrategy.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/maxStrategy.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriber.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriber.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriberMap.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriberMap.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/solanaPriorityFeeMethod.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/solanaPriorityFeeMethod.js +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/types.d.ts +0 -0
- /package/lib/{priorityFee → browser/priorityFee}/types.js +0 -0
- /package/lib/{serum → browser/serum}/serumFulfillmentConfigMap.d.ts +0 -0
- /package/lib/{serum → browser/serum}/serumFulfillmentConfigMap.js +0 -0
- /package/lib/{serum → browser/serum}/serumSubscriber.d.ts +0 -0
- /package/lib/{serum → browser/serum}/serumSubscriber.js +0 -0
- /package/lib/{serum → browser/serum}/types.d.ts +0 -0
- /package/lib/{serum → browser/serum}/types.js +0 -0
- /package/lib/{slot → browser/slot}/SlotSubscriber.d.ts +0 -0
- /package/lib/{slot → browser/slot}/SlotSubscriber.js +0 -0
- /package/lib/{testClient.d.ts → browser/testClient.d.ts} +0 -0
- /package/lib/{testClient.js → browser/testClient.js} +0 -0
- /package/lib/{token → browser/token}/index.js +0 -0
- /package/lib/{tokenFaucet.d.ts → browser/tokenFaucet.d.ts} +0 -0
- /package/lib/{tokenFaucet.js → browser/tokenFaucet.js} +0 -0
- /package/lib/{tx → browser/tx}/baseTxSender.js +0 -0
- /package/lib/{tx → browser/tx}/blockhashFetcher/baseBlockhashFetcher.d.ts +0 -0
- /package/lib/{tx → browser/tx}/blockhashFetcher/baseBlockhashFetcher.js +0 -0
- /package/lib/{tx → browser/tx}/blockhashFetcher/cachedBlockhashFetcher.d.ts +0 -0
- /package/lib/{tx → browser/tx}/blockhashFetcher/cachedBlockhashFetcher.js +0 -0
- /package/lib/{tx → browser/tx}/blockhashFetcher/types.d.ts +0 -0
- /package/lib/{tx → browser/tx}/blockhashFetcher/types.js +0 -0
- /package/lib/{tx → browser/tx}/fastSingleTxSender.js +0 -0
- /package/lib/{tx → browser/tx}/forwardOnlyTxSender.js +0 -0
- /package/lib/{tx → browser/tx}/priorityFeeCalculator.d.ts +0 -0
- /package/lib/{tx → browser/tx}/priorityFeeCalculator.js +0 -0
- /package/lib/{tx → browser/tx}/reportTransactionError.d.ts +0 -0
- /package/lib/{tx → browser/tx}/reportTransactionError.js +0 -0
- /package/lib/{tx → browser/tx}/retryTxSender.js +0 -0
- /package/lib/{tx → browser/tx}/txHandler.d.ts +0 -0
- /package/lib/{tx → browser/tx}/txHandler.js +0 -0
- /package/lib/{tx → browser/tx}/txParamProcessor.d.ts +0 -0
- /package/lib/{tx → browser/tx}/txParamProcessor.js +0 -0
- /package/lib/{tx → browser/tx}/types.js +0 -0
- /package/lib/{tx → browser/tx}/utils.d.ts +0 -0
- /package/lib/{tx → browser/tx}/utils.js +0 -0
- /package/lib/{tx → browser/tx}/whileValidTxSender.js +0 -0
- /package/lib/{types.js → browser/types.js} +0 -0
- /package/lib/{user.d.ts → browser/user.d.ts} +0 -0
- /package/lib/{userConfig.js → browser/userConfig.js} +0 -0
- /package/lib/{userMap → browser/userMap}/PollingSubscription.d.ts +0 -0
- /package/lib/{userMap → browser/userMap}/PollingSubscription.js +0 -0
- /package/lib/{userMap → browser/userMap}/WebsocketSubscription.js +0 -0
- /package/lib/{userMap → browser/userMap}/userMap.d.ts +0 -0
- /package/lib/{userMap → browser/userMap}/userMapConfig.js +0 -0
- /package/lib/{userMap → browser/userMap}/userStatsMap.d.ts +0 -0
- /package/lib/{userMap → browser/userMap}/userStatsMap.js +0 -0
- /package/lib/{userName.d.ts → browser/userName.d.ts} +0 -0
- /package/lib/{userName.js → browser/userName.js} +0 -0
- /package/lib/{userStats.d.ts → browser/userStats.d.ts} +0 -0
- /package/lib/{userStatsConfig.js → browser/userStatsConfig.js} +0 -0
- /package/lib/{util → browser/util}/TransactionConfirmationManager.d.ts +0 -0
- /package/lib/{util → browser/util}/TransactionConfirmationManager.js +0 -0
- /package/lib/{util → browser/util}/chainClock.d.ts +0 -0
- /package/lib/{util → browser/util}/chainClock.js +0 -0
- /package/lib/{util → browser/util}/computeUnits.d.ts +0 -0
- /package/lib/{util → browser/util}/computeUnits.js +0 -0
- /package/lib/{util → browser/util}/promiseTimeout.d.ts +0 -0
- /package/lib/{util → browser/util}/promiseTimeout.js +0 -0
- /package/lib/{util → browser/util}/pythPullOracleUtils.d.ts +0 -0
- /package/lib/{util → browser/util}/pythPullOracleUtils.js +0 -0
- /package/lib/{util → browser/util}/tps.d.ts +0 -0
- /package/lib/{util → browser/util}/tps.js +0 -0
- /package/lib/{wallet.d.ts → browser/wallet.d.ts} +0 -0
- /package/lib/{wallet.js → browser/wallet.js} +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
|
+
const auction_1 = require("./auction");
|
|
8
|
+
const amm_1 = require("./amm");
|
|
9
|
+
function isOrderRiskIncreasing(user, order) {
|
|
10
|
+
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const position = user.getPerpPosition(order.marketIndex) ||
|
|
14
|
+
user.getEmptyPosition(order.marketIndex);
|
|
15
|
+
// if no position exists, it's risk increasing
|
|
16
|
+
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
// if position is long and order is long
|
|
20
|
+
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// if position is short and order is short
|
|
24
|
+
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
25
|
+
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const baseAssetAmountToFill = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
29
|
+
// if order will flip position
|
|
30
|
+
if (baseAssetAmountToFill.gt(position.baseAssetAmount.abs().mul(numericConstants_1.TWO))) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
|
|
36
|
+
function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
37
|
+
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const position = user.getPerpPosition(order.marketIndex) ||
|
|
41
|
+
user.getEmptyPosition(order.marketIndex);
|
|
42
|
+
// if no position exists, it's risk increasing
|
|
43
|
+
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// if position is long and order is long
|
|
47
|
+
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
// if position is short and order is short
|
|
51
|
+
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
52
|
+
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
|
|
58
|
+
function isOrderReduceOnly(user, order) {
|
|
59
|
+
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const position = user.getPerpPosition(order.marketIndex) ||
|
|
63
|
+
user.getEmptyPosition(order.marketIndex);
|
|
64
|
+
// if position is long and order is long
|
|
65
|
+
if (position.baseAssetAmount.gte(numericConstants_1.ZERO) &&
|
|
66
|
+
(0, types_1.isVariant)(order.direction, 'long')) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// if position is short and order is short
|
|
70
|
+
if (position.baseAssetAmount.lte(numericConstants_1.ZERO) &&
|
|
71
|
+
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
exports.isOrderReduceOnly = isOrderReduceOnly;
|
|
77
|
+
function standardizeBaseAssetAmount(baseAssetAmount, stepSize) {
|
|
78
|
+
const remainder = baseAssetAmount.mod(stepSize);
|
|
79
|
+
return baseAssetAmount.sub(remainder);
|
|
80
|
+
}
|
|
81
|
+
exports.standardizeBaseAssetAmount = standardizeBaseAssetAmount;
|
|
82
|
+
function standardizePrice(price, tickSize, direction) {
|
|
83
|
+
if (price.eq(numericConstants_1.ZERO)) {
|
|
84
|
+
console.log('price is zero');
|
|
85
|
+
return price;
|
|
86
|
+
}
|
|
87
|
+
const remainder = price.mod(tickSize);
|
|
88
|
+
if (remainder.eq(numericConstants_1.ZERO)) {
|
|
89
|
+
return price;
|
|
90
|
+
}
|
|
91
|
+
if ((0, types_1.isVariant)(direction, 'long')) {
|
|
92
|
+
return price.sub(remainder);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return price.add(tickSize).sub(remainder);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.standardizePrice = standardizePrice;
|
|
99
|
+
function getLimitPrice(order, oraclePriceData, slot, fallbackPrice) {
|
|
100
|
+
let limitPrice;
|
|
101
|
+
if (hasAuctionPrice(order, slot)) {
|
|
102
|
+
limitPrice = (0, auction_1.getAuctionPrice)(order, slot, oraclePriceData.price);
|
|
103
|
+
}
|
|
104
|
+
else if (order.oraclePriceOffset !== 0) {
|
|
105
|
+
limitPrice = anchor_1.BN.max(oraclePriceData.price.add(new anchor_1.BN(order.oraclePriceOffset)), numericConstants_1.ONE);
|
|
106
|
+
}
|
|
107
|
+
else if (order.price.eq(numericConstants_1.ZERO)) {
|
|
108
|
+
limitPrice = fallbackPrice;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
limitPrice = order.price;
|
|
112
|
+
}
|
|
113
|
+
return limitPrice;
|
|
114
|
+
}
|
|
115
|
+
exports.getLimitPrice = getLimitPrice;
|
|
116
|
+
function hasLimitPrice(order, slot) {
|
|
117
|
+
return (order.price.gt(numericConstants_1.ZERO) ||
|
|
118
|
+
order.oraclePriceOffset != 0 ||
|
|
119
|
+
!(0, auction_1.isAuctionComplete)(order, slot));
|
|
120
|
+
}
|
|
121
|
+
exports.hasLimitPrice = hasLimitPrice;
|
|
122
|
+
function hasAuctionPrice(order, slot) {
|
|
123
|
+
return (!(0, auction_1.isAuctionComplete)(order, slot) &&
|
|
124
|
+
(!order.auctionStartPrice.eq(numericConstants_1.ZERO) || !order.auctionEndPrice.eq(numericConstants_1.ZERO)));
|
|
125
|
+
}
|
|
126
|
+
exports.hasAuctionPrice = hasAuctionPrice;
|
|
127
|
+
function isFillableByVAMM(order, market, oraclePriceData, slot, ts, minAuctionDuration) {
|
|
128
|
+
return (((0, auction_1.isFallbackAvailableLiquiditySource)(order, minAuctionDuration, slot) &&
|
|
129
|
+
calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData, slot).gte(market.amm.minOrderSize)) ||
|
|
130
|
+
isOrderExpired(order, ts));
|
|
131
|
+
}
|
|
132
|
+
exports.isFillableByVAMM = isFillableByVAMM;
|
|
133
|
+
function calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData, slot) {
|
|
134
|
+
if (mustBeTriggered(order) && !isTriggered(order)) {
|
|
135
|
+
return numericConstants_1.ZERO;
|
|
136
|
+
}
|
|
137
|
+
const limitPrice = getLimitPrice(order, oraclePriceData, slot);
|
|
138
|
+
let baseAssetAmount;
|
|
139
|
+
const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, oraclePriceData);
|
|
140
|
+
if (limitPrice !== undefined) {
|
|
141
|
+
baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, limitPrice, oraclePriceData);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
baseAssetAmount = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
145
|
+
}
|
|
146
|
+
const maxBaseAssetAmount = (0, amm_1.calculateMaxBaseAssetAmountFillable)(updatedAMM, order.direction);
|
|
147
|
+
return anchor_1.BN.min(maxBaseAssetAmount, baseAssetAmount);
|
|
148
|
+
}
|
|
149
|
+
exports.calculateBaseAssetAmountForAmmToFulfill = calculateBaseAssetAmountForAmmToFulfill;
|
|
150
|
+
function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, limitPrice, oraclePriceData) {
|
|
151
|
+
const adjustedLimitPrice = (0, types_1.isVariant)(order.direction, 'long')
|
|
152
|
+
? limitPrice.sub(amm.orderTickSize)
|
|
153
|
+
: limitPrice.add(amm.orderTickSize);
|
|
154
|
+
const [maxAmountToTrade, direction] = (0, amm_1.calculateMaxBaseAssetAmountToTrade)(amm, adjustedLimitPrice, order.direction, oraclePriceData);
|
|
155
|
+
const baseAssetAmount = standardizeBaseAssetAmount(maxAmountToTrade, amm.orderStepSize);
|
|
156
|
+
// Check that directions are the same
|
|
157
|
+
const sameDirection = isSameDirection(direction, order.direction);
|
|
158
|
+
if (!sameDirection) {
|
|
159
|
+
return numericConstants_1.ZERO;
|
|
160
|
+
}
|
|
161
|
+
const baseAssetAmountUnfilled = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
162
|
+
return baseAssetAmount.gt(baseAssetAmountUnfilled)
|
|
163
|
+
? baseAssetAmountUnfilled
|
|
164
|
+
: baseAssetAmount;
|
|
165
|
+
}
|
|
166
|
+
exports.calculateBaseAssetAmountToFillUpToLimitPrice = calculateBaseAssetAmountToFillUpToLimitPrice;
|
|
167
|
+
function isSameDirection(firstDirection, secondDirection) {
|
|
168
|
+
return (((0, types_1.isVariant)(firstDirection, 'long') && (0, types_1.isVariant)(secondDirection, 'long')) ||
|
|
169
|
+
((0, types_1.isVariant)(firstDirection, 'short') && (0, types_1.isVariant)(secondDirection, 'short')));
|
|
170
|
+
}
|
|
171
|
+
function isOrderExpired(order, ts, enforceBuffer = false, bufferSeconds = 15) {
|
|
172
|
+
if (mustBeTriggered(order) ||
|
|
173
|
+
!(0, types_1.isVariant)(order.status, 'open') ||
|
|
174
|
+
order.maxTs.eq(numericConstants_1.ZERO)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
let maxTs;
|
|
178
|
+
if (enforceBuffer && isLimitOrder(order)) {
|
|
179
|
+
maxTs = order.maxTs.addn(bufferSeconds);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
maxTs = order.maxTs;
|
|
183
|
+
}
|
|
184
|
+
return new anchor_1.BN(ts).gt(maxTs);
|
|
185
|
+
}
|
|
186
|
+
exports.isOrderExpired = isOrderExpired;
|
|
187
|
+
function isMarketOrder(order) {
|
|
188
|
+
return (0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle']);
|
|
189
|
+
}
|
|
190
|
+
exports.isMarketOrder = isMarketOrder;
|
|
191
|
+
function isLimitOrder(order) {
|
|
192
|
+
return (0, types_1.isOneOfVariant)(order.orderType, ['limit', 'triggerLimit']);
|
|
193
|
+
}
|
|
194
|
+
exports.isLimitOrder = isLimitOrder;
|
|
195
|
+
function mustBeTriggered(order) {
|
|
196
|
+
return (0, types_1.isOneOfVariant)(order.orderType, ['triggerMarket', 'triggerLimit']);
|
|
197
|
+
}
|
|
198
|
+
exports.mustBeTriggered = mustBeTriggered;
|
|
199
|
+
function isTriggered(order) {
|
|
200
|
+
return (0, types_1.isOneOfVariant)(order.triggerCondition, [
|
|
201
|
+
'triggeredAbove',
|
|
202
|
+
'triggeredBelow',
|
|
203
|
+
]);
|
|
204
|
+
}
|
|
205
|
+
exports.isTriggered = isTriggered;
|
|
206
|
+
function isRestingLimitOrder(order, slot) {
|
|
207
|
+
if (!isLimitOrder(order)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
|
|
211
|
+
}
|
|
212
|
+
exports.isRestingLimitOrder = isRestingLimitOrder;
|
|
213
|
+
function isTakingOrder(order, slot) {
|
|
214
|
+
return isMarketOrder(order) || !isRestingLimitOrder(order, slot);
|
|
215
|
+
}
|
|
216
|
+
exports.isTakingOrder = isTakingOrder;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN, SpotMarketAccount } from '../';
|
|
3
|
+
import { OraclePriceData } from '../oracles/types';
|
|
4
|
+
import { PerpMarketAccount, PositionDirection, PerpPosition } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* calculateBaseAssetValue
|
|
7
|
+
* = market value of closing entire position
|
|
8
|
+
* @param market
|
|
9
|
+
* @param userPosition
|
|
10
|
+
* @param oraclePriceData
|
|
11
|
+
* @returns Base Asset Value. : Precision QUOTE_PRECISION
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateBaseAssetValue(market: PerpMarketAccount, userPosition: PerpPosition, oraclePriceData: OraclePriceData, useSpread?: boolean, skipUpdate?: boolean): BN;
|
|
14
|
+
/**
|
|
15
|
+
* calculatePositionPNL
|
|
16
|
+
* = BaseAssetAmount * (Avg Exit Price - Avg Entry Price)
|
|
17
|
+
* @param market
|
|
18
|
+
* @param PerpPosition
|
|
19
|
+
* @param withFunding (adds unrealized funding payment pnl to result)
|
|
20
|
+
* @param oraclePriceData
|
|
21
|
+
* @returns BaseAssetAmount : Precision QUOTE_PRECISION
|
|
22
|
+
*/
|
|
23
|
+
export declare function calculatePositionPNL(market: PerpMarketAccount, perpPosition: PerpPosition, withFunding: boolean, oraclePriceData: OraclePriceData): BN;
|
|
24
|
+
export declare function calculateClaimablePnl(market: PerpMarketAccount, spotMarket: SpotMarketAccount, perpPosition: PerpPosition, oraclePriceData: OraclePriceData): BN;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param market
|
|
28
|
+
* @param PerpPosition
|
|
29
|
+
* @returns // QUOTE_PRECISION
|
|
30
|
+
*/
|
|
31
|
+
export declare function calculatePositionFundingPNL(market: PerpMarketAccount, perpPosition: PerpPosition): BN;
|
|
32
|
+
export declare function positionIsAvailable(position: PerpPosition): boolean;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param userPosition
|
|
36
|
+
* @returns Precision: PRICE_PRECISION (10^6)
|
|
37
|
+
*/
|
|
38
|
+
export declare function calculateBreakEvenPrice(userPosition: PerpPosition): BN;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param userPosition
|
|
42
|
+
* @returns Precision: PRICE_PRECISION (10^6)
|
|
43
|
+
*/
|
|
44
|
+
export declare function calculateEntryPrice(userPosition: PerpPosition): BN;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param userPosition
|
|
48
|
+
* @returns Precision: PRICE_PRECISION (10^10)
|
|
49
|
+
*/
|
|
50
|
+
export declare function calculateCostBasis(userPosition: PerpPosition, includeSettledPnl?: boolean): BN;
|
|
51
|
+
export declare function findDirectionToClose(userPosition: PerpPosition): PositionDirection;
|
|
52
|
+
export declare function positionCurrentDirection(userPosition: PerpPosition): PositionDirection;
|
|
53
|
+
export declare function isEmptyPosition(userPosition: PerpPosition): boolean;
|
|
54
|
+
export declare function hasOpenOrders(position: PerpPosition): boolean;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasOpenOrders = exports.isEmptyPosition = exports.positionCurrentDirection = exports.findDirectionToClose = exports.calculateCostBasis = exports.calculateEntryPrice = exports.calculateBreakEvenPrice = exports.positionIsAvailable = exports.calculatePositionFundingPNL = exports.calculateClaimablePnl = exports.calculatePositionPNL = exports.calculateBaseAssetValue = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const amm_1 = require("./amm");
|
|
8
|
+
const margin_1 = require("./margin");
|
|
9
|
+
const market_1 = require("./market");
|
|
10
|
+
/**
|
|
11
|
+
* calculateBaseAssetValue
|
|
12
|
+
* = market value of closing entire position
|
|
13
|
+
* @param market
|
|
14
|
+
* @param userPosition
|
|
15
|
+
* @param oraclePriceData
|
|
16
|
+
* @returns Base Asset Value. : Precision QUOTE_PRECISION
|
|
17
|
+
*/
|
|
18
|
+
function calculateBaseAssetValue(market, userPosition, oraclePriceData, useSpread = true, skipUpdate = false) {
|
|
19
|
+
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
20
|
+
return numericConstants_1.ZERO;
|
|
21
|
+
}
|
|
22
|
+
const directionToClose = findDirectionToClose(userPosition);
|
|
23
|
+
let prepegAmm;
|
|
24
|
+
if (!skipUpdate) {
|
|
25
|
+
if (market.amm.baseSpread > 0 && useSpread) {
|
|
26
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, directionToClose, oraclePriceData);
|
|
27
|
+
prepegAmm = {
|
|
28
|
+
baseAssetReserve,
|
|
29
|
+
quoteAssetReserve,
|
|
30
|
+
sqrtK: sqrtK,
|
|
31
|
+
pegMultiplier: newPeg,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
prepegAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, oraclePriceData);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
prepegAmm = market.amm;
|
|
40
|
+
}
|
|
41
|
+
const [newQuoteAssetReserve, _] = (0, amm_1.calculateAmmReservesAfterSwap)(prepegAmm, 'base', userPosition.baseAssetAmount.abs(), (0, amm_1.getSwapDirection)('base', directionToClose));
|
|
42
|
+
switch (directionToClose) {
|
|
43
|
+
case types_1.PositionDirection.SHORT:
|
|
44
|
+
return prepegAmm.quoteAssetReserve
|
|
45
|
+
.sub(newQuoteAssetReserve)
|
|
46
|
+
.mul(prepegAmm.pegMultiplier)
|
|
47
|
+
.div(numericConstants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO);
|
|
48
|
+
case types_1.PositionDirection.LONG:
|
|
49
|
+
return newQuoteAssetReserve
|
|
50
|
+
.sub(prepegAmm.quoteAssetReserve)
|
|
51
|
+
.mul(prepegAmm.pegMultiplier)
|
|
52
|
+
.div(numericConstants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO)
|
|
53
|
+
.add(numericConstants_1.ONE);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.calculateBaseAssetValue = calculateBaseAssetValue;
|
|
57
|
+
/**
|
|
58
|
+
* calculatePositionPNL
|
|
59
|
+
* = BaseAssetAmount * (Avg Exit Price - Avg Entry Price)
|
|
60
|
+
* @param market
|
|
61
|
+
* @param PerpPosition
|
|
62
|
+
* @param withFunding (adds unrealized funding payment pnl to result)
|
|
63
|
+
* @param oraclePriceData
|
|
64
|
+
* @returns BaseAssetAmount : Precision QUOTE_PRECISION
|
|
65
|
+
*/
|
|
66
|
+
function calculatePositionPNL(market, perpPosition, withFunding = false, oraclePriceData) {
|
|
67
|
+
if (perpPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
68
|
+
return perpPosition.quoteAssetAmount;
|
|
69
|
+
}
|
|
70
|
+
const baseAssetValue = (0, margin_1.calculateBaseAssetValueWithOracle)(market, perpPosition, oraclePriceData);
|
|
71
|
+
const baseAssetValueSign = perpPosition.baseAssetAmount.isNeg()
|
|
72
|
+
? new __1.BN(-1)
|
|
73
|
+
: new __1.BN(1);
|
|
74
|
+
let pnl = baseAssetValue
|
|
75
|
+
.mul(baseAssetValueSign)
|
|
76
|
+
.add(perpPosition.quoteAssetAmount);
|
|
77
|
+
if (withFunding) {
|
|
78
|
+
const fundingRatePnL = calculatePositionFundingPNL(market, perpPosition);
|
|
79
|
+
pnl = pnl.add(fundingRatePnL);
|
|
80
|
+
}
|
|
81
|
+
return pnl;
|
|
82
|
+
}
|
|
83
|
+
exports.calculatePositionPNL = calculatePositionPNL;
|
|
84
|
+
function calculateClaimablePnl(market, spotMarket, perpPosition, oraclePriceData) {
|
|
85
|
+
const unrealizedPnl = calculatePositionPNL(market, perpPosition, true, oraclePriceData);
|
|
86
|
+
let unsettledPnl = unrealizedPnl;
|
|
87
|
+
if (unrealizedPnl.gt(numericConstants_1.ZERO)) {
|
|
88
|
+
const excessPnlPool = __1.BN.max(numericConstants_1.ZERO, (0, market_1.calculateNetUserPnlImbalance)(market, spotMarket, oraclePriceData).mul(new __1.BN(-1)));
|
|
89
|
+
const maxPositivePnl = __1.BN.max(perpPosition.quoteAssetAmount.sub(perpPosition.quoteEntryAmount), numericConstants_1.ZERO).add(excessPnlPool);
|
|
90
|
+
unsettledPnl = __1.BN.min(maxPositivePnl, unrealizedPnl);
|
|
91
|
+
}
|
|
92
|
+
return unsettledPnl;
|
|
93
|
+
}
|
|
94
|
+
exports.calculateClaimablePnl = calculateClaimablePnl;
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param market
|
|
98
|
+
* @param PerpPosition
|
|
99
|
+
* @returns // QUOTE_PRECISION
|
|
100
|
+
*/
|
|
101
|
+
function calculatePositionFundingPNL(market, perpPosition) {
|
|
102
|
+
if (perpPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
103
|
+
return numericConstants_1.ZERO;
|
|
104
|
+
}
|
|
105
|
+
let ammCumulativeFundingRate;
|
|
106
|
+
if (perpPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
107
|
+
ammCumulativeFundingRate = market.amm.cumulativeFundingRateLong;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
ammCumulativeFundingRate = market.amm.cumulativeFundingRateShort;
|
|
111
|
+
}
|
|
112
|
+
const perPositionFundingRate = ammCumulativeFundingRate
|
|
113
|
+
.sub(perpPosition.lastCumulativeFundingRate)
|
|
114
|
+
.mul(perpPosition.baseAssetAmount)
|
|
115
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
116
|
+
.div(numericConstants_1.FUNDING_RATE_BUFFER_PRECISION)
|
|
117
|
+
.mul(new __1.BN(-1));
|
|
118
|
+
return perPositionFundingRate;
|
|
119
|
+
}
|
|
120
|
+
exports.calculatePositionFundingPNL = calculatePositionFundingPNL;
|
|
121
|
+
function positionIsAvailable(position) {
|
|
122
|
+
return (position.baseAssetAmount.eq(numericConstants_1.ZERO) &&
|
|
123
|
+
position.openOrders === 0 &&
|
|
124
|
+
position.quoteAssetAmount.eq(numericConstants_1.ZERO) &&
|
|
125
|
+
position.lpShares.eq(numericConstants_1.ZERO));
|
|
126
|
+
}
|
|
127
|
+
exports.positionIsAvailable = positionIsAvailable;
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @param userPosition
|
|
131
|
+
* @returns Precision: PRICE_PRECISION (10^6)
|
|
132
|
+
*/
|
|
133
|
+
function calculateBreakEvenPrice(userPosition) {
|
|
134
|
+
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
135
|
+
return numericConstants_1.ZERO;
|
|
136
|
+
}
|
|
137
|
+
return userPosition.quoteBreakEvenAmount
|
|
138
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
139
|
+
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
140
|
+
.div(userPosition.baseAssetAmount)
|
|
141
|
+
.abs();
|
|
142
|
+
}
|
|
143
|
+
exports.calculateBreakEvenPrice = calculateBreakEvenPrice;
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @param userPosition
|
|
147
|
+
* @returns Precision: PRICE_PRECISION (10^6)
|
|
148
|
+
*/
|
|
149
|
+
function calculateEntryPrice(userPosition) {
|
|
150
|
+
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
151
|
+
return numericConstants_1.ZERO;
|
|
152
|
+
}
|
|
153
|
+
return userPosition.quoteEntryAmount
|
|
154
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
155
|
+
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
156
|
+
.div(userPosition.baseAssetAmount)
|
|
157
|
+
.abs();
|
|
158
|
+
}
|
|
159
|
+
exports.calculateEntryPrice = calculateEntryPrice;
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* @param userPosition
|
|
163
|
+
* @returns Precision: PRICE_PRECISION (10^10)
|
|
164
|
+
*/
|
|
165
|
+
function calculateCostBasis(userPosition, includeSettledPnl = false) {
|
|
166
|
+
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
167
|
+
return numericConstants_1.ZERO;
|
|
168
|
+
}
|
|
169
|
+
return userPosition.quoteAssetAmount
|
|
170
|
+
.add(includeSettledPnl ? userPosition.settledPnl : numericConstants_1.ZERO)
|
|
171
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
172
|
+
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
173
|
+
.div(userPosition.baseAssetAmount)
|
|
174
|
+
.abs();
|
|
175
|
+
}
|
|
176
|
+
exports.calculateCostBasis = calculateCostBasis;
|
|
177
|
+
function findDirectionToClose(userPosition) {
|
|
178
|
+
return userPosition.baseAssetAmount.gt(numericConstants_1.ZERO)
|
|
179
|
+
? types_1.PositionDirection.SHORT
|
|
180
|
+
: types_1.PositionDirection.LONG;
|
|
181
|
+
}
|
|
182
|
+
exports.findDirectionToClose = findDirectionToClose;
|
|
183
|
+
function positionCurrentDirection(userPosition) {
|
|
184
|
+
return userPosition.baseAssetAmount.gte(numericConstants_1.ZERO)
|
|
185
|
+
? types_1.PositionDirection.LONG
|
|
186
|
+
: types_1.PositionDirection.SHORT;
|
|
187
|
+
}
|
|
188
|
+
exports.positionCurrentDirection = positionCurrentDirection;
|
|
189
|
+
function isEmptyPosition(userPosition) {
|
|
190
|
+
return userPosition.baseAssetAmount.eq(numericConstants_1.ZERO) && userPosition.openOrders === 0;
|
|
191
|
+
}
|
|
192
|
+
exports.isEmptyPosition = isEmptyPosition;
|
|
193
|
+
function hasOpenOrders(position) {
|
|
194
|
+
return (position.openOrders != 0 ||
|
|
195
|
+
!position.openBids.eq(numericConstants_1.ZERO) ||
|
|
196
|
+
!position.openAsks.eq(numericConstants_1.ZERO));
|
|
197
|
+
}
|
|
198
|
+
exports.hasOpenOrders = hasOpenOrders;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
|
+
import { AMM } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Helper function calculating adjust k cost
|
|
6
|
+
* @param amm
|
|
7
|
+
* @param numerator
|
|
8
|
+
* @param denomenator
|
|
9
|
+
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateAdjustKCost(amm: AMM, numerator: BN, denomenator: BN): BN;
|
|
12
|
+
/**
|
|
13
|
+
* Helper function calculating adjust pegMultiplier (repeg) cost
|
|
14
|
+
*
|
|
15
|
+
* @param amm
|
|
16
|
+
* @param newPeg
|
|
17
|
+
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
18
|
+
*/
|
|
19
|
+
export declare function calculateRepegCost(amm: AMM, newPeg: BN): BN;
|
|
20
|
+
export declare function calculateBudgetedKBN(x: BN, y: BN, budget: BN, Q: BN, d: BN): [BN, BN];
|
|
21
|
+
export declare function calculateBudgetedK(amm: AMM, cost: BN): [BN, BN];
|
|
22
|
+
export declare function calculateBudgetedPeg(amm: AMM, budget: BN, targetPrice: BN): BN;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateBudgetedPeg = exports.calculateBudgetedK = exports.calculateBudgetedKBN = exports.calculateRepegCost = exports.calculateAdjustKCost = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const assert_1 = require("../assert/assert");
|
|
6
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
|
+
/**
|
|
8
|
+
* Helper function calculating adjust k cost
|
|
9
|
+
* @param amm
|
|
10
|
+
* @param numerator
|
|
11
|
+
* @param denomenator
|
|
12
|
+
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
13
|
+
*/
|
|
14
|
+
function calculateAdjustKCost(amm, numerator, denomenator) {
|
|
15
|
+
// const k = market.amm.sqrtK.mul(market.amm.sqrtK);
|
|
16
|
+
const x = amm.baseAssetReserve;
|
|
17
|
+
const y = amm.quoteAssetReserve;
|
|
18
|
+
const d = amm.baseAssetAmountWithAmm;
|
|
19
|
+
const Q = amm.pegMultiplier;
|
|
20
|
+
const quoteScale = y.mul(d).mul(Q); //.div(AMM_RESERVE_PRECISION);
|
|
21
|
+
const p = numerator.mul(numericConstants_1.PRICE_PRECISION).div(denomenator);
|
|
22
|
+
const cost = quoteScale
|
|
23
|
+
.mul(numericConstants_1.PERCENTAGE_PRECISION)
|
|
24
|
+
.mul(numericConstants_1.PERCENTAGE_PRECISION)
|
|
25
|
+
.div(x.add(d))
|
|
26
|
+
.sub(quoteScale
|
|
27
|
+
.mul(p)
|
|
28
|
+
.mul(numericConstants_1.PERCENTAGE_PRECISION)
|
|
29
|
+
.mul(numericConstants_1.PERCENTAGE_PRECISION)
|
|
30
|
+
.div(numericConstants_1.PRICE_PRECISION)
|
|
31
|
+
.div(x.mul(p).div(numericConstants_1.PRICE_PRECISION).add(d)))
|
|
32
|
+
.div(numericConstants_1.PERCENTAGE_PRECISION)
|
|
33
|
+
.div(numericConstants_1.PERCENTAGE_PRECISION)
|
|
34
|
+
.div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
35
|
+
.div(numericConstants_1.PEG_PRECISION);
|
|
36
|
+
return cost.mul(new anchor_1.BN(-1));
|
|
37
|
+
}
|
|
38
|
+
exports.calculateAdjustKCost = calculateAdjustKCost;
|
|
39
|
+
// /**
|
|
40
|
+
// * Helper function calculating adjust k cost
|
|
41
|
+
// * @param amm
|
|
42
|
+
// * @param numerator
|
|
43
|
+
// * @param denomenator
|
|
44
|
+
// * @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
45
|
+
// */
|
|
46
|
+
// export function calculateAdjustKCost2(
|
|
47
|
+
// amm: AMM,
|
|
48
|
+
// numerator: BN,
|
|
49
|
+
// denomenator: BN
|
|
50
|
+
// ): BN {
|
|
51
|
+
// // const k = market.amm.sqrtK.mul(market.amm.sqrtK);
|
|
52
|
+
// const directionToClose = amm.baseAssetAmountWithAmm.gt(ZERO)
|
|
53
|
+
// ? PositionDirection.SHORT
|
|
54
|
+
// : PositionDirection.LONG;
|
|
55
|
+
// const [newQuoteAssetReserve, _newBaseAssetReserve] =
|
|
56
|
+
// calculateAmmReservesAfterSwap(
|
|
57
|
+
// amm,
|
|
58
|
+
// 'base',
|
|
59
|
+
// amm.baseAssetAmountWithAmm.abs(),
|
|
60
|
+
// getSwapDirection('base', directionToClose)
|
|
61
|
+
// );
|
|
62
|
+
// }
|
|
63
|
+
/**
|
|
64
|
+
* Helper function calculating adjust pegMultiplier (repeg) cost
|
|
65
|
+
*
|
|
66
|
+
* @param amm
|
|
67
|
+
* @param newPeg
|
|
68
|
+
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
69
|
+
*/
|
|
70
|
+
function calculateRepegCost(amm, newPeg) {
|
|
71
|
+
const dqar = amm.quoteAssetReserve.sub(amm.terminalQuoteAssetReserve);
|
|
72
|
+
const cost = dqar
|
|
73
|
+
.mul(newPeg.sub(amm.pegMultiplier))
|
|
74
|
+
.div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
75
|
+
.div(numericConstants_1.PEG_PRECISION);
|
|
76
|
+
return cost;
|
|
77
|
+
}
|
|
78
|
+
exports.calculateRepegCost = calculateRepegCost;
|
|
79
|
+
function calculateBudgetedKBN(x, y, budget, Q, d) {
|
|
80
|
+
(0, assert_1.assert)(Q.gt(new anchor_1.BN(0)));
|
|
81
|
+
const C = budget.mul(new anchor_1.BN(-1));
|
|
82
|
+
let dSign = new anchor_1.BN(1);
|
|
83
|
+
if (d.lt(new anchor_1.BN(0))) {
|
|
84
|
+
dSign = new anchor_1.BN(-1);
|
|
85
|
+
}
|
|
86
|
+
const pegged_y_d_d = y
|
|
87
|
+
.mul(d)
|
|
88
|
+
.mul(d)
|
|
89
|
+
.mul(Q)
|
|
90
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
91
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
92
|
+
.div(numericConstants_1.PEG_PRECISION);
|
|
93
|
+
const numer1 = pegged_y_d_d;
|
|
94
|
+
const numer2 = C.mul(d)
|
|
95
|
+
.div(numericConstants_1.QUOTE_PRECISION)
|
|
96
|
+
.mul(x.add(d))
|
|
97
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
98
|
+
.mul(dSign);
|
|
99
|
+
const denom1 = C.mul(x)
|
|
100
|
+
.mul(x.add(d))
|
|
101
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
102
|
+
.div(numericConstants_1.QUOTE_PRECISION);
|
|
103
|
+
const denom2 = pegged_y_d_d;
|
|
104
|
+
// protocol is spending to increase k
|
|
105
|
+
if (C.lt(numericConstants_1.ZERO)) {
|
|
106
|
+
// thus denom1 is negative and solution is unstable
|
|
107
|
+
if (denom1.abs().gt(denom2.abs())) {
|
|
108
|
+
console.log('denom1 > denom2', denom1.toString(), denom2.toString());
|
|
109
|
+
console.log('budget cost exceeds stable K solution');
|
|
110
|
+
return [new anchor_1.BN(10000), new anchor_1.BN(1)];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const numerator = numer1.sub(numer2).div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
|
|
114
|
+
const denominator = denom1.add(denom2).div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
|
|
115
|
+
return [numerator, denominator];
|
|
116
|
+
}
|
|
117
|
+
exports.calculateBudgetedKBN = calculateBudgetedKBN;
|
|
118
|
+
function calculateBudgetedK(amm, cost) {
|
|
119
|
+
// wolframalpha.com
|
|
120
|
+
// (1/(x+d) - p/(x*p+d))*y*d*Q = C solve for p
|
|
121
|
+
// p = (d(y*d*Q - C(x+d))) / (C*x(x+d) + y*d*d*Q)
|
|
122
|
+
// numer
|
|
123
|
+
// = y*d*d*Q - Cxd - Cdd
|
|
124
|
+
// = y/x*Q*d*d - Cd - Cd/x
|
|
125
|
+
// = mark - C/d - C/(x)
|
|
126
|
+
// = mark/C - 1/d - 1/x
|
|
127
|
+
// denom
|
|
128
|
+
// = C*x*x + C*x*d + y*d*d*Q
|
|
129
|
+
// = x/d**2 + 1 / d + mark/C
|
|
130
|
+
// todo: assumes k = x * y
|
|
131
|
+
// otherwise use: (y(1-p) + (kp^2/(x*p+d)) - k/(x+d)) * Q = C solve for p
|
|
132
|
+
const x = amm.baseAssetReserve;
|
|
133
|
+
const y = amm.quoteAssetReserve;
|
|
134
|
+
const d = amm.baseAssetAmountWithAmm;
|
|
135
|
+
const Q = amm.pegMultiplier;
|
|
136
|
+
const [numerator, denominator] = calculateBudgetedKBN(x, y, cost, Q, d);
|
|
137
|
+
return [numerator, denominator];
|
|
138
|
+
}
|
|
139
|
+
exports.calculateBudgetedK = calculateBudgetedK;
|
|
140
|
+
function calculateBudgetedPeg(amm, budget, targetPrice) {
|
|
141
|
+
let perPegCost = amm.quoteAssetReserve
|
|
142
|
+
.sub(amm.terminalQuoteAssetReserve)
|
|
143
|
+
.div(numericConstants_1.AMM_RESERVE_PRECISION.div(numericConstants_1.PRICE_PRECISION));
|
|
144
|
+
if (perPegCost.gt(numericConstants_1.ZERO)) {
|
|
145
|
+
perPegCost = perPegCost.add(numericConstants_1.ONE);
|
|
146
|
+
}
|
|
147
|
+
else if (perPegCost.lt(numericConstants_1.ZERO)) {
|
|
148
|
+
perPegCost = perPegCost.sub(numericConstants_1.ONE);
|
|
149
|
+
}
|
|
150
|
+
const targetPeg = targetPrice
|
|
151
|
+
.mul(amm.baseAssetReserve)
|
|
152
|
+
.div(amm.quoteAssetReserve)
|
|
153
|
+
.div(numericConstants_1.PRICE_DIV_PEG);
|
|
154
|
+
const pegChangeDirection = targetPeg.sub(amm.pegMultiplier);
|
|
155
|
+
const useTargetPeg = (perPegCost.lt(numericConstants_1.ZERO) && pegChangeDirection.gt(numericConstants_1.ZERO)) ||
|
|
156
|
+
(perPegCost.gt(numericConstants_1.ZERO) && pegChangeDirection.lt(numericConstants_1.ZERO));
|
|
157
|
+
if (perPegCost.eq(numericConstants_1.ZERO) || useTargetPeg) {
|
|
158
|
+
return targetPeg;
|
|
159
|
+
}
|
|
160
|
+
const budgetDeltaPeg = budget.mul(numericConstants_1.PEG_PRECISION).div(perPegCost);
|
|
161
|
+
const newPeg = anchor_1.BN.max(numericConstants_1.ONE, amm.pegMultiplier.add(budgetDeltaPeg));
|
|
162
|
+
return newPeg;
|
|
163
|
+
}
|
|
164
|
+
exports.calculateBudgetedPeg = calculateBudgetedPeg;
|