@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,83 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
|
+
import { OraclePriceData } from '../oracles/types';
|
|
5
|
+
import { StrictOraclePrice } from '../oracles/strictOraclePrice';
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the balance of a given token amount including any accumulated interest. This
|
|
8
|
+
* is the same as `SpotPosition.scaledBalance`.
|
|
9
|
+
*
|
|
10
|
+
* @param {BN} tokenAmount - the amount of tokens
|
|
11
|
+
* @param {SpotMarketAccount} spotMarket - the spot market account
|
|
12
|
+
* @param {SpotBalanceType} balanceType - the balance type ('deposit' or 'borrow')
|
|
13
|
+
* @return {BN} the calculated balance, scaled by `SPOT_MARKET_BALANCE_PRECISION`
|
|
14
|
+
*/
|
|
15
|
+
export declare function getBalance(tokenAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
|
|
16
|
+
/**
|
|
17
|
+
* Calculates the spot token amount including any accumulated interest.
|
|
18
|
+
*
|
|
19
|
+
* @param {BN} balanceAmount - The balance amount, typically from `SpotPosition.scaledBalance`
|
|
20
|
+
* @param {SpotMarketAccount} spotMarket - The spot market account details
|
|
21
|
+
* @param {SpotBalanceType} balanceType - The balance type to be used for calculation
|
|
22
|
+
* @returns {BN} The calculated token amount, scaled by `SpotMarketConfig.precision`
|
|
23
|
+
*/
|
|
24
|
+
export declare function getTokenAmount(balanceAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the signed (positive for deposit,negative for borrow) token amount based on the balance type.
|
|
27
|
+
*
|
|
28
|
+
* @param {BN} tokenAmount - The token amount to convert (from `getTokenAmount`)
|
|
29
|
+
* @param {SpotBalanceType} balanceType - The balance type to determine the sign of the token amount.
|
|
30
|
+
* @returns {BN} - The signed token amount, scaled by `SpotMarketConfig.precision`
|
|
31
|
+
*/
|
|
32
|
+
export declare function getSignedTokenAmount(tokenAmount: BN, balanceType: SpotBalanceType): BN;
|
|
33
|
+
/**
|
|
34
|
+
* Calculates the value of a given token amount using the worst of the provided oracle price and its TWAP.
|
|
35
|
+
*
|
|
36
|
+
* @param {BN} tokenAmount - The amount of tokens to calculate the value for (from `getTokenAmount`)
|
|
37
|
+
* @param {number} spotDecimals - The number of decimals in the token.
|
|
38
|
+
* @param {StrictOraclePrice} strictOraclePrice - Contains oracle price and 5min twap.
|
|
39
|
+
* @return {BN} The calculated value of the given token amount, scaled by `PRICE_PRECISION`
|
|
40
|
+
*/
|
|
41
|
+
export declare function getStrictTokenValue(tokenAmount: BN, spotDecimals: number, strictOraclePrice: StrictOraclePrice): BN;
|
|
42
|
+
/**
|
|
43
|
+
* Calculates the value of a given token amount in relation to an oracle price data
|
|
44
|
+
*
|
|
45
|
+
* @param {BN} tokenAmount - The amount of tokens to calculate the value for (from `getTokenAmount`)
|
|
46
|
+
* @param {number} spotDecimals - The number of decimal places of the token.
|
|
47
|
+
* @param {OraclePriceData} oraclePriceData - The oracle price data (typically a token/USD oracle).
|
|
48
|
+
* @return {BN} The value of the token based on the oracle, scaled by `PRICE_PRECISION`
|
|
49
|
+
*/
|
|
50
|
+
export declare function getTokenValue(tokenAmount: BN, spotDecimals: number, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
|
|
51
|
+
export declare function calculateAssetWeight(balanceAmount: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
52
|
+
export declare function calculateScaledInitialAssetWeight(spotMarket: SpotMarketAccount, oraclePrice: BN): BN;
|
|
53
|
+
export declare function calculateLiabilityWeight(size: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
54
|
+
export declare function calculateUtilization(bank: SpotMarketAccount, delta?: BN): BN;
|
|
55
|
+
/**
|
|
56
|
+
* calculates max borrow amount where rate would stay below targetBorrowRate
|
|
57
|
+
* @param spotMarketAccount
|
|
58
|
+
* @param targetBorrowRate
|
|
59
|
+
* @returns : Precision: TOKEN DECIMALS
|
|
60
|
+
*/
|
|
61
|
+
export declare function calculateSpotMarketBorrowCapacity(spotMarketAccount: SpotMarketAccount, targetBorrowRate: BN): {
|
|
62
|
+
totalCapacity: BN;
|
|
63
|
+
remainingCapacity: BN;
|
|
64
|
+
};
|
|
65
|
+
export declare function calculateInterestRate(bank: SpotMarketAccount, delta?: BN, currentUtilization?: BN): BN;
|
|
66
|
+
export declare function calculateDepositRate(bank: SpotMarketAccount, delta?: BN, currentUtilization?: BN): BN;
|
|
67
|
+
export declare function calculateBorrowRate(bank: SpotMarketAccount, delta?: BN, currentUtilization?: BN): BN;
|
|
68
|
+
export declare function calculateInterestAccumulated(bank: SpotMarketAccount, now: BN): {
|
|
69
|
+
borrowInterest: BN;
|
|
70
|
+
depositInterest: BN;
|
|
71
|
+
};
|
|
72
|
+
export declare function calculateTokenUtilizationLimits(depositTokenAmount: BN, borrowTokenAmount: BN, spotMarket: SpotMarketAccount): {
|
|
73
|
+
minDepositTokensForUtilization: BN;
|
|
74
|
+
maxBorrowTokensForUtilization: BN;
|
|
75
|
+
};
|
|
76
|
+
export declare function calculateWithdrawLimit(spotMarket: SpotMarketAccount, now: BN): {
|
|
77
|
+
borrowLimit: BN;
|
|
78
|
+
withdrawLimit: BN;
|
|
79
|
+
minDepositAmount: BN;
|
|
80
|
+
maxBorrowAmount: BN;
|
|
81
|
+
currentDepositAmount: any;
|
|
82
|
+
currentBorrowAmount: any;
|
|
83
|
+
};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateWithdrawLimit = exports.calculateTokenUtilizationLimits = exports.calculateInterestAccumulated = exports.calculateBorrowRate = exports.calculateDepositRate = exports.calculateInterestRate = exports.calculateSpotMarketBorrowCapacity = exports.calculateUtilization = exports.calculateLiabilityWeight = exports.calculateScaledInitialAssetWeight = exports.calculateAssetWeight = exports.getTokenValue = exports.getStrictTokenValue = exports.getSignedTokenAmount = exports.getTokenAmount = exports.getBalance = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
|
+
const margin_1 = require("./margin");
|
|
8
|
+
const numericConstants_2 = require("../constants/numericConstants");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the balance of a given token amount including any accumulated interest. This
|
|
12
|
+
* is the same as `SpotPosition.scaledBalance`.
|
|
13
|
+
*
|
|
14
|
+
* @param {BN} tokenAmount - the amount of tokens
|
|
15
|
+
* @param {SpotMarketAccount} spotMarket - the spot market account
|
|
16
|
+
* @param {SpotBalanceType} balanceType - the balance type ('deposit' or 'borrow')
|
|
17
|
+
* @return {BN} the calculated balance, scaled by `SPOT_MARKET_BALANCE_PRECISION`
|
|
18
|
+
*/
|
|
19
|
+
function getBalance(tokenAmount, spotMarket, balanceType) {
|
|
20
|
+
const precisionIncrease = numericConstants_1.TEN.pow(new anchor_1.BN(19 - spotMarket.decimals));
|
|
21
|
+
const cumulativeInterest = (0, types_1.isVariant)(balanceType, 'deposit')
|
|
22
|
+
? spotMarket.cumulativeDepositInterest
|
|
23
|
+
: spotMarket.cumulativeBorrowInterest;
|
|
24
|
+
let balance = tokenAmount.mul(precisionIncrease).div(cumulativeInterest);
|
|
25
|
+
if (!balance.eq(numericConstants_1.ZERO) && (0, types_1.isVariant)(balanceType, 'borrow')) {
|
|
26
|
+
balance = balance.add(numericConstants_1.ONE);
|
|
27
|
+
}
|
|
28
|
+
return balance;
|
|
29
|
+
}
|
|
30
|
+
exports.getBalance = getBalance;
|
|
31
|
+
/**
|
|
32
|
+
* Calculates the spot token amount including any accumulated interest.
|
|
33
|
+
*
|
|
34
|
+
* @param {BN} balanceAmount - The balance amount, typically from `SpotPosition.scaledBalance`
|
|
35
|
+
* @param {SpotMarketAccount} spotMarket - The spot market account details
|
|
36
|
+
* @param {SpotBalanceType} balanceType - The balance type to be used for calculation
|
|
37
|
+
* @returns {BN} The calculated token amount, scaled by `SpotMarketConfig.precision`
|
|
38
|
+
*/
|
|
39
|
+
function getTokenAmount(balanceAmount, spotMarket, balanceType) {
|
|
40
|
+
const precisionDecrease = numericConstants_1.TEN.pow(new anchor_1.BN(19 - spotMarket.decimals));
|
|
41
|
+
if ((0, types_1.isVariant)(balanceType, 'deposit')) {
|
|
42
|
+
return balanceAmount
|
|
43
|
+
.mul(spotMarket.cumulativeDepositInterest)
|
|
44
|
+
.div(precisionDecrease);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return (0, utils_1.divCeil)(balanceAmount.mul(spotMarket.cumulativeBorrowInterest), precisionDecrease);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.getTokenAmount = getTokenAmount;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the signed (positive for deposit,negative for borrow) token amount based on the balance type.
|
|
53
|
+
*
|
|
54
|
+
* @param {BN} tokenAmount - The token amount to convert (from `getTokenAmount`)
|
|
55
|
+
* @param {SpotBalanceType} balanceType - The balance type to determine the sign of the token amount.
|
|
56
|
+
* @returns {BN} - The signed token amount, scaled by `SpotMarketConfig.precision`
|
|
57
|
+
*/
|
|
58
|
+
function getSignedTokenAmount(tokenAmount, balanceType) {
|
|
59
|
+
if ((0, types_1.isVariant)(balanceType, 'deposit')) {
|
|
60
|
+
return tokenAmount;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return tokenAmount.abs().neg();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.getSignedTokenAmount = getSignedTokenAmount;
|
|
67
|
+
/**
|
|
68
|
+
* Calculates the value of a given token amount using the worst of the provided oracle price and its TWAP.
|
|
69
|
+
*
|
|
70
|
+
* @param {BN} tokenAmount - The amount of tokens to calculate the value for (from `getTokenAmount`)
|
|
71
|
+
* @param {number} spotDecimals - The number of decimals in the token.
|
|
72
|
+
* @param {StrictOraclePrice} strictOraclePrice - Contains oracle price and 5min twap.
|
|
73
|
+
* @return {BN} The calculated value of the given token amount, scaled by `PRICE_PRECISION`
|
|
74
|
+
*/
|
|
75
|
+
function getStrictTokenValue(tokenAmount, spotDecimals, strictOraclePrice) {
|
|
76
|
+
if (tokenAmount.eq(numericConstants_1.ZERO)) {
|
|
77
|
+
return numericConstants_1.ZERO;
|
|
78
|
+
}
|
|
79
|
+
let price;
|
|
80
|
+
if (tokenAmount.gte(numericConstants_1.ZERO)) {
|
|
81
|
+
price = strictOraclePrice.min();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
price = strictOraclePrice.max();
|
|
85
|
+
}
|
|
86
|
+
const precisionDecrease = numericConstants_1.TEN.pow(new anchor_1.BN(spotDecimals));
|
|
87
|
+
return tokenAmount.mul(price).div(precisionDecrease);
|
|
88
|
+
}
|
|
89
|
+
exports.getStrictTokenValue = getStrictTokenValue;
|
|
90
|
+
/**
|
|
91
|
+
* Calculates the value of a given token amount in relation to an oracle price data
|
|
92
|
+
*
|
|
93
|
+
* @param {BN} tokenAmount - The amount of tokens to calculate the value for (from `getTokenAmount`)
|
|
94
|
+
* @param {number} spotDecimals - The number of decimal places of the token.
|
|
95
|
+
* @param {OraclePriceData} oraclePriceData - The oracle price data (typically a token/USD oracle).
|
|
96
|
+
* @return {BN} The value of the token based on the oracle, scaled by `PRICE_PRECISION`
|
|
97
|
+
*/
|
|
98
|
+
function getTokenValue(tokenAmount, spotDecimals, oraclePriceData) {
|
|
99
|
+
if (tokenAmount.eq(numericConstants_1.ZERO)) {
|
|
100
|
+
return numericConstants_1.ZERO;
|
|
101
|
+
}
|
|
102
|
+
const precisionDecrease = numericConstants_1.TEN.pow(new anchor_1.BN(spotDecimals));
|
|
103
|
+
return tokenAmount.mul(oraclePriceData.price).div(precisionDecrease);
|
|
104
|
+
}
|
|
105
|
+
exports.getTokenValue = getTokenValue;
|
|
106
|
+
function calculateAssetWeight(balanceAmount, oraclePrice, spotMarket, marginCategory) {
|
|
107
|
+
const sizePrecision = numericConstants_1.TEN.pow(new anchor_1.BN(spotMarket.decimals));
|
|
108
|
+
let sizeInAmmReservePrecision;
|
|
109
|
+
if (sizePrecision.gt(numericConstants_1.AMM_RESERVE_PRECISION)) {
|
|
110
|
+
sizeInAmmReservePrecision = balanceAmount.div(sizePrecision.div(numericConstants_1.AMM_RESERVE_PRECISION));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
sizeInAmmReservePrecision = balanceAmount
|
|
114
|
+
.mul(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
115
|
+
.div(sizePrecision);
|
|
116
|
+
}
|
|
117
|
+
let assetWeight;
|
|
118
|
+
switch (marginCategory) {
|
|
119
|
+
case 'Initial':
|
|
120
|
+
assetWeight = (0, margin_1.calculateSizeDiscountAssetWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), calculateScaledInitialAssetWeight(spotMarket, oraclePrice));
|
|
121
|
+
break;
|
|
122
|
+
case 'Maintenance':
|
|
123
|
+
assetWeight = (0, margin_1.calculateSizeDiscountAssetWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.maintenanceAssetWeight));
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
assetWeight = calculateScaledInitialAssetWeight(spotMarket, oraclePrice);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
return assetWeight;
|
|
130
|
+
}
|
|
131
|
+
exports.calculateAssetWeight = calculateAssetWeight;
|
|
132
|
+
function calculateScaledInitialAssetWeight(spotMarket, oraclePrice) {
|
|
133
|
+
if (spotMarket.scaleInitialAssetWeightStart.eq(numericConstants_1.ZERO)) {
|
|
134
|
+
return new anchor_1.BN(spotMarket.initialAssetWeight);
|
|
135
|
+
}
|
|
136
|
+
const deposits = getTokenAmount(spotMarket.depositBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
137
|
+
const depositsValue = getTokenValue(deposits, spotMarket.decimals, {
|
|
138
|
+
price: oraclePrice,
|
|
139
|
+
});
|
|
140
|
+
if (depositsValue.lt(spotMarket.scaleInitialAssetWeightStart)) {
|
|
141
|
+
return new anchor_1.BN(spotMarket.initialAssetWeight);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return new anchor_1.BN(spotMarket.initialAssetWeight)
|
|
145
|
+
.mul(spotMarket.scaleInitialAssetWeightStart)
|
|
146
|
+
.div(depositsValue);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.calculateScaledInitialAssetWeight = calculateScaledInitialAssetWeight;
|
|
150
|
+
function calculateLiabilityWeight(size, spotMarket, marginCategory) {
|
|
151
|
+
const sizePrecision = numericConstants_1.TEN.pow(new anchor_1.BN(spotMarket.decimals));
|
|
152
|
+
let sizeInAmmReservePrecision;
|
|
153
|
+
if (sizePrecision.gt(numericConstants_1.AMM_RESERVE_PRECISION)) {
|
|
154
|
+
sizeInAmmReservePrecision = size.div(sizePrecision.div(numericConstants_1.AMM_RESERVE_PRECISION));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
sizeInAmmReservePrecision = size
|
|
158
|
+
.mul(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
159
|
+
.div(sizePrecision);
|
|
160
|
+
}
|
|
161
|
+
let liabilityWeight;
|
|
162
|
+
switch (marginCategory) {
|
|
163
|
+
case 'Initial':
|
|
164
|
+
liabilityWeight = (0, margin_1.calculateSizePremiumLiabilityWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.initialLiabilityWeight), numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
|
|
165
|
+
break;
|
|
166
|
+
case 'Maintenance':
|
|
167
|
+
liabilityWeight = (0, margin_1.calculateSizePremiumLiabilityWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.maintenanceLiabilityWeight), numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
liabilityWeight = new anchor_1.BN(spotMarket.initialLiabilityWeight);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return liabilityWeight;
|
|
174
|
+
}
|
|
175
|
+
exports.calculateLiabilityWeight = calculateLiabilityWeight;
|
|
176
|
+
function calculateUtilization(bank, delta = numericConstants_1.ZERO) {
|
|
177
|
+
let tokenDepositAmount = getTokenAmount(bank.depositBalance, bank, types_1.SpotBalanceType.DEPOSIT);
|
|
178
|
+
let tokenBorrowAmount = getTokenAmount(bank.borrowBalance, bank, types_1.SpotBalanceType.BORROW);
|
|
179
|
+
if (delta.gt(numericConstants_1.ZERO)) {
|
|
180
|
+
tokenDepositAmount = tokenDepositAmount.add(delta);
|
|
181
|
+
}
|
|
182
|
+
else if (delta.lt(numericConstants_1.ZERO)) {
|
|
183
|
+
tokenBorrowAmount = tokenBorrowAmount.add(delta.abs());
|
|
184
|
+
}
|
|
185
|
+
let utilization;
|
|
186
|
+
if (tokenBorrowAmount.eq(numericConstants_1.ZERO) && tokenDepositAmount.eq(numericConstants_1.ZERO)) {
|
|
187
|
+
utilization = numericConstants_1.ZERO;
|
|
188
|
+
}
|
|
189
|
+
else if (tokenDepositAmount.eq(numericConstants_1.ZERO)) {
|
|
190
|
+
utilization = numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
utilization = tokenBorrowAmount
|
|
194
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
195
|
+
.div(tokenDepositAmount);
|
|
196
|
+
}
|
|
197
|
+
return utilization;
|
|
198
|
+
}
|
|
199
|
+
exports.calculateUtilization = calculateUtilization;
|
|
200
|
+
/**
|
|
201
|
+
* calculates max borrow amount where rate would stay below targetBorrowRate
|
|
202
|
+
* @param spotMarketAccount
|
|
203
|
+
* @param targetBorrowRate
|
|
204
|
+
* @returns : Precision: TOKEN DECIMALS
|
|
205
|
+
*/
|
|
206
|
+
function calculateSpotMarketBorrowCapacity(spotMarketAccount, targetBorrowRate) {
|
|
207
|
+
const currentBorrowRate = calculateBorrowRate(spotMarketAccount);
|
|
208
|
+
const tokenDepositAmount = getTokenAmount(spotMarketAccount.depositBalance, spotMarketAccount, types_1.SpotBalanceType.DEPOSIT);
|
|
209
|
+
const tokenBorrowAmount = getTokenAmount(spotMarketAccount.borrowBalance, spotMarketAccount, types_1.SpotBalanceType.BORROW);
|
|
210
|
+
let targetUtilization;
|
|
211
|
+
// target utilization past mid point
|
|
212
|
+
if (targetBorrowRate.gte(new anchor_1.BN(spotMarketAccount.optimalBorrowRate))) {
|
|
213
|
+
const borrowRateSlope = new anchor_1.BN(spotMarketAccount.maxBorrowRate - spotMarketAccount.optimalBorrowRate)
|
|
214
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
215
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION.sub(new anchor_1.BN(spotMarketAccount.optimalUtilization)));
|
|
216
|
+
const surplusTargetUtilization = targetBorrowRate
|
|
217
|
+
.sub(new anchor_1.BN(spotMarketAccount.optimalBorrowRate))
|
|
218
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
219
|
+
.div(borrowRateSlope);
|
|
220
|
+
targetUtilization = surplusTargetUtilization.add(new anchor_1.BN(spotMarketAccount.optimalUtilization));
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
const borrowRateSlope = new anchor_1.BN(spotMarketAccount.optimalBorrowRate)
|
|
224
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
225
|
+
.div(new anchor_1.BN(spotMarketAccount.optimalUtilization));
|
|
226
|
+
targetUtilization = targetBorrowRate
|
|
227
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
228
|
+
.div(borrowRateSlope);
|
|
229
|
+
}
|
|
230
|
+
const totalCapacity = tokenDepositAmount
|
|
231
|
+
.mul(targetUtilization)
|
|
232
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION);
|
|
233
|
+
let remainingCapacity;
|
|
234
|
+
if (currentBorrowRate.gte(targetBorrowRate)) {
|
|
235
|
+
remainingCapacity = numericConstants_1.ZERO;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
remainingCapacity = anchor_1.BN.max(numericConstants_1.ZERO, totalCapacity.sub(tokenBorrowAmount));
|
|
239
|
+
}
|
|
240
|
+
if (spotMarketAccount.maxTokenBorrowsFraction > 0) {
|
|
241
|
+
const maxTokenBorrows = spotMarketAccount.maxTokenDeposits
|
|
242
|
+
.mul(new anchor_1.BN(spotMarketAccount.maxTokenBorrowsFraction))
|
|
243
|
+
.divn(10000);
|
|
244
|
+
remainingCapacity = anchor_1.BN.min(remainingCapacity, anchor_1.BN.max(numericConstants_1.ZERO, maxTokenBorrows.sub(tokenBorrowAmount)));
|
|
245
|
+
}
|
|
246
|
+
return { totalCapacity, remainingCapacity };
|
|
247
|
+
}
|
|
248
|
+
exports.calculateSpotMarketBorrowCapacity = calculateSpotMarketBorrowCapacity;
|
|
249
|
+
function calculateInterestRate(bank, delta = numericConstants_1.ZERO, currentUtilization = null) {
|
|
250
|
+
const utilization = currentUtilization || calculateUtilization(bank, delta);
|
|
251
|
+
let interestRate;
|
|
252
|
+
if (utilization.gt(new anchor_1.BN(bank.optimalUtilization))) {
|
|
253
|
+
const surplusUtilization = utilization.sub(new anchor_1.BN(bank.optimalUtilization));
|
|
254
|
+
const borrowRateSlope = new anchor_1.BN(bank.maxBorrowRate - bank.optimalBorrowRate)
|
|
255
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
256
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION.sub(new anchor_1.BN(bank.optimalUtilization)));
|
|
257
|
+
interestRate = new anchor_1.BN(bank.optimalBorrowRate).add(surplusUtilization
|
|
258
|
+
.mul(borrowRateSlope)
|
|
259
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION));
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const borrowRateSlope = new anchor_1.BN(bank.optimalBorrowRate)
|
|
263
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
264
|
+
.div(new anchor_1.BN(bank.optimalUtilization));
|
|
265
|
+
interestRate = utilization
|
|
266
|
+
.mul(borrowRateSlope)
|
|
267
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION);
|
|
268
|
+
}
|
|
269
|
+
return anchor_1.BN.max(interestRate, new anchor_1.BN(bank.minBorrowRate).mul(numericConstants_2.PERCENTAGE_PRECISION.divn(200)));
|
|
270
|
+
}
|
|
271
|
+
exports.calculateInterestRate = calculateInterestRate;
|
|
272
|
+
function calculateDepositRate(bank, delta = numericConstants_1.ZERO, currentUtilization = null) {
|
|
273
|
+
// positive delta => adding to deposit
|
|
274
|
+
// negative delta => adding to borrow
|
|
275
|
+
const utilization = currentUtilization || calculateUtilization(bank, delta);
|
|
276
|
+
const borrowRate = calculateBorrowRate(bank, delta, utilization);
|
|
277
|
+
const depositRate = borrowRate
|
|
278
|
+
.mul(numericConstants_2.PERCENTAGE_PRECISION.sub(new anchor_1.BN(bank.insuranceFund.totalFactor)))
|
|
279
|
+
.mul(utilization)
|
|
280
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
281
|
+
.div(numericConstants_2.PERCENTAGE_PRECISION);
|
|
282
|
+
return depositRate;
|
|
283
|
+
}
|
|
284
|
+
exports.calculateDepositRate = calculateDepositRate;
|
|
285
|
+
function calculateBorrowRate(bank, delta = numericConstants_1.ZERO, currentUtilization = null) {
|
|
286
|
+
return calculateInterestRate(bank, delta, currentUtilization);
|
|
287
|
+
}
|
|
288
|
+
exports.calculateBorrowRate = calculateBorrowRate;
|
|
289
|
+
function calculateInterestAccumulated(bank, now) {
|
|
290
|
+
const interestRate = calculateInterestRate(bank);
|
|
291
|
+
const timeSinceLastUpdate = now.sub(bank.lastInterestTs);
|
|
292
|
+
const modifiedBorrowRate = interestRate.mul(timeSinceLastUpdate);
|
|
293
|
+
const utilization = calculateUtilization(bank);
|
|
294
|
+
const modifiedDepositRate = modifiedBorrowRate
|
|
295
|
+
.mul(utilization)
|
|
296
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION);
|
|
297
|
+
const borrowInterest = bank.cumulativeBorrowInterest
|
|
298
|
+
.mul(modifiedBorrowRate)
|
|
299
|
+
.div(numericConstants_1.ONE_YEAR)
|
|
300
|
+
.div(numericConstants_1.SPOT_MARKET_RATE_PRECISION)
|
|
301
|
+
.add(numericConstants_1.ONE);
|
|
302
|
+
const depositInterest = bank.cumulativeDepositInterest
|
|
303
|
+
.mul(modifiedDepositRate)
|
|
304
|
+
.div(numericConstants_1.ONE_YEAR)
|
|
305
|
+
.div(numericConstants_1.SPOT_MARKET_RATE_PRECISION);
|
|
306
|
+
return { borrowInterest, depositInterest };
|
|
307
|
+
}
|
|
308
|
+
exports.calculateInterestAccumulated = calculateInterestAccumulated;
|
|
309
|
+
function calculateTokenUtilizationLimits(depositTokenAmount, borrowTokenAmount, spotMarket) {
|
|
310
|
+
// Calculates the allowable minimum deposit and maximum borrow amounts for immediate withdrawal based on market utilization.
|
|
311
|
+
// First, it determines a maximum withdrawal utilization from the market's target and historic utilization.
|
|
312
|
+
// Then, it deduces corresponding deposit/borrow amounts.
|
|
313
|
+
// Note: For deposit sizes below the guard threshold, withdrawals aren't blocked.
|
|
314
|
+
const maxWithdrawUtilization = anchor_1.BN.max(new anchor_1.BN(spotMarket.optimalUtilization), spotMarket.utilizationTwap.add(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION.sub(spotMarket.utilizationTwap).div(new anchor_1.BN(2))));
|
|
315
|
+
let minDepositTokensForUtilization = borrowTokenAmount
|
|
316
|
+
.mul(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
317
|
+
.div(maxWithdrawUtilization);
|
|
318
|
+
// don't block withdraws for deposit sizes below guard threshold
|
|
319
|
+
minDepositTokensForUtilization = anchor_1.BN.min(minDepositTokensForUtilization, depositTokenAmount.sub(spotMarket.withdrawGuardThreshold));
|
|
320
|
+
let maxBorrowTokensForUtilization = maxWithdrawUtilization
|
|
321
|
+
.mul(depositTokenAmount)
|
|
322
|
+
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION);
|
|
323
|
+
maxBorrowTokensForUtilization = anchor_1.BN.max(spotMarket.withdrawGuardThreshold, maxBorrowTokensForUtilization);
|
|
324
|
+
return {
|
|
325
|
+
minDepositTokensForUtilization,
|
|
326
|
+
maxBorrowTokensForUtilization,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
exports.calculateTokenUtilizationLimits = calculateTokenUtilizationLimits;
|
|
330
|
+
function calculateWithdrawLimit(spotMarket, now) {
|
|
331
|
+
const marketDepositTokenAmount = getTokenAmount(spotMarket.depositBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
332
|
+
const marketBorrowTokenAmount = getTokenAmount(spotMarket.borrowBalance, spotMarket, types_1.SpotBalanceType.BORROW);
|
|
333
|
+
const twentyFourHours = new anchor_1.BN(60 * 60 * 24);
|
|
334
|
+
const sinceLast = now.sub(spotMarket.lastTwapTs);
|
|
335
|
+
const sinceStart = anchor_1.BN.max(numericConstants_1.ZERO, twentyFourHours.sub(sinceLast));
|
|
336
|
+
const borrowTokenTwapLive = spotMarket.borrowTokenTwap
|
|
337
|
+
.mul(sinceStart)
|
|
338
|
+
.add(marketBorrowTokenAmount.mul(sinceLast))
|
|
339
|
+
.div(sinceLast.add(sinceStart));
|
|
340
|
+
const depositTokenTwapLive = spotMarket.depositTokenTwap
|
|
341
|
+
.mul(sinceStart)
|
|
342
|
+
.add(marketDepositTokenAmount.mul(sinceLast))
|
|
343
|
+
.div(sinceLast.add(sinceStart));
|
|
344
|
+
const lesserDepositAmount = anchor_1.BN.min(marketDepositTokenAmount, depositTokenTwapLive);
|
|
345
|
+
const maxBorrowTokensTwap = anchor_1.BN.max(spotMarket.withdrawGuardThreshold, anchor_1.BN.min(anchor_1.BN.max(marketDepositTokenAmount.div(new anchor_1.BN(6)), borrowTokenTwapLive.add(lesserDepositAmount.div(new anchor_1.BN(10)))), lesserDepositAmount.sub(lesserDepositAmount.div(new anchor_1.BN(5))))); // between ~15-80% utilization with friction on twap
|
|
346
|
+
const minDepositTokensTwap = depositTokenTwapLive.sub(anchor_1.BN.max(depositTokenTwapLive.div(new anchor_1.BN(4)), anchor_1.BN.min(spotMarket.withdrawGuardThreshold, depositTokenTwapLive)));
|
|
347
|
+
const { minDepositTokensForUtilization, maxBorrowTokensForUtilization } = calculateTokenUtilizationLimits(marketDepositTokenAmount, marketBorrowTokenAmount, spotMarket);
|
|
348
|
+
const minDepositTokens = anchor_1.BN.max(minDepositTokensForUtilization, minDepositTokensTwap);
|
|
349
|
+
let maxBorrowTokens = anchor_1.BN.min(maxBorrowTokensForUtilization, maxBorrowTokensTwap);
|
|
350
|
+
const withdrawLimit = anchor_1.BN.max(marketDepositTokenAmount.sub(minDepositTokens), numericConstants_1.ZERO);
|
|
351
|
+
let borrowLimit = maxBorrowTokens.sub(marketBorrowTokenAmount);
|
|
352
|
+
borrowLimit = anchor_1.BN.min(borrowLimit, marketDepositTokenAmount.sub(marketBorrowTokenAmount));
|
|
353
|
+
if (spotMarket.maxTokenBorrowsFraction > 0) {
|
|
354
|
+
const maxTokenBorrowsByFraction = spotMarket.maxTokenDeposits
|
|
355
|
+
.mul(new anchor_1.BN(spotMarket.maxTokenBorrowsFraction))
|
|
356
|
+
.divn(10000);
|
|
357
|
+
const trueMaxBorrowTokensAvailable = maxTokenBorrowsByFraction.sub(marketBorrowTokenAmount);
|
|
358
|
+
maxBorrowTokens = anchor_1.BN.min(maxBorrowTokens, trueMaxBorrowTokensAvailable);
|
|
359
|
+
borrowLimit = anchor_1.BN.min(borrowLimit, maxBorrowTokens);
|
|
360
|
+
}
|
|
361
|
+
if (withdrawLimit.eq(numericConstants_1.ZERO)) {
|
|
362
|
+
borrowLimit = numericConstants_1.ZERO;
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
borrowLimit,
|
|
366
|
+
withdrawLimit,
|
|
367
|
+
maxBorrowAmount: maxBorrowTokens,
|
|
368
|
+
minDepositAmount: minDepositTokens,
|
|
369
|
+
currentDepositAmount: marketDepositTokenAmount,
|
|
370
|
+
currentBorrowAmount: marketBorrowTokenAmount,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
exports.calculateWithdrawLimit = calculateWithdrawLimit;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
3
|
+
import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
|
|
4
|
+
export declare function castNumberToSpotPrecision(value: number | BN, spotMarket: SpotMarketAccount): BN;
|
|
5
|
+
export declare function calculateSpotMarketMarginRatio(market: SpotMarketAccount, oraclePrice: BN, marginCategory: MarginCategory, size: BN, balanceType: SpotBalanceType, customMarginRatio?: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the maximum remaining deposit that can be made to the spot market. If the maxTokenDeposits on the market is zero then there is no limit and this function will also return zero. (so that needs to be checked)
|
|
8
|
+
* @param market
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateMaxRemainingDeposit(market: SpotMarketAccount): BN;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateMaxRemainingDeposit = exports.calculateSpotMarketMarginRatio = exports.castNumberToSpotPrecision = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const spotBalance_1 = require("./spotBalance");
|
|
7
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
function castNumberToSpotPrecision(value, spotMarket) {
|
|
10
|
+
if (typeof value === 'number') {
|
|
11
|
+
return (0, utils_1.numberToSafeBN)(value, new anchor_1.BN(Math.pow(10, spotMarket.decimals)));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return value.mul(new anchor_1.BN(Math.pow(10, spotMarket.decimals)));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.castNumberToSpotPrecision = castNumberToSpotPrecision;
|
|
18
|
+
function calculateSpotMarketMarginRatio(market, oraclePrice, marginCategory, size, balanceType, customMarginRatio = 0) {
|
|
19
|
+
let marginRatio;
|
|
20
|
+
if ((0, types_1.isVariant)(balanceType, 'deposit')) {
|
|
21
|
+
const assetWeight = (0, spotBalance_1.calculateAssetWeight)(size, oraclePrice, market, marginCategory);
|
|
22
|
+
marginRatio = numericConstants_1.MARGIN_PRECISION.sub(assetWeight).toNumber();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const liabilityWeight = (0, spotBalance_1.calculateLiabilityWeight)(size, market, marginCategory);
|
|
26
|
+
marginRatio = liabilityWeight.sub(numericConstants_1.MARGIN_PRECISION).toNumber();
|
|
27
|
+
}
|
|
28
|
+
if (marginCategory === 'Initial') {
|
|
29
|
+
// use lowest leverage between max allowed and optional user custom max
|
|
30
|
+
return Math.max(marginRatio, customMarginRatio);
|
|
31
|
+
}
|
|
32
|
+
return marginRatio;
|
|
33
|
+
}
|
|
34
|
+
exports.calculateSpotMarketMarginRatio = calculateSpotMarketMarginRatio;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the maximum remaining deposit that can be made to the spot market. If the maxTokenDeposits on the market is zero then there is no limit and this function will also return zero. (so that needs to be checked)
|
|
37
|
+
* @param market
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
function calculateMaxRemainingDeposit(market) {
|
|
41
|
+
const marketMaxTokenDeposits = market.maxTokenDeposits;
|
|
42
|
+
if (marketMaxTokenDeposits.eq(numericConstants_1.ZERO)) {
|
|
43
|
+
// If the maxTokenDeposits is set to zero then that means there is no limit. Return the largest number we can to represent infinite available deposit.
|
|
44
|
+
return numericConstants_1.ZERO;
|
|
45
|
+
}
|
|
46
|
+
const totalDepositsTokenAmount = (0, spotBalance_1.getTokenAmount)(market.depositBalance, market, types_1.SpotBalanceType.DEPOSIT);
|
|
47
|
+
return marketMaxTokenDeposits.sub(totalDepositsTokenAmount);
|
|
48
|
+
}
|
|
49
|
+
exports.calculateMaxRemainingDeposit = calculateMaxRemainingDeposit;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { MarginCategory, SpotMarketAccount, SpotPosition } from '../types';
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
|
+
import { StrictOraclePrice } from '../oracles/strictOraclePrice';
|
|
5
|
+
export declare function isSpotPositionAvailable(position: SpotPosition): boolean;
|
|
6
|
+
export type OrderFillSimulation = {
|
|
7
|
+
tokenAmount: BN;
|
|
8
|
+
ordersValue: BN;
|
|
9
|
+
tokenValue: BN;
|
|
10
|
+
weight: BN;
|
|
11
|
+
weightedTokenValue: BN;
|
|
12
|
+
freeCollateralContribution: any;
|
|
13
|
+
};
|
|
14
|
+
export declare function getWorstCaseTokenAmounts(spotPosition: SpotPosition, spotMarketAccount: SpotMarketAccount, strictOraclePrice: StrictOraclePrice, marginCategory: MarginCategory, customMarginRatio?: number): OrderFillSimulation;
|
|
15
|
+
export declare function calculateWeightedTokenValue(tokenAmount: BN, tokenValue: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory, customMarginRatio?: number): {
|
|
16
|
+
weight: BN;
|
|
17
|
+
weightedTokenValue: BN;
|
|
18
|
+
};
|
|
19
|
+
export declare function simulateOrderFill(tokenAmount: BN, tokenValue: BN, openOrders: BN, strictOraclePrice: StrictOraclePrice, spotMarket: SpotMarketAccount, marginCategory: MarginCategory, customMarginRatio?: number): OrderFillSimulation;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simulateOrderFill = exports.calculateWeightedTokenValue = exports.getWorstCaseTokenAmounts = exports.isSpotPositionAvailable = void 0;
|
|
4
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
|
+
const spotBalance_1 = require("./spotBalance");
|
|
7
|
+
function isSpotPositionAvailable(position) {
|
|
8
|
+
return position.scaledBalance.eq(numericConstants_1.ZERO) && position.openOrders === 0;
|
|
9
|
+
}
|
|
10
|
+
exports.isSpotPositionAvailable = isSpotPositionAvailable;
|
|
11
|
+
function getWorstCaseTokenAmounts(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, customMarginRatio) {
|
|
12
|
+
const tokenAmount = (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType), spotPosition.balanceType);
|
|
13
|
+
const tokenValue = (0, spotBalance_1.getStrictTokenValue)(tokenAmount, spotMarketAccount.decimals, strictOraclePrice);
|
|
14
|
+
if (spotPosition.openBids.eq(numericConstants_1.ZERO) && spotPosition.openAsks.eq(numericConstants_1.ZERO)) {
|
|
15
|
+
const { weight, weightedTokenValue } = calculateWeightedTokenValue(tokenAmount, tokenValue, strictOraclePrice.current, spotMarketAccount, marginCategory, customMarginRatio);
|
|
16
|
+
return {
|
|
17
|
+
tokenAmount,
|
|
18
|
+
ordersValue: numericConstants_1.ZERO,
|
|
19
|
+
tokenValue,
|
|
20
|
+
weight,
|
|
21
|
+
weightedTokenValue,
|
|
22
|
+
freeCollateralContribution: weightedTokenValue,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const bidsSimulation = simulateOrderFill(tokenAmount, tokenValue, spotPosition.openBids, strictOraclePrice, spotMarketAccount, marginCategory, customMarginRatio);
|
|
26
|
+
const asksSimulation = simulateOrderFill(tokenAmount, tokenValue, spotPosition.openAsks, strictOraclePrice, spotMarketAccount, marginCategory, customMarginRatio);
|
|
27
|
+
if (asksSimulation.freeCollateralContribution.lt(bidsSimulation.freeCollateralContribution)) {
|
|
28
|
+
return asksSimulation;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return bidsSimulation;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.getWorstCaseTokenAmounts = getWorstCaseTokenAmounts;
|
|
35
|
+
function calculateWeightedTokenValue(tokenAmount, tokenValue, oraclePrice, spotMarket, marginCategory, customMarginRatio) {
|
|
36
|
+
let weight;
|
|
37
|
+
if (tokenValue.gte(numericConstants_1.ZERO)) {
|
|
38
|
+
weight = (0, spotBalance_1.calculateAssetWeight)(tokenAmount, oraclePrice, spotMarket, marginCategory);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
weight = (0, spotBalance_1.calculateLiabilityWeight)(tokenAmount.abs(), spotMarket, marginCategory);
|
|
42
|
+
}
|
|
43
|
+
if (marginCategory === 'Initial' &&
|
|
44
|
+
customMarginRatio &&
|
|
45
|
+
spotMarket.marketIndex !== numericConstants_1.QUOTE_SPOT_MARKET_INDEX) {
|
|
46
|
+
const userCustomAssetWeight = tokenValue.gte(numericConstants_1.ZERO)
|
|
47
|
+
? anchor_1.BN.max(numericConstants_1.ZERO, numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION.subn(customMarginRatio))
|
|
48
|
+
: numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION.addn(customMarginRatio);
|
|
49
|
+
weight = tokenValue.gte(numericConstants_1.ZERO)
|
|
50
|
+
? anchor_1.BN.min(weight, userCustomAssetWeight)
|
|
51
|
+
: anchor_1.BN.max(weight, userCustomAssetWeight);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
weight: weight,
|
|
55
|
+
weightedTokenValue: tokenValue
|
|
56
|
+
.mul(weight)
|
|
57
|
+
.div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.calculateWeightedTokenValue = calculateWeightedTokenValue;
|
|
61
|
+
function simulateOrderFill(tokenAmount, tokenValue, openOrders, strictOraclePrice, spotMarket, marginCategory, customMarginRatio) {
|
|
62
|
+
const ordersValue = (0, spotBalance_1.getTokenValue)(openOrders.neg(), spotMarket.decimals, {
|
|
63
|
+
price: strictOraclePrice.max(),
|
|
64
|
+
});
|
|
65
|
+
const tokenAmountAfterFill = tokenAmount.add(openOrders);
|
|
66
|
+
const tokenValueAfterFill = tokenValue.add(ordersValue.neg());
|
|
67
|
+
const { weight, weightedTokenValue: weightedTokenValueAfterFill } = calculateWeightedTokenValue(tokenAmountAfterFill, tokenValueAfterFill, strictOraclePrice.current, spotMarket, marginCategory, customMarginRatio);
|
|
68
|
+
const freeCollateralContribution = weightedTokenValueAfterFill.add(ordersValue);
|
|
69
|
+
return {
|
|
70
|
+
tokenAmount: tokenAmountAfterFill,
|
|
71
|
+
ordersValue: ordersValue,
|
|
72
|
+
tokenValue: tokenValueAfterFill,
|
|
73
|
+
weight,
|
|
74
|
+
weightedTokenValue: weightedTokenValueAfterFill,
|
|
75
|
+
freeCollateralContribution,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.simulateOrderFill = simulateOrderFill;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaxNumberOfSubAccounts = exports.calculateInitUserFee = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
function calculateInitUserFee(stateAccount) {
|
|
6
|
+
const maxInitFee = new __1.BN(stateAccount.maxInitializeUserFee)
|
|
7
|
+
.mul(__1.LAMPORTS_PRECISION)
|
|
8
|
+
.divn(100);
|
|
9
|
+
const targetUtilization = __1.PERCENTAGE_PRECISION.muln(8).divn(10);
|
|
10
|
+
const accountSpaceUtilization = stateAccount.numberOfSubAccounts
|
|
11
|
+
.addn(1)
|
|
12
|
+
.mul(__1.PERCENTAGE_PRECISION)
|
|
13
|
+
.div(getMaxNumberOfSubAccounts(stateAccount));
|
|
14
|
+
if (accountSpaceUtilization.gt(targetUtilization)) {
|
|
15
|
+
return maxInitFee
|
|
16
|
+
.mul(accountSpaceUtilization.sub(targetUtilization))
|
|
17
|
+
.div(__1.PERCENTAGE_PRECISION.sub(targetUtilization));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return __1.ZERO;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.calculateInitUserFee = calculateInitUserFee;
|
|
24
|
+
function getMaxNumberOfSubAccounts(stateAccount) {
|
|
25
|
+
if (stateAccount.maxNumberOfSubAccounts <= 5) {
|
|
26
|
+
return new __1.BN(stateAccount.maxNumberOfSubAccounts);
|
|
27
|
+
}
|
|
28
|
+
return new __1.BN(stateAccount.maxNumberOfSubAccounts).muln(100);
|
|
29
|
+
}
|
|
30
|
+
exports.getMaxNumberOfSubAccounts = getMaxNumberOfSubAccounts;
|