@drift-labs/sdk-browser 2.163.0-beta.11 → 2.163.0-beta.13
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.lock +26 -13
- package/lib/browser/accounts/fetch.d.ts +9 -0
- package/lib/browser/accounts/fetch.js +14 -1
- package/lib/browser/addresses/pda.d.ts +1 -1
- package/lib/browser/addresses/pda.js +2 -2
- package/lib/browser/adminClient.d.ts +1 -1
- package/lib/browser/adminClient.js +2 -2
- package/lib/browser/bankrun/bankrunConnection.d.ts +1 -1
- package/lib/browser/bankrun/bankrunConnection.js +1 -1
- package/lib/browser/clock/clockSubscriber.js +1 -1
- package/lib/browser/config.d.ts +1 -1
- package/lib/browser/constants/numericConstants.d.ts +1 -1
- package/lib/browser/constants/numericConstants.js +1 -1
- package/lib/browser/constants/perpMarkets.js +1 -1
- package/lib/browser/constants/spotMarkets.d.ts +1 -1
- package/lib/browser/constants/spotMarkets.js +4 -3
- package/lib/browser/core/DriftCore.d.ts +224 -0
- package/lib/browser/core/DriftCore.js +138 -0
- package/lib/browser/core/index.d.ts +12 -0
- package/lib/browser/core/index.js +28 -0
- package/lib/browser/core/instructions/deposit.d.ts +19 -0
- package/lib/browser/core/instructions/deposit.js +19 -0
- package/lib/browser/core/instructions/fill.d.ts +13 -0
- package/lib/browser/core/instructions/fill.js +17 -0
- package/lib/browser/core/instructions/funding.d.ts +9 -0
- package/lib/browser/core/instructions/funding.js +13 -0
- package/lib/browser/core/instructions/liquidation.d.ts +15 -0
- package/lib/browser/core/instructions/liquidation.js +17 -0
- package/lib/browser/core/instructions/orders.d.ts +22 -0
- package/lib/browser/core/instructions/orders.js +27 -0
- package/lib/browser/core/instructions/perpOrders.d.ts +78 -0
- package/lib/browser/core/instructions/perpOrders.js +99 -0
- package/lib/browser/core/instructions/settlement.d.ts +11 -0
- package/lib/browser/core/instructions/settlement.js +15 -0
- package/lib/browser/core/instructions/trigger.d.ts +11 -0
- package/lib/browser/core/instructions/trigger.js +15 -0
- package/lib/browser/core/instructions/withdraw.d.ts +20 -0
- package/lib/browser/core/instructions/withdraw.js +20 -0
- package/lib/browser/core/remainingAccounts.d.ts +27 -0
- package/lib/browser/core/remainingAccounts.js +122 -0
- package/lib/browser/core/signedMsg.d.ts +17 -0
- package/lib/browser/core/signedMsg.js +39 -0
- package/lib/browser/decode/customCoder.d.ts +1 -1
- package/lib/browser/decode/customCoder.js +1 -1
- package/lib/browser/decode/user.js +1 -1
- package/lib/browser/dlob/DLOB.d.ts +1 -1
- package/lib/browser/dlob/DLOB.js +1 -1
- package/lib/browser/dlob/DLOBNode.d.ts +1 -1
- package/lib/browser/dlob/DLOBNode.js +1 -1
- package/lib/browser/dlob/DLOBSubscriber.d.ts +1 -1
- package/lib/browser/dlob/NodeList.d.ts +1 -1
- package/lib/browser/dlob/orderBookLevels.d.ts +1 -1
- package/lib/browser/dlob/orderBookLevels.js +1 -1
- package/lib/browser/driftClient.d.ts +17 -24
- package/lib/browser/driftClient.js +192 -291
- package/lib/browser/driftClientConfig.d.ts +1 -1
- package/lib/browser/events/eventSubscriber.d.ts +1 -1
- package/lib/browser/events/fetchLogs.d.ts +1 -1
- package/lib/browser/events/parse.d.ts +1 -1
- package/lib/browser/factory/bigNum.d.ts +1 -1
- package/lib/browser/factory/bigNum.js +1 -1
- package/lib/browser/factory/oracleClient.js +1 -1
- package/lib/browser/index.d.ts +2 -1
- package/lib/browser/index.js +2 -1
- package/lib/browser/indicative-quotes/indicativeQuotesSender.d.ts +1 -1
- package/lib/browser/isomorphic/anchor.browser.d.ts +24 -0
- package/lib/browser/isomorphic/anchor.browser.js +60 -0
- package/lib/browser/isomorphic/anchor.d.ts +24 -0
- package/lib/browser/isomorphic/anchor.js +60 -0
- package/lib/browser/isomorphic/anchor29.browser.d.ts +12 -0
- package/lib/browser/isomorphic/anchor29.browser.js +48 -0
- package/lib/browser/isomorphic/anchor29.d.ts +12 -0
- package/lib/browser/isomorphic/anchor29.js +48 -0
- package/lib/browser/jupiter/jupiterClient.d.ts +1 -1
- package/lib/browser/marginCalculation.d.ts +1 -1
- package/lib/browser/marinade/index.d.ts +1 -1
- package/lib/browser/marinade/index.js +2 -2
- package/lib/browser/math/amm.d.ts +1 -1
- package/lib/browser/math/amm.js +1 -1
- package/lib/browser/math/auction.d.ts +1 -1
- package/lib/browser/math/auction.js +1 -1
- package/lib/browser/math/conversion.d.ts +1 -1
- package/lib/browser/math/conversion.js +1 -1
- package/lib/browser/math/exchangeStatus.js +1 -1
- package/lib/browser/math/fuel.d.ts +1 -1
- package/lib/browser/math/fuel.js +1 -1
- package/lib/browser/math/funding.d.ts +1 -1
- package/lib/browser/math/funding.js +1 -1
- package/lib/browser/math/insurance.d.ts +1 -1
- package/lib/browser/math/insurance.js +1 -1
- package/lib/browser/math/liquidation.d.ts +1 -1
- package/lib/browser/math/liquidation.js +1 -1
- package/lib/browser/math/margin.d.ts +1 -1
- package/lib/browser/math/margin.js +1 -1
- package/lib/browser/math/market.d.ts +1 -1
- package/lib/browser/math/market.js +1 -1
- package/lib/browser/math/oracles.d.ts +1 -1
- package/lib/browser/math/oracles.js +1 -1
- package/lib/browser/math/orders.d.ts +1 -1
- package/lib/browser/math/orders.js +1 -1
- package/lib/browser/math/position.d.ts +1 -1
- package/lib/browser/math/position.js +1 -1
- package/lib/browser/math/protectedMakerParams.js +1 -1
- package/lib/browser/math/repeg.d.ts +1 -1
- package/lib/browser/math/repeg.js +1 -1
- package/lib/browser/math/spotBalance.d.ts +1 -1
- package/lib/browser/math/spotBalance.js +1 -1
- package/lib/browser/math/spotMarket.d.ts +1 -1
- package/lib/browser/math/spotMarket.js +1 -1
- package/lib/browser/math/spotPosition.d.ts +1 -1
- package/lib/browser/math/spotPosition.js +1 -1
- package/lib/browser/math/state.d.ts +1 -1
- package/lib/browser/math/state.js +1 -1
- package/lib/browser/math/superStake.d.ts +1 -1
- package/lib/browser/math/superStake.js +1 -1
- package/lib/browser/math/trade.d.ts +1 -1
- package/lib/browser/math/trade.js +1 -1
- package/lib/browser/math/utils.d.ts +1 -1
- package/lib/browser/math/utils.js +1 -1
- package/lib/browser/memcmp.js +8 -8
- package/lib/browser/openbook/openbookV2Subscriber.d.ts +1 -1
- package/lib/browser/openbook/openbookV2Subscriber.js +3 -3
- package/lib/browser/oracles/pythClient.d.ts +1 -1
- package/lib/browser/oracles/pythClient.js +1 -1
- package/lib/browser/oracles/pythLazerClient.d.ts +1 -1
- package/lib/browser/oracles/pythLazerClient.js +1 -1
- package/lib/browser/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/browser/oracles/strictOraclePrice.d.ts +1 -1
- package/lib/browser/oracles/strictOraclePrice.js +1 -1
- package/lib/browser/oracles/types.d.ts +1 -1
- package/lib/browser/oracles/utils.d.ts +1 -1
- package/lib/browser/orderParams.d.ts +1 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.js +1 -1
- package/lib/browser/phoenix/phoenixSubscriber.d.ts +1 -1
- package/lib/browser/phoenix/phoenixSubscriber.js +1 -1
- package/lib/browser/pyth/types.d.ts +1 -1
- package/lib/browser/serum/serumSubscriber.d.ts +1 -1
- package/lib/browser/serum/serumSubscriber.js +1 -1
- package/lib/browser/slot/SlothashSubscriber.js +6 -3
- package/lib/browser/swap/UnifiedSwapClient.d.ts +1 -1
- package/lib/browser/titan/titanClient.d.ts +1 -1
- package/lib/browser/tokenFaucet.d.ts +3 -3
- package/lib/browser/tokenFaucet.js +4 -4
- package/lib/browser/types.d.ts +1 -1
- package/lib/browser/user.d.ts +1 -1
- package/lib/browser/user.js +1 -1
- package/lib/browser/userMap/referrerMap.js +7 -4
- package/lib/browser/userStats.d.ts +1 -1
- package/lib/browser/userStats.js +1 -1
- package/lib/node/accounts/fetch.d.ts +9 -0
- package/lib/node/accounts/fetch.d.ts.map +1 -1
- package/lib/node/accounts/fetch.js +14 -1
- package/lib/node/addresses/pda.d.ts +1 -1
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +2 -2
- package/lib/node/adminClient.d.ts +1 -1
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +2 -2
- package/lib/node/bankrun/bankrunConnection.d.ts +1 -1
- package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.js +1 -1
- package/lib/node/clock/clockSubscriber.js +1 -1
- package/lib/node/config.d.ts +1 -1
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.d.ts +1 -1
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +1 -1
- package/lib/node/constants/perpMarkets.js +1 -1
- package/lib/node/constants/spotMarkets.d.ts +1 -1
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/constants/spotMarkets.js +4 -3
- package/lib/node/core/DriftCore.d.ts +225 -0
- package/lib/node/core/DriftCore.d.ts.map +1 -0
- package/lib/node/core/DriftCore.js +138 -0
- package/lib/node/core/index.d.ts +13 -0
- package/lib/node/core/index.d.ts.map +1 -0
- package/lib/node/core/index.js +28 -0
- package/lib/node/core/instructions/deposit.d.ts +20 -0
- package/lib/node/core/instructions/deposit.d.ts.map +1 -0
- package/lib/node/core/instructions/deposit.js +19 -0
- package/lib/node/core/instructions/fill.d.ts +14 -0
- package/lib/node/core/instructions/fill.d.ts.map +1 -0
- package/lib/node/core/instructions/fill.js +17 -0
- package/lib/node/core/instructions/funding.d.ts +10 -0
- package/lib/node/core/instructions/funding.d.ts.map +1 -0
- package/lib/node/core/instructions/funding.js +13 -0
- package/lib/node/core/instructions/liquidation.d.ts +16 -0
- package/lib/node/core/instructions/liquidation.d.ts.map +1 -0
- package/lib/node/core/instructions/liquidation.js +17 -0
- package/lib/node/core/instructions/orders.d.ts +23 -0
- package/lib/node/core/instructions/orders.d.ts.map +1 -0
- package/lib/node/core/instructions/orders.js +27 -0
- package/lib/node/core/instructions/perpOrders.d.ts +79 -0
- package/lib/node/core/instructions/perpOrders.d.ts.map +1 -0
- package/lib/node/core/instructions/perpOrders.js +99 -0
- package/lib/node/core/instructions/settlement.d.ts +12 -0
- package/lib/node/core/instructions/settlement.d.ts.map +1 -0
- package/lib/node/core/instructions/settlement.js +15 -0
- package/lib/node/core/instructions/trigger.d.ts +12 -0
- package/lib/node/core/instructions/trigger.d.ts.map +1 -0
- package/lib/node/core/instructions/trigger.js +15 -0
- package/lib/node/core/instructions/withdraw.d.ts +21 -0
- package/lib/node/core/instructions/withdraw.d.ts.map +1 -0
- package/lib/node/core/instructions/withdraw.js +20 -0
- package/lib/node/core/remainingAccounts.d.ts +28 -0
- package/lib/node/core/remainingAccounts.d.ts.map +1 -0
- package/lib/node/core/remainingAccounts.js +122 -0
- package/lib/node/core/signedMsg.d.ts +18 -0
- package/lib/node/core/signedMsg.d.ts.map +1 -0
- package/lib/node/core/signedMsg.js +39 -0
- package/lib/node/decode/customCoder.d.ts +1 -1
- package/lib/node/decode/customCoder.d.ts.map +1 -1
- package/lib/node/decode/customCoder.js +1 -1
- package/lib/node/decode/user.js +1 -1
- package/lib/node/dlob/DLOB.d.ts +1 -1
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +1 -1
- package/lib/node/dlob/DLOBNode.d.ts +1 -1
- package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
- package/lib/node/dlob/DLOBNode.js +1 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts +1 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/NodeList.d.ts +1 -1
- package/lib/node/dlob/NodeList.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.d.ts +1 -1
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +1 -1
- package/lib/node/driftClient.d.ts +17 -24
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +192 -291
- package/lib/node/driftClientConfig.d.ts +1 -1
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.d.ts +1 -1
- package/lib/node/events/eventSubscriber.d.ts.map +1 -1
- package/lib/node/events/fetchLogs.d.ts +1 -1
- package/lib/node/events/fetchLogs.d.ts.map +1 -1
- package/lib/node/events/parse.d.ts +1 -1
- package/lib/node/events/parse.d.ts.map +1 -1
- package/lib/node/factory/bigNum.d.ts +1 -1
- package/lib/node/factory/bigNum.d.ts.map +1 -1
- package/lib/node/factory/bigNum.js +1 -1
- package/lib/node/factory/oracleClient.js +1 -1
- package/lib/node/index.d.ts +2 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -1
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts +1 -1
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts.map +1 -1
- package/lib/node/isomorphic/anchor.browser.d.ts +25 -0
- package/lib/node/isomorphic/anchor.browser.d.ts.map +1 -0
- package/lib/node/isomorphic/anchor.browser.js +60 -0
- package/lib/node/isomorphic/anchor.d.ts +25 -0
- package/lib/node/isomorphic/anchor.d.ts.map +1 -0
- package/lib/node/isomorphic/anchor.js +60 -0
- package/lib/node/isomorphic/anchor.node.d.ts.map +1 -0
- package/lib/node/isomorphic/anchor29.browser.d.ts +13 -0
- package/lib/node/isomorphic/anchor29.browser.d.ts.map +1 -0
- package/lib/node/isomorphic/anchor29.browser.js +48 -0
- package/lib/node/isomorphic/anchor29.d.ts +13 -0
- package/lib/node/isomorphic/anchor29.d.ts.map +1 -0
- package/lib/node/isomorphic/anchor29.js +48 -0
- package/lib/node/isomorphic/anchor29.node.d.ts.map +1 -0
- package/lib/node/jupiter/jupiterClient.d.ts +1 -1
- package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
- package/lib/node/marginCalculation.d.ts +1 -1
- package/lib/node/marginCalculation.d.ts.map +1 -1
- package/lib/node/marinade/index.d.ts +1 -1
- package/lib/node/marinade/index.d.ts.map +1 -1
- package/lib/node/marinade/index.js +2 -2
- package/lib/node/math/amm.d.ts +1 -1
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +1 -1
- package/lib/node/math/auction.d.ts +1 -1
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +1 -1
- package/lib/node/math/conversion.d.ts +1 -1
- package/lib/node/math/conversion.d.ts.map +1 -1
- package/lib/node/math/conversion.js +1 -1
- package/lib/node/math/exchangeStatus.js +1 -1
- package/lib/node/math/fuel.d.ts +1 -1
- package/lib/node/math/fuel.d.ts.map +1 -1
- package/lib/node/math/fuel.js +1 -1
- package/lib/node/math/funding.d.ts +1 -1
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +1 -1
- package/lib/node/math/insurance.d.ts +1 -1
- package/lib/node/math/insurance.d.ts.map +1 -1
- package/lib/node/math/insurance.js +1 -1
- package/lib/node/math/liquidation.d.ts +1 -1
- package/lib/node/math/liquidation.d.ts.map +1 -1
- package/lib/node/math/liquidation.js +1 -1
- package/lib/node/math/margin.d.ts +1 -1
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +1 -1
- package/lib/node/math/market.d.ts +1 -1
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +1 -1
- package/lib/node/math/oracles.d.ts +1 -1
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +1 -1
- package/lib/node/math/orders.d.ts +1 -1
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +1 -1
- package/lib/node/math/position.d.ts +1 -1
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +1 -1
- package/lib/node/math/protectedMakerParams.js +1 -1
- package/lib/node/math/repeg.d.ts +1 -1
- package/lib/node/math/repeg.d.ts.map +1 -1
- package/lib/node/math/repeg.js +1 -1
- package/lib/node/math/spotBalance.d.ts +1 -1
- package/lib/node/math/spotBalance.d.ts.map +1 -1
- package/lib/node/math/spotBalance.js +1 -1
- package/lib/node/math/spotMarket.d.ts +1 -1
- package/lib/node/math/spotMarket.d.ts.map +1 -1
- package/lib/node/math/spotMarket.js +1 -1
- package/lib/node/math/spotPosition.d.ts +1 -1
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/spotPosition.js +1 -1
- package/lib/node/math/state.d.ts +1 -1
- package/lib/node/math/state.d.ts.map +1 -1
- package/lib/node/math/state.js +1 -1
- package/lib/node/math/superStake.d.ts +1 -1
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +1 -1
- package/lib/node/math/trade.d.ts +1 -1
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +1 -1
- package/lib/node/math/utils.d.ts +1 -1
- package/lib/node/math/utils.d.ts.map +1 -1
- package/lib/node/math/utils.js +1 -1
- package/lib/node/memcmp.js +8 -8
- package/lib/node/openbook/openbookV2Subscriber.d.ts +1 -1
- package/lib/node/openbook/openbookV2Subscriber.d.ts.map +1 -1
- package/lib/node/openbook/openbookV2Subscriber.js +3 -3
- package/lib/node/oracles/pythClient.d.ts +1 -1
- package/lib/node/oracles/pythClient.d.ts.map +1 -1
- package/lib/node/oracles/pythClient.js +1 -1
- package/lib/node/oracles/pythLazerClient.d.ts +1 -1
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.js +1 -1
- package/lib/node/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/node/oracles/strictOraclePrice.d.ts +1 -1
- package/lib/node/oracles/strictOraclePrice.d.ts.map +1 -1
- package/lib/node/oracles/strictOraclePrice.js +1 -1
- package/lib/node/oracles/types.d.ts +1 -1
- package/lib/node/oracles/types.d.ts.map +1 -1
- package/lib/node/oracles/utils.d.ts +1 -1
- package/lib/node/oracles/utils.d.ts.map +1 -1
- package/lib/node/orderParams.d.ts +1 -1
- package/lib/node/orderParams.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +1 -1
- package/lib/node/phoenix/phoenixSubscriber.d.ts +1 -1
- package/lib/node/phoenix/phoenixSubscriber.d.ts.map +1 -1
- package/lib/node/phoenix/phoenixSubscriber.js +1 -1
- package/lib/node/pyth/types.d.ts +1 -1
- package/lib/node/pyth/types.d.ts.map +1 -1
- package/lib/node/serum/serumSubscriber.d.ts +1 -1
- package/lib/node/serum/serumSubscriber.d.ts.map +1 -1
- package/lib/node/serum/serumSubscriber.js +1 -1
- package/lib/node/slot/SlothashSubscriber.js +6 -3
- package/lib/node/swap/UnifiedSwapClient.d.ts +1 -1
- package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
- package/lib/node/titan/titanClient.d.ts +1 -1
- package/lib/node/titan/titanClient.d.ts.map +1 -1
- package/lib/node/tokenFaucet.d.ts +3 -3
- package/lib/node/tokenFaucet.d.ts.map +1 -1
- package/lib/node/tokenFaucet.js +4 -4
- package/lib/node/types.d.ts +1 -1
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +1 -1
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +1 -1
- package/lib/node/userMap/referrerMap.js +7 -4
- package/lib/node/userStats.d.ts +1 -1
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +1 -1
- package/package.json +4 -2
- package/scripts/postbuild.js +1 -1
- package/src/accounts/fetch.ts +27 -0
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketAccountSubscriberV2.ts +1 -1
- package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +1 -1
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +1 -1
- package/src/addresses/pda.ts +2 -2
- package/src/adminClient.ts +2 -2
- package/src/bankrun/bankrunConnection.ts +1 -1
- package/src/clock/clockSubscriber.ts +1 -1
- package/src/config.ts +1 -1
- package/src/constants/numericConstants.ts +1 -1
- package/src/constants/perpMarkets.ts +1 -1
- package/src/constants/spotMarkets.ts +4 -3
- package/src/core/DriftCore.ts +326 -0
- package/src/core/index.ts +12 -0
- package/src/core/instructions/deposit.ts +42 -0
- package/src/core/instructions/fill.ts +34 -0
- package/src/core/instructions/funding.ts +21 -0
- package/src/core/instructions/liquidation.ts +37 -0
- package/src/core/instructions/orders.ts +56 -0
- package/src/core/instructions/perpOrders.ts +192 -0
- package/src/core/instructions/settlement.ts +26 -0
- package/src/core/instructions/trigger.ts +26 -0
- package/src/core/instructions/withdraw.ts +44 -0
- package/src/core/remainingAccounts.ts +276 -0
- package/src/core/signedMsg.ts +71 -0
- package/src/decode/customCoder.ts +1 -1
- package/src/decode/user.ts +1 -1
- package/src/dlob/DLOB.ts +1 -1
- package/src/dlob/DLOBNode.ts +1 -1
- package/src/dlob/DLOBSubscriber.ts +1 -1
- package/src/dlob/NodeList.ts +1 -1
- package/src/dlob/orderBookLevels.ts +1 -1
- package/src/driftClient.ts +207 -402
- package/src/driftClientConfig.ts +1 -1
- package/src/events/eventSubscriber.ts +1 -1
- package/src/events/fetchLogs.ts +1 -1
- package/src/events/parse.ts +1 -1
- package/src/factory/bigNum.ts +1 -1
- package/src/factory/oracleClient.ts +1 -1
- package/src/index.ts +2 -1
- package/src/indicative-quotes/indicativeQuotesSender.ts +1 -1
- package/src/isomorphic/anchor.browser.ts +44 -0
- package/src/isomorphic/anchor.node.ts +1 -0
- package/src/isomorphic/anchor.ts +1 -0
- package/src/isomorphic/anchor29.browser.ts +24 -0
- package/src/isomorphic/anchor29.node.ts +1 -0
- package/src/isomorphic/anchor29.ts +1 -0
- package/src/jupiter/jupiterClient.ts +1 -1
- package/src/marginCalculation.ts +1 -1
- package/src/marinade/index.ts +1 -1
- package/src/math/amm.ts +1 -1
- package/src/math/auction.ts +1 -1
- package/src/math/conversion.ts +1 -1
- package/src/math/exchangeStatus.ts +1 -1
- package/src/math/fuel.ts +1 -1
- package/src/math/funding.ts +1 -1
- package/src/math/insurance.ts +1 -1
- package/src/math/liquidation.ts +1 -1
- package/src/math/margin.ts +1 -1
- package/src/math/market.ts +1 -1
- package/src/math/oracles.ts +1 -1
- package/src/math/orders.ts +1 -1
- package/src/math/position.ts +1 -1
- package/src/math/protectedMakerParams.ts +1 -1
- package/src/math/repeg.ts +1 -1
- package/src/math/spotBalance.ts +1 -1
- package/src/math/spotMarket.ts +1 -1
- package/src/math/spotPosition.ts +1 -1
- package/src/math/state.ts +1 -1
- package/src/math/superStake.ts +1 -1
- package/src/math/trade.ts +1 -1
- package/src/math/utils.ts +1 -1
- package/src/memcmp.ts +1 -1
- package/src/openbook/openbookV2Subscriber.ts +7 -1
- package/src/oracles/pythClient.ts +1 -1
- package/src/oracles/pythLazerClient.ts +1 -1
- package/src/oracles/quoteAssetOracleClient.ts +1 -1
- package/src/oracles/strictOraclePrice.ts +1 -1
- package/src/oracles/types.ts +1 -1
- package/src/oracles/utils.ts +1 -1
- package/src/orderParams.ts +1 -1
- package/src/orderSubscriber/OrderSubscriber.ts +1 -1
- package/src/phoenix/phoenixSubscriber.ts +1 -1
- package/src/pyth/types.ts +1 -1
- package/src/serum/serumSubscriber.ts +1 -1
- package/src/slot/SlothashSubscriber.ts +2 -2
- package/src/swap/UnifiedSwapClient.ts +1 -1
- package/src/titan/titanClient.ts +1 -1
- package/src/tokenFaucet.ts +3 -3
- package/src/types.ts +1 -1
- package/src/user.ts +1 -1
- package/src/userMap/referrerMap.ts +1 -1
- package/src/userMap/userMap.ts +1 -1
- package/src/userStats.ts +1 -1
- package/tests/DriftCore/decode.test.ts +16 -0
- package/tests/DriftCore/fill_trigger.test.ts +73 -0
- package/tests/DriftCore/instructions.test.ts +46 -0
- package/tests/DriftCore/pdas.test.ts +29 -0
- package/tests/DriftCore/perp_orders.test.ts +205 -0
- package/tests/DriftCore/remainingAccounts.test.ts +70 -0
- package/tests/DriftCore/settlement_liquidation.test.ts +69 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { Keypair } from '@solana/web3.js';
|
|
3
|
+
import { DriftCore } from '../../src/core/DriftCore';
|
|
4
|
+
|
|
5
|
+
describe('DriftCore fill/trigger builders', () => {
|
|
6
|
+
test('buildFillPerpOrderInstruction wires accounts + args', async () => {
|
|
7
|
+
const called: any[] = [];
|
|
8
|
+
const fakeIx = {
|
|
9
|
+
keys: [],
|
|
10
|
+
programId: Keypair.generate().publicKey,
|
|
11
|
+
data: Buffer.alloc(0),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const program = {
|
|
15
|
+
instruction: {
|
|
16
|
+
fillPerpOrder: async (...args: any[]) => {
|
|
17
|
+
called.push(args);
|
|
18
|
+
return fakeIx;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const pk = () => Keypair.generate().publicKey;
|
|
23
|
+
|
|
24
|
+
const ix = await DriftCore.buildFillPerpOrderInstruction({
|
|
25
|
+
program,
|
|
26
|
+
orderId: 7,
|
|
27
|
+
state: pk(),
|
|
28
|
+
filler: pk(),
|
|
29
|
+
fillerStats: pk(),
|
|
30
|
+
user: pk(),
|
|
31
|
+
userStats: pk(),
|
|
32
|
+
authority: pk(),
|
|
33
|
+
remainingAccounts: [],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(ix).toBe(fakeIx as any);
|
|
37
|
+
expect(called.length).toBe(1);
|
|
38
|
+
expect(called[0][0]).toBe(7);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('buildTriggerOrderInstruction wires accounts + args', async () => {
|
|
42
|
+
const called: any[] = [];
|
|
43
|
+
const fakeIx = {
|
|
44
|
+
keys: [],
|
|
45
|
+
programId: Keypair.generate().publicKey,
|
|
46
|
+
data: Buffer.alloc(0),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const program = {
|
|
50
|
+
instruction: {
|
|
51
|
+
triggerOrder: async (...args: any[]) => {
|
|
52
|
+
called.push(args);
|
|
53
|
+
return fakeIx;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const pk = () => Keypair.generate().publicKey;
|
|
58
|
+
|
|
59
|
+
const ix = await DriftCore.buildTriggerOrderInstruction({
|
|
60
|
+
program,
|
|
61
|
+
orderId: 9,
|
|
62
|
+
state: pk(),
|
|
63
|
+
filler: pk(),
|
|
64
|
+
user: pk(),
|
|
65
|
+
authority: pk(),
|
|
66
|
+
remainingAccounts: [],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(ix).toBe(fakeIx as any);
|
|
70
|
+
expect(called.length).toBe(1);
|
|
71
|
+
expect(called[0][0]).toBe(9);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { DriftCore } from '../../src/core/DriftCore';
|
|
3
|
+
import { Keypair } from '@solana/web3.js';
|
|
4
|
+
import { BN } from '../../src/isomorphic/anchor';
|
|
5
|
+
|
|
6
|
+
describe('DriftCore instruction builders', () => {
|
|
7
|
+
test('buildDepositInstruction calls underlying program.deposit', async () => {
|
|
8
|
+
const called: any[] = [];
|
|
9
|
+
const fakeIx = {
|
|
10
|
+
keys: [],
|
|
11
|
+
programId: Keypair.generate().publicKey,
|
|
12
|
+
data: Buffer.alloc(0),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const program = {
|
|
16
|
+
instruction: {
|
|
17
|
+
deposit: async (...args: any[]) => {
|
|
18
|
+
called.push(args);
|
|
19
|
+
return fakeIx;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const pk = () => Keypair.generate().publicKey;
|
|
25
|
+
|
|
26
|
+
const ix = await DriftCore.buildDepositInstruction({
|
|
27
|
+
program,
|
|
28
|
+
marketIndex: 1,
|
|
29
|
+
amount: new BN(123),
|
|
30
|
+
reduceOnly: false,
|
|
31
|
+
state: pk(),
|
|
32
|
+
spotMarket: pk(),
|
|
33
|
+
spotMarketVault: pk(),
|
|
34
|
+
user: pk(),
|
|
35
|
+
userStats: pk(),
|
|
36
|
+
userTokenAccount: pk(),
|
|
37
|
+
authority: pk(),
|
|
38
|
+
tokenProgram: pk(),
|
|
39
|
+
remainingAccounts: [],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(ix).toBe(fakeIx as any);
|
|
43
|
+
expect(called.length).toBe(1);
|
|
44
|
+
expect(called[0][0]).toBe(1);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { Keypair, PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { DriftCore } from '../../src/core/DriftCore';
|
|
4
|
+
|
|
5
|
+
describe('DriftCore.pdas', () => {
|
|
6
|
+
test('derives deterministic user/state PDAs', async () => {
|
|
7
|
+
const programId = Keypair.generate().publicKey;
|
|
8
|
+
const authority = Keypair.generate().publicKey;
|
|
9
|
+
|
|
10
|
+
const [state] = await DriftCore.pdas.getDriftStateAccountPublicKeyAndNonce(
|
|
11
|
+
programId
|
|
12
|
+
);
|
|
13
|
+
const user0 = await DriftCore.pdas.getUserAccountPublicKey(
|
|
14
|
+
programId,
|
|
15
|
+
authority,
|
|
16
|
+
0
|
|
17
|
+
);
|
|
18
|
+
const user1 = await DriftCore.pdas.getUserAccountPublicKey(
|
|
19
|
+
programId,
|
|
20
|
+
authority,
|
|
21
|
+
1
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(state).toBeInstanceOf(PublicKey);
|
|
25
|
+
expect(user0).toBeInstanceOf(PublicKey);
|
|
26
|
+
expect(user1).toBeInstanceOf(PublicKey);
|
|
27
|
+
expect(user0.toBase58()).not.toEqual(user1.toBase58());
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { Keypair } from '@solana/web3.js';
|
|
3
|
+
import { DriftCore } from '../../src/core/DriftCore';
|
|
4
|
+
|
|
5
|
+
describe('DriftCore perp order instruction builders', () => {
|
|
6
|
+
const pk = () => Keypair.generate().publicKey;
|
|
7
|
+
const fakeIx = {
|
|
8
|
+
keys: [],
|
|
9
|
+
programId: Keypair.generate().publicKey,
|
|
10
|
+
data: Buffer.alloc(0),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
test('buildPlacePerpOrderInstruction', async () => {
|
|
14
|
+
const called: any[] = [];
|
|
15
|
+
const program = {
|
|
16
|
+
instruction: {
|
|
17
|
+
placePerpOrder: async (...args: any[]) => {
|
|
18
|
+
called.push(args);
|
|
19
|
+
return fakeIx;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const ix = await DriftCore.buildPlacePerpOrderInstruction({
|
|
24
|
+
program,
|
|
25
|
+
orderParams: { x: 1 },
|
|
26
|
+
state: pk(),
|
|
27
|
+
user: pk(),
|
|
28
|
+
userStats: pk(),
|
|
29
|
+
authority: pk(),
|
|
30
|
+
remainingAccounts: [],
|
|
31
|
+
});
|
|
32
|
+
expect(ix).toBe(fakeIx as any);
|
|
33
|
+
expect(called[0][0]).toEqual({ x: 1 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('buildPlaceAndTakePerpOrderInstruction', async () => {
|
|
37
|
+
const called: any[] = [];
|
|
38
|
+
const program = {
|
|
39
|
+
instruction: {
|
|
40
|
+
placeAndTakePerpOrder: async (...args: any[]) => {
|
|
41
|
+
called.push(args);
|
|
42
|
+
return fakeIx;
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const ix = await DriftCore.buildPlaceAndTakePerpOrderInstruction({
|
|
47
|
+
program,
|
|
48
|
+
orderParams: { m: 0 },
|
|
49
|
+
optionalParams: 256,
|
|
50
|
+
state: pk(),
|
|
51
|
+
user: pk(),
|
|
52
|
+
userStats: pk(),
|
|
53
|
+
authority: pk(),
|
|
54
|
+
remainingAccounts: [],
|
|
55
|
+
});
|
|
56
|
+
expect(ix).toBe(fakeIx as any);
|
|
57
|
+
expect(called[0][1]).toBe(256);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('buildPlaceAndMakePerpOrderInstruction', async () => {
|
|
61
|
+
const called: any[] = [];
|
|
62
|
+
const program = {
|
|
63
|
+
instruction: {
|
|
64
|
+
placeAndMakePerpOrder: async (...args: any[]) => {
|
|
65
|
+
called.push(args);
|
|
66
|
+
return fakeIx;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const ix = await DriftCore.buildPlaceAndMakePerpOrderInstruction({
|
|
71
|
+
program,
|
|
72
|
+
orderParams: {},
|
|
73
|
+
takerOrderId: 7,
|
|
74
|
+
state: pk(),
|
|
75
|
+
user: pk(),
|
|
76
|
+
userStats: pk(),
|
|
77
|
+
taker: pk(),
|
|
78
|
+
takerStats: pk(),
|
|
79
|
+
authority: pk(),
|
|
80
|
+
remainingAccounts: [],
|
|
81
|
+
});
|
|
82
|
+
expect(ix).toBe(fakeIx as any);
|
|
83
|
+
expect(called[0][1]).toBe(7);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('buildCancelOrderInstruction', async () => {
|
|
87
|
+
const called: any[] = [];
|
|
88
|
+
const program = {
|
|
89
|
+
instruction: {
|
|
90
|
+
cancelOrder: async (...args: any[]) => {
|
|
91
|
+
called.push(args);
|
|
92
|
+
return fakeIx;
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
const ix = await DriftCore.buildCancelOrderInstruction({
|
|
97
|
+
program,
|
|
98
|
+
orderId: 3,
|
|
99
|
+
state: pk(),
|
|
100
|
+
user: pk(),
|
|
101
|
+
authority: pk(),
|
|
102
|
+
remainingAccounts: [],
|
|
103
|
+
});
|
|
104
|
+
expect(ix).toBe(fakeIx as any);
|
|
105
|
+
expect(called[0][0]).toBe(3);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('buildCancelOrderByUserIdInstruction', async () => {
|
|
109
|
+
const called: any[] = [];
|
|
110
|
+
const program = {
|
|
111
|
+
instruction: {
|
|
112
|
+
cancelOrderByUserId: async (...args: any[]) => {
|
|
113
|
+
called.push(args);
|
|
114
|
+
return fakeIx;
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
const ix = await DriftCore.buildCancelOrderByUserIdInstruction({
|
|
119
|
+
program,
|
|
120
|
+
userOrderId: 9,
|
|
121
|
+
state: pk(),
|
|
122
|
+
user: pk(),
|
|
123
|
+
authority: pk(),
|
|
124
|
+
oracle: pk(),
|
|
125
|
+
remainingAccounts: [],
|
|
126
|
+
});
|
|
127
|
+
expect(ix).toBe(fakeIx as any);
|
|
128
|
+
expect(called[0][0]).toBe(9);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('buildCancelOrdersByIdsInstruction', async () => {
|
|
132
|
+
const called: any[] = [];
|
|
133
|
+
const program = {
|
|
134
|
+
instruction: {
|
|
135
|
+
cancelOrdersByIds: async (...args: any[]) => {
|
|
136
|
+
called.push(args);
|
|
137
|
+
return fakeIx;
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
const ids = [1, 2];
|
|
142
|
+
const ix = await DriftCore.buildCancelOrdersByIdsInstruction({
|
|
143
|
+
program,
|
|
144
|
+
orderIds: ids,
|
|
145
|
+
state: pk(),
|
|
146
|
+
user: pk(),
|
|
147
|
+
authority: pk(),
|
|
148
|
+
remainingAccounts: [],
|
|
149
|
+
});
|
|
150
|
+
expect(ix).toBe(fakeIx as any);
|
|
151
|
+
expect(called[0][0]).toBe(ids);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('buildModifyOrderInstruction', async () => {
|
|
155
|
+
const called: any[] = [];
|
|
156
|
+
const program = {
|
|
157
|
+
instruction: {
|
|
158
|
+
modifyOrder: async (...args: any[]) => {
|
|
159
|
+
called.push(args);
|
|
160
|
+
return fakeIx;
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const mp = { baseAssetAmount: null };
|
|
165
|
+
const ix = await DriftCore.buildModifyOrderInstruction({
|
|
166
|
+
program,
|
|
167
|
+
orderId: 4,
|
|
168
|
+
modifyParams: mp,
|
|
169
|
+
state: pk(),
|
|
170
|
+
user: pk(),
|
|
171
|
+
userStats: pk(),
|
|
172
|
+
authority: pk(),
|
|
173
|
+
remainingAccounts: [],
|
|
174
|
+
});
|
|
175
|
+
expect(ix).toBe(fakeIx as any);
|
|
176
|
+
expect(called[0][0]).toBe(4);
|
|
177
|
+
expect(called[0][1]).toBe(mp);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('buildModifyOrderByUserIdInstruction', async () => {
|
|
181
|
+
const called: any[] = [];
|
|
182
|
+
const program = {
|
|
183
|
+
instruction: {
|
|
184
|
+
modifyOrderByUserId: async (...args: any[]) => {
|
|
185
|
+
called.push(args);
|
|
186
|
+
return fakeIx;
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
const mp = { reduceOnly: false };
|
|
191
|
+
const ix = await DriftCore.buildModifyOrderByUserIdInstruction({
|
|
192
|
+
program,
|
|
193
|
+
userOrderId: 11,
|
|
194
|
+
modifyParams: mp,
|
|
195
|
+
state: pk(),
|
|
196
|
+
user: pk(),
|
|
197
|
+
userStats: pk(),
|
|
198
|
+
authority: pk(),
|
|
199
|
+
remainingAccounts: [],
|
|
200
|
+
});
|
|
201
|
+
expect(ix).toBe(fakeIx as any);
|
|
202
|
+
expect(called[0][0]).toBe(11);
|
|
203
|
+
expect(called[0][1]).toBe(mp);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { Keypair } from '@solana/web3.js';
|
|
3
|
+
import { DriftCore } from '../../src/core/DriftCore';
|
|
4
|
+
import { BN } from '../../src/isomorphic/anchor';
|
|
5
|
+
import type { UserAccount } from '../../src/types';
|
|
6
|
+
|
|
7
|
+
describe('DriftCore.remainingAccounts', () => {
|
|
8
|
+
test('includes spot/perp + oracle accounts based on user positions', () => {
|
|
9
|
+
const spotMarket0 = {
|
|
10
|
+
marketIndex: 0,
|
|
11
|
+
pubkey: Keypair.generate().publicKey,
|
|
12
|
+
oracle: Keypair.generate().publicKey,
|
|
13
|
+
} as any;
|
|
14
|
+
const quoteSpotMarket = {
|
|
15
|
+
marketIndex: 0,
|
|
16
|
+
pubkey: spotMarket0.pubkey,
|
|
17
|
+
oracle: spotMarket0.oracle,
|
|
18
|
+
} as any;
|
|
19
|
+
const perpMarket0 = {
|
|
20
|
+
pubkey: Keypair.generate().publicKey,
|
|
21
|
+
quoteSpotMarketIndex: 0,
|
|
22
|
+
amm: {
|
|
23
|
+
oracle: Keypair.generate().publicKey,
|
|
24
|
+
oracleSource: { prelaunch: {} },
|
|
25
|
+
},
|
|
26
|
+
} as any;
|
|
27
|
+
|
|
28
|
+
const user: UserAccount = {
|
|
29
|
+
authority: Keypair.generate().publicKey,
|
|
30
|
+
subAccountId: 0,
|
|
31
|
+
spotPositions: [
|
|
32
|
+
{
|
|
33
|
+
marketIndex: 0,
|
|
34
|
+
scaledBalance: new BN(1),
|
|
35
|
+
openBids: new BN(0),
|
|
36
|
+
openAsks: new BN(0),
|
|
37
|
+
cumulativeDeposits: new BN(0),
|
|
38
|
+
balanceType: { deposit: {} },
|
|
39
|
+
openOrders: 0,
|
|
40
|
+
} as any,
|
|
41
|
+
],
|
|
42
|
+
perpPositions: [
|
|
43
|
+
{
|
|
44
|
+
marketIndex: 0,
|
|
45
|
+
baseAssetAmount: new BN(1),
|
|
46
|
+
} as any,
|
|
47
|
+
],
|
|
48
|
+
} as any;
|
|
49
|
+
|
|
50
|
+
const ctx = {
|
|
51
|
+
getPerpMarketAccount: () => perpMarket0,
|
|
52
|
+
getSpotMarketAccount: () => quoteSpotMarket,
|
|
53
|
+
getUserAccountAndSlot: () => ({ slot: 0 }),
|
|
54
|
+
activeSubAccountId: 0,
|
|
55
|
+
authority: user.authority,
|
|
56
|
+
perpMarketLastSlotCache: new Map<number, number>(),
|
|
57
|
+
spotMarketLastSlotCache: new Map<number, number>(),
|
|
58
|
+
mustIncludePerpMarketIndexes: new Set<number>(),
|
|
59
|
+
mustIncludeSpotMarketIndexes: new Set<number>(),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const metas = DriftCore.remainingAccounts.getRemainingAccounts(ctx as any, {
|
|
63
|
+
userAccounts: [user],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const keys = new Set(metas.map((m) => m.pubkey.toBase58()));
|
|
67
|
+
expect(keys.has(perpMarket0.pubkey.toBase58())).toBe(true);
|
|
68
|
+
expect(keys.has(perpMarket0.amm.oracle.toBase58())).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { Keypair } from '@solana/web3.js';
|
|
3
|
+
import { DriftCore } from '../../src/core/DriftCore';
|
|
4
|
+
|
|
5
|
+
describe('DriftCore settlement/liquidation builders', () => {
|
|
6
|
+
test('buildSettlePnlInstruction wires args', async () => {
|
|
7
|
+
const called: any[] = [];
|
|
8
|
+
const fakeIx = {
|
|
9
|
+
keys: [],
|
|
10
|
+
programId: Keypair.generate().publicKey,
|
|
11
|
+
data: Buffer.alloc(0),
|
|
12
|
+
};
|
|
13
|
+
const program = {
|
|
14
|
+
instruction: {
|
|
15
|
+
settlePnl: async (...args: any[]) => {
|
|
16
|
+
called.push(args);
|
|
17
|
+
return fakeIx;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const pk = () => Keypair.generate().publicKey;
|
|
22
|
+
|
|
23
|
+
const ix = await DriftCore.buildSettlePnlInstruction({
|
|
24
|
+
program,
|
|
25
|
+
marketIndex: 1,
|
|
26
|
+
state: pk(),
|
|
27
|
+
authority: pk(),
|
|
28
|
+
user: pk(),
|
|
29
|
+
spotMarketVault: pk(),
|
|
30
|
+
remainingAccounts: [],
|
|
31
|
+
});
|
|
32
|
+
expect(ix).toBe(fakeIx as any);
|
|
33
|
+
expect(called[0][0]).toBe(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('buildLiquidatePerpInstruction wires args', async () => {
|
|
37
|
+
const called: any[] = [];
|
|
38
|
+
const fakeIx = {
|
|
39
|
+
keys: [],
|
|
40
|
+
programId: Keypair.generate().publicKey,
|
|
41
|
+
data: Buffer.alloc(0),
|
|
42
|
+
};
|
|
43
|
+
const program = {
|
|
44
|
+
instruction: {
|
|
45
|
+
liquidatePerp: async (...args: any[]) => {
|
|
46
|
+
called.push(args);
|
|
47
|
+
return fakeIx;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const pk = () => Keypair.generate().publicKey;
|
|
52
|
+
|
|
53
|
+
const ix = await DriftCore.buildLiquidatePerpInstruction({
|
|
54
|
+
program,
|
|
55
|
+
marketIndex: 2,
|
|
56
|
+
maxBaseAssetAmount: 123,
|
|
57
|
+
limitPrice: null,
|
|
58
|
+
state: pk(),
|
|
59
|
+
authority: pk(),
|
|
60
|
+
user: pk(),
|
|
61
|
+
userStats: pk(),
|
|
62
|
+
liquidator: pk(),
|
|
63
|
+
liquidatorStats: pk(),
|
|
64
|
+
remainingAccounts: [],
|
|
65
|
+
});
|
|
66
|
+
expect(ix).toBe(fakeIx as any);
|
|
67
|
+
expect(called[0][0]).toBe(2);
|
|
68
|
+
});
|
|
69
|
+
});
|