@drift-labs/sdk 0.1.26 → 0.1.29-master.0
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/lib/accounts/bulkAccountLoader.js +8 -3
- package/lib/accounts/pollingOracleSubscriber.d.ts +26 -0
- package/lib/accounts/pollingOracleSubscriber.js +79 -0
- package/lib/accounts/types.d.ts +14 -1
- package/lib/clearingHouse.d.ts +6 -4
- package/lib/clearingHouse.js +56 -7
- package/lib/constants/markets.d.ts +2 -2
- package/lib/constants/markets.js +50 -28
- package/lib/idl/clearing_house.json +60 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/market.d.ts +2 -0
- package/lib/math/market.js +6 -1
- package/lib/orderParams.d.ts +1 -1
- package/lib/orderParams.js +2 -2
- package/lib/orders.d.ts +3 -2
- package/lib/orders.js +11 -4
- package/lib/types.d.ts +3 -0
- package/lib/types.js +1 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +10 -4
- package/src/accounts/bulkUserSubscription.js +56 -0
- package/src/accounts/bulkUserSubscription.js.map +1 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +210 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js.map +1 -0
- package/src/accounts/pollingOracleSubscriber.js +65 -0
- package/src/accounts/pollingOracleSubscriber.js.map +1 -0
- package/src/accounts/pollingOracleSubscriber.ts +103 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +65 -0
- package/src/accounts/pollingTokenAccountSubscriber.js.map +1 -0
- package/src/accounts/pollingUserAccountSubscriber.js +139 -0
- package/src/accounts/pollingUserAccountSubscriber.js.map +1 -0
- package/src/accounts/types.js +1 -0
- package/src/accounts/types.js.map +1 -0
- package/src/accounts/types.ts +22 -1
- package/src/accounts/utils.js +1 -0
- package/src/accounts/utils.js.map +1 -0
- package/src/accounts/webSocketAccountSubscriber.js +15 -27
- package/src/accounts/webSocketAccountSubscriber.js.map +1 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +212 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js.map +1 -0
- package/src/accounts/webSocketUserAccountSubscriber.js +78 -0
- package/src/accounts/webSocketUserAccountSubscriber.js.map +1 -0
- package/src/addresses.js +20 -44
- package/src/addresses.js.map +1 -0
- package/src/admin.js +443 -0
- package/src/admin.js.map +1 -0
- package/src/assert/assert.js +10 -0
- package/src/assert/assert.js.map +1 -0
- package/src/clearingHouse.ts +85 -7
- package/src/clearingHouseUser.js +581 -0
- package/src/clearingHouseUser.js.map +1 -0
- package/src/config.js +37 -0
- package/src/config.js.map +1 -0
- package/src/constants/markets.js +167 -0
- package/src/constants/markets.js.map +1 -0
- package/src/constants/markets.ts +52 -30
- package/src/constants/numericConstants.js +22 -0
- package/src/constants/numericConstants.js.map +1 -0
- package/src/factory/clearingHouse.js +65 -0
- package/src/factory/clearingHouse.js.map +1 -0
- package/src/factory/clearingHouseUser.js +35 -0
- package/src/factory/clearingHouseUser.js.map +1 -0
- package/src/factory/oracleClient.js +17 -0
- package/src/factory/oracleClient.js.map +1 -0
- package/src/idl/clearing_house.json +60 -1
- package/src/index.js +56 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +1 -0
- package/src/math/amm.js +285 -0
- package/src/math/amm.js.map +1 -0
- package/src/math/conversion.js +16 -0
- package/src/math/conversion.js.map +1 -0
- package/src/math/funding.js +223 -0
- package/src/math/funding.js.map +1 -0
- package/src/math/insuranceFund.js +23 -0
- package/src/math/insuranceFund.js.map +1 -0
- package/src/math/market.js +30 -0
- package/src/math/market.js.map +1 -0
- package/src/math/market.ts +9 -0
- package/src/math/orders.js +73 -0
- package/src/math/orders.js.map +1 -0
- package/src/math/position.js +121 -0
- package/src/math/position.js.map +1 -0
- package/src/math/trade.js +182 -0
- package/src/math/trade.js.map +1 -0
- package/src/math/utils.js +27 -0
- package/src/math/utils.js.map +1 -0
- package/src/mockUSDCFaucet.js +88 -116
- package/src/mockUSDCFaucet.js.map +1 -0
- package/src/oracles/pythClient.js +39 -0
- package/src/oracles/pythClient.js.map +1 -0
- package/src/oracles/switchboardClient.js +60 -0
- package/src/oracles/switchboardClient.js.map +1 -0
- package/src/oracles/types.js +3 -0
- package/src/oracles/types.js.map +1 -0
- package/src/orderParams.js +109 -0
- package/src/orderParams.js.map +1 -0
- package/src/orderParams.ts +3 -2
- package/src/orders.js +172 -0
- package/src/orders.js.map +1 -0
- package/src/orders.ts +17 -4
- package/src/token/index.js +39 -0
- package/src/token/index.js.map +1 -0
- package/src/tx/defaultTxSender.js +13 -0
- package/src/tx/defaultTxSender.js.map +1 -0
- package/src/tx/retryTxSender.js +137 -0
- package/src/tx/retryTxSender.js.map +1 -0
- package/src/tx/types.js +3 -0
- package/src/tx/types.js.map +1 -0
- package/src/tx/utils.js +9 -0
- package/src/tx/utils.js.map +1 -0
- package/src/types.js +1 -0
- package/src/types.js.map +1 -0
- package/src/types.ts +1 -0
- package/src/util/computeUnits.js +17 -0
- package/src/util/computeUnits.js.map +1 -0
- package/src/util/tps.js +17 -0
- package/src/util/tps.js.map +1 -0
- package/src/wallet.js +23 -0
- package/src/wallet.js.map +1 -0
package/src/clearingHouse.ts
CHANGED
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
getClearingHouse,
|
|
58
58
|
getWebSocketClearingHouseConfig,
|
|
59
59
|
} from './factory/clearingHouse';
|
|
60
|
+
import { ZERO } from './constants/numericConstants';
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
63
|
* # ClearingHouse
|
|
@@ -760,6 +761,14 @@ export class ClearingHouse {
|
|
|
760
761
|
});
|
|
761
762
|
}
|
|
762
763
|
|
|
764
|
+
if (!orderParams.oraclePriceOffset.eq(ZERO)) {
|
|
765
|
+
remainingAccounts.push({
|
|
766
|
+
pubkey: priceOracle,
|
|
767
|
+
isWritable: false,
|
|
768
|
+
isSigner: false,
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
|
|
763
772
|
const state = this.getStateAccount();
|
|
764
773
|
const orderState = this.getOrderStateAccount();
|
|
765
774
|
return await this.program.instruction.placeOrder(orderParams, {
|
|
@@ -774,26 +783,81 @@ export class ClearingHouse {
|
|
|
774
783
|
fundingRateHistory: state.fundingRateHistory,
|
|
775
784
|
orderState: await this.getOrderStatePublicKey(),
|
|
776
785
|
orderHistory: orderState.orderHistory,
|
|
777
|
-
oracle: priceOracle,
|
|
778
786
|
},
|
|
779
787
|
remainingAccounts,
|
|
780
788
|
});
|
|
781
789
|
}
|
|
782
790
|
|
|
783
|
-
public async
|
|
791
|
+
public async expireOrders(
|
|
792
|
+
userAccountPublicKey: PublicKey,
|
|
793
|
+
userOrdersAccountPublicKey: PublicKey
|
|
794
|
+
): Promise<TransactionSignature> {
|
|
795
|
+
return await this.txSender.send(
|
|
796
|
+
wrapInTx(
|
|
797
|
+
await this.getExpireOrdersIx(
|
|
798
|
+
userAccountPublicKey,
|
|
799
|
+
userOrdersAccountPublicKey
|
|
800
|
+
)
|
|
801
|
+
),
|
|
802
|
+
[],
|
|
803
|
+
this.opts
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
public async getExpireOrdersIx(
|
|
808
|
+
userAccountPublicKey: PublicKey,
|
|
809
|
+
userOrdersAccountPublicKey: PublicKey
|
|
810
|
+
): Promise<TransactionInstruction> {
|
|
811
|
+
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
812
|
+
const userAccount: any = await this.program.account.user.fetch(
|
|
813
|
+
userAccountPublicKey
|
|
814
|
+
);
|
|
815
|
+
|
|
816
|
+
const orderState = this.getOrderStateAccount();
|
|
817
|
+
return await this.program.instruction.expireOrders({
|
|
818
|
+
accounts: {
|
|
819
|
+
state: await this.getStatePublicKey(),
|
|
820
|
+
filler: fillerPublicKey,
|
|
821
|
+
user: userAccountPublicKey,
|
|
822
|
+
authority: this.wallet.publicKey,
|
|
823
|
+
userPositions: userAccount.positions,
|
|
824
|
+
userOrders: userOrdersAccountPublicKey,
|
|
825
|
+
orderState: await this.getOrderStatePublicKey(),
|
|
826
|
+
orderHistory: orderState.orderHistory,
|
|
827
|
+
},
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
public async cancelOrder(
|
|
832
|
+
orderId: BN,
|
|
833
|
+
oracle?: PublicKey
|
|
834
|
+
): Promise<TransactionSignature> {
|
|
784
835
|
return await this.txSender.send(
|
|
785
|
-
wrapInTx(await this.getCancelOrderIx(orderId)),
|
|
836
|
+
wrapInTx(await this.getCancelOrderIx(orderId, oracle)),
|
|
786
837
|
[],
|
|
787
838
|
this.opts
|
|
788
839
|
);
|
|
789
840
|
}
|
|
790
841
|
|
|
791
|
-
public async getCancelOrderIx(
|
|
842
|
+
public async getCancelOrderIx(
|
|
843
|
+
orderId: BN,
|
|
844
|
+
oracle?: PublicKey
|
|
845
|
+
): Promise<TransactionInstruction> {
|
|
792
846
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
793
847
|
const userAccount = await this.getUserAccount();
|
|
794
848
|
|
|
795
849
|
const state = this.getStateAccount();
|
|
796
850
|
const orderState = this.getOrderStateAccount();
|
|
851
|
+
|
|
852
|
+
const remainingAccounts = [];
|
|
853
|
+
if (oracle) {
|
|
854
|
+
remainingAccounts.push({
|
|
855
|
+
pubkey: oracle,
|
|
856
|
+
isWritable: false,
|
|
857
|
+
isSigner: false,
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
|
|
797
861
|
return await this.program.instruction.cancelOrder(orderId, {
|
|
798
862
|
accounts: {
|
|
799
863
|
state: await this.getStatePublicKey(),
|
|
@@ -807,27 +871,40 @@ export class ClearingHouse {
|
|
|
807
871
|
orderState: await this.getOrderStatePublicKey(),
|
|
808
872
|
orderHistory: orderState.orderHistory,
|
|
809
873
|
},
|
|
874
|
+
remainingAccounts,
|
|
810
875
|
});
|
|
811
876
|
}
|
|
812
877
|
|
|
813
878
|
public async cancelOrderByUserId(
|
|
814
|
-
userOrderId: number
|
|
879
|
+
userOrderId: number,
|
|
880
|
+
oracle?: PublicKey
|
|
815
881
|
): Promise<TransactionSignature> {
|
|
816
882
|
return await this.txSender.send(
|
|
817
|
-
wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId)),
|
|
883
|
+
wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId, oracle)),
|
|
818
884
|
[],
|
|
819
885
|
this.opts
|
|
820
886
|
);
|
|
821
887
|
}
|
|
822
888
|
|
|
823
889
|
public async getCancelOrderByUserIdIx(
|
|
824
|
-
userOrderId: number
|
|
890
|
+
userOrderId: number,
|
|
891
|
+
oracle?: PublicKey
|
|
825
892
|
): Promise<TransactionInstruction> {
|
|
826
893
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
827
894
|
const userAccount = await this.getUserAccount();
|
|
828
895
|
|
|
829
896
|
const state = this.getStateAccount();
|
|
830
897
|
const orderState = this.getOrderStateAccount();
|
|
898
|
+
|
|
899
|
+
const remainingAccounts = [];
|
|
900
|
+
if (oracle) {
|
|
901
|
+
remainingAccounts.push({
|
|
902
|
+
pubkey: oracle,
|
|
903
|
+
isWritable: false,
|
|
904
|
+
isSigner: false,
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
|
|
831
908
|
return await this.program.instruction.cancelOrderByUserId(userOrderId, {
|
|
832
909
|
accounts: {
|
|
833
910
|
state: await this.getStatePublicKey(),
|
|
@@ -841,6 +918,7 @@ export class ClearingHouse {
|
|
|
841
918
|
orderState: await this.getOrderStatePublicKey(),
|
|
842
919
|
orderHistory: orderState.orderHistory,
|
|
843
920
|
},
|
|
921
|
+
remainingAccounts,
|
|
844
922
|
});
|
|
845
923
|
}
|
|
846
924
|
|