@drift-labs/sdk 2.16.0 → 2.17.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/driftClient.d.ts +27 -13
- package/lib/driftClient.js +73 -103
- package/lib/idl/drift.json +21 -2
- package/lib/types.d.ts +12 -1
- package/lib/types.js +8 -2
- package/package.json +4 -3
- package/src/driftClient.ts +97 -122
- package/src/idl/drift.json +21 -2
- package/src/types.ts +8 -2
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
import { AnchorProvider, BN, Program } from '@project-serum/anchor';
|
|
4
|
-
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, OrderType, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount } from './types';
|
|
4
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, OrderType, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, OrderTriggerCondition } from './types';
|
|
5
5
|
import * as anchor from '@project-serum/anchor';
|
|
6
6
|
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount } from '@solana/web3.js';
|
|
7
7
|
import { TokenFaucet } from './tokenFaucet';
|
|
@@ -222,6 +222,16 @@ export declare class DriftClient {
|
|
|
222
222
|
* @returns
|
|
223
223
|
*/
|
|
224
224
|
modifyPerpOrder(orderId: number, newBaseAmount?: BN, newLimitPrice?: BN, newOraclePriceOffset?: number): Promise<TransactionSignature>;
|
|
225
|
+
/**
|
|
226
|
+
* Modifies an open order by closing it and replacing it with a new order.
|
|
227
|
+
* @deprecated use modifyOrderByUserOrderId instead
|
|
228
|
+
* @param userOrderId: The open order to modify
|
|
229
|
+
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
230
|
+
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
231
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
modifyPerpOrderByUserOrderId(userOrderId: number, newBaseAmount?: BN, newLimitPrice?: BN, newOraclePriceOffset?: number): Promise<TransactionSignature>;
|
|
225
235
|
/**
|
|
226
236
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
227
237
|
* @param orderId: The open order to modify
|
|
@@ -231,27 +241,24 @@ export declare class DriftClient {
|
|
|
231
241
|
* @param newOrderType: Optional - New order type for the order.
|
|
232
242
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
233
243
|
* @param isSpot: Optional - Set to true if the order is a spot order
|
|
244
|
+
* @param auctionDuration: Only required if order type changed to market from something else
|
|
245
|
+
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
246
|
+
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
234
247
|
* @returns
|
|
235
248
|
*/
|
|
236
|
-
modifyOrder({ orderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, isSpot, }: {
|
|
249
|
+
modifyOrder({ orderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, newTriggerCondition, isSpot, auctionDuration, auctionStartPrice, auctionEndPrice, }: {
|
|
237
250
|
orderId: number;
|
|
238
251
|
newBaseAmount?: BN;
|
|
239
252
|
newLimitPrice?: BN;
|
|
240
253
|
newOraclePriceOffset?: number;
|
|
241
254
|
newOrderType?: OrderType;
|
|
242
255
|
newTriggerPrice?: BN;
|
|
256
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
243
257
|
isSpot?: boolean;
|
|
258
|
+
auctionDuration?: number;
|
|
259
|
+
auctionStartPrice?: BN;
|
|
260
|
+
auctionEndPrice?: BN;
|
|
244
261
|
}): Promise<TransactionSignature>;
|
|
245
|
-
/**
|
|
246
|
-
* Modifies an open order by closing it and replacing it with a new order.
|
|
247
|
-
* @deprecated use modifyOrderByUserOrderId instead
|
|
248
|
-
* @param userOrderId: The open order to modify
|
|
249
|
-
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
250
|
-
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
251
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
252
|
-
* @returns
|
|
253
|
-
*/
|
|
254
|
-
modifyPerpOrderByUserOrderId(userOrderId: number, newBaseAmount?: BN, newLimitPrice?: BN, newOraclePriceOffset?: number): Promise<TransactionSignature>;
|
|
255
262
|
/**
|
|
256
263
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
257
264
|
* @param userOrderId: The open order to modify
|
|
@@ -261,16 +268,23 @@ export declare class DriftClient {
|
|
|
261
268
|
* @param newOrderType: Optional - New order type for the order.
|
|
262
269
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
263
270
|
* @param isSpot: Set to true if the order is a spot order
|
|
271
|
+
* @param auctionDuration: Only required if order type changed to market from something else
|
|
272
|
+
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
273
|
+
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
264
274
|
* @returns
|
|
265
275
|
*/
|
|
266
|
-
modifyOrderByUserOrderId({ userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, isSpot, }: {
|
|
276
|
+
modifyOrderByUserOrderId({ userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, newTriggerCondition, isSpot, auctionDuration, auctionStartPrice, auctionEndPrice, }: {
|
|
267
277
|
userOrderId: number;
|
|
268
278
|
newBaseAmount?: BN;
|
|
269
279
|
newLimitPrice?: BN;
|
|
270
280
|
newOraclePriceOffset?: number;
|
|
271
281
|
newOrderType?: OrderType;
|
|
272
282
|
newTriggerPrice?: BN;
|
|
283
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
273
284
|
isSpot?: boolean;
|
|
285
|
+
auctionDuration?: number;
|
|
286
|
+
auctionStartPrice?: BN;
|
|
287
|
+
auctionEndPrice?: BN;
|
|
274
288
|
}): Promise<TransactionSignature>;
|
|
275
289
|
settlePNLs(users: {
|
|
276
290
|
settleeUserAccountPublicKey: PublicKey;
|
package/lib/driftClient.js
CHANGED
|
@@ -1769,44 +1769,29 @@ class DriftClient {
|
|
|
1769
1769
|
* @returns
|
|
1770
1770
|
*/
|
|
1771
1771
|
async modifyPerpOrder(orderId, newBaseAmount, newLimitPrice, newOraclePriceOffset) {
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
1796
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
1797
|
-
userOrderId: openOrder.userOrderId,
|
|
1798
|
-
};
|
|
1799
|
-
const placeOrderIx = await this.getPlacePerpOrderIx(newOrderParams);
|
|
1800
|
-
const tx = new web3_js_1.Transaction();
|
|
1801
|
-
tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
|
|
1802
|
-
units: 1000000,
|
|
1803
|
-
additionalFee: 0,
|
|
1804
|
-
}));
|
|
1805
|
-
tx.add(cancelOrderIx);
|
|
1806
|
-
tx.add(placeOrderIx);
|
|
1807
|
-
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
1808
|
-
this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
|
|
1809
|
-
return txSig;
|
|
1772
|
+
return this.modifyOrder({
|
|
1773
|
+
orderId,
|
|
1774
|
+
newBaseAmount,
|
|
1775
|
+
newLimitPrice,
|
|
1776
|
+
newOraclePriceOffset,
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Modifies an open order by closing it and replacing it with a new order.
|
|
1781
|
+
* @deprecated use modifyOrderByUserOrderId instead
|
|
1782
|
+
* @param userOrderId: The open order to modify
|
|
1783
|
+
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
1784
|
+
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
1785
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
1786
|
+
* @returns
|
|
1787
|
+
*/
|
|
1788
|
+
async modifyPerpOrderByUserOrderId(userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset) {
|
|
1789
|
+
return this.modifyOrderByUserOrderId({
|
|
1790
|
+
userOrderId,
|
|
1791
|
+
newBaseAmount,
|
|
1792
|
+
newLimitPrice,
|
|
1793
|
+
newOraclePriceOffset,
|
|
1794
|
+
});
|
|
1810
1795
|
}
|
|
1811
1796
|
/**
|
|
1812
1797
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
@@ -1817,9 +1802,12 @@ class DriftClient {
|
|
|
1817
1802
|
* @param newOrderType: Optional - New order type for the order.
|
|
1818
1803
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
1819
1804
|
* @param isSpot: Optional - Set to true if the order is a spot order
|
|
1805
|
+
* @param auctionDuration: Only required if order type changed to market from something else
|
|
1806
|
+
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
1807
|
+
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
1820
1808
|
* @returns
|
|
1821
1809
|
*/
|
|
1822
|
-
async modifyOrder({ orderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, isSpot, }) {
|
|
1810
|
+
async modifyOrder({ orderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, newTriggerCondition, isSpot, auctionDuration, auctionStartPrice, auctionEndPrice, }) {
|
|
1823
1811
|
if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
|
|
1824
1812
|
throw new Error(`Must provide newBaseAmount or newLimitPrice or newOraclePriceOffset to modify order`);
|
|
1825
1813
|
}
|
|
@@ -1828,23 +1816,37 @@ class DriftClient {
|
|
|
1828
1816
|
throw new Error(`No open order with id ${orderId.toString()}`);
|
|
1829
1817
|
}
|
|
1830
1818
|
const cancelOrderIx = await this.getCancelOrderIx(orderId);
|
|
1819
|
+
const orderTypeHasTrigger = newOrderType
|
|
1820
|
+
? types_1.isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
1821
|
+
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
1822
|
+
const orderTypeHasLimitPrice = newOrderType
|
|
1823
|
+
? types_1.isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
1824
|
+
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
1831
1825
|
const newOrderParams = {
|
|
1832
1826
|
orderType: newOrderType || openOrder.orderType,
|
|
1833
1827
|
marketType: openOrder.marketType,
|
|
1834
1828
|
direction: openOrder.direction,
|
|
1835
1829
|
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
1836
|
-
price:
|
|
1830
|
+
price: orderTypeHasLimitPrice
|
|
1831
|
+
? newLimitPrice || openOrder.price
|
|
1832
|
+
: undefined,
|
|
1837
1833
|
marketIndex: openOrder.marketIndex,
|
|
1838
1834
|
reduceOnly: openOrder.reduceOnly,
|
|
1839
|
-
postOnly: openOrder.postOnly
|
|
1835
|
+
postOnly: openOrder.postOnly
|
|
1836
|
+
? types_1.PostOnlyParams.MUST_POST_ONLY
|
|
1837
|
+
: types_1.PostOnlyParams.NONE,
|
|
1840
1838
|
immediateOrCancel: openOrder.immediateOrCancel,
|
|
1841
|
-
triggerPrice:
|
|
1842
|
-
|
|
1839
|
+
triggerPrice: orderTypeHasTrigger
|
|
1840
|
+
? newTriggerPrice || openOrder.triggerPrice
|
|
1841
|
+
: undefined,
|
|
1842
|
+
triggerCondition: orderTypeHasTrigger
|
|
1843
|
+
? newTriggerCondition || openOrder.triggerCondition
|
|
1844
|
+
: undefined,
|
|
1843
1845
|
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
1844
|
-
auctionDuration: openOrder.auctionDuration,
|
|
1846
|
+
auctionDuration: auctionDuration || openOrder.auctionDuration,
|
|
1845
1847
|
maxTs: openOrder.maxTs,
|
|
1846
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
1847
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
1848
|
+
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
1849
|
+
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
|
1848
1850
|
userOrderId: openOrder.userOrderId,
|
|
1849
1851
|
};
|
|
1850
1852
|
const placeOrderIx = isSpot
|
|
@@ -1867,55 +1869,6 @@ class DriftClient {
|
|
|
1867
1869
|
}
|
|
1868
1870
|
return txSig;
|
|
1869
1871
|
}
|
|
1870
|
-
/**
|
|
1871
|
-
* Modifies an open order by closing it and replacing it with a new order.
|
|
1872
|
-
* @deprecated use modifyOrderByUserOrderId instead
|
|
1873
|
-
* @param userOrderId: The open order to modify
|
|
1874
|
-
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
1875
|
-
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
1876
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
1877
|
-
* @returns
|
|
1878
|
-
*/
|
|
1879
|
-
async modifyPerpOrderByUserOrderId(userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset) {
|
|
1880
|
-
if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
|
|
1881
|
-
throw new Error(`Must provide newBaseAmount or newLimitPrice or newOraclePriceOffset to modify order`);
|
|
1882
|
-
}
|
|
1883
|
-
const openOrder = this.getUser().getOrderByUserOrderId(userOrderId);
|
|
1884
|
-
if (!openOrder) {
|
|
1885
|
-
throw new Error(`No open order with user order id ${userOrderId.toString()}`);
|
|
1886
|
-
}
|
|
1887
|
-
const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
|
|
1888
|
-
const newOrderParams = {
|
|
1889
|
-
orderType: openOrder.orderType,
|
|
1890
|
-
marketType: openOrder.marketType,
|
|
1891
|
-
direction: openOrder.direction,
|
|
1892
|
-
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
1893
|
-
price: newLimitPrice || openOrder.price,
|
|
1894
|
-
marketIndex: openOrder.marketIndex,
|
|
1895
|
-
reduceOnly: openOrder.reduceOnly,
|
|
1896
|
-
postOnly: openOrder.postOnly,
|
|
1897
|
-
immediateOrCancel: openOrder.immediateOrCancel,
|
|
1898
|
-
triggerPrice: openOrder.triggerPrice,
|
|
1899
|
-
triggerCondition: openOrder.triggerCondition,
|
|
1900
|
-
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
1901
|
-
auctionDuration: openOrder.auctionDuration,
|
|
1902
|
-
maxTs: openOrder.maxTs,
|
|
1903
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
1904
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
1905
|
-
userOrderId: openOrder.userOrderId,
|
|
1906
|
-
};
|
|
1907
|
-
const placeOrderIx = await this.getPlacePerpOrderIx(newOrderParams);
|
|
1908
|
-
const tx = new web3_js_1.Transaction();
|
|
1909
|
-
tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
|
|
1910
|
-
units: 1000000,
|
|
1911
|
-
additionalFee: 0,
|
|
1912
|
-
}));
|
|
1913
|
-
tx.add(cancelOrderIx);
|
|
1914
|
-
tx.add(placeOrderIx);
|
|
1915
|
-
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
1916
|
-
this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
|
|
1917
|
-
return txSig;
|
|
1918
|
-
}
|
|
1919
1872
|
/**
|
|
1920
1873
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
1921
1874
|
* @param userOrderId: The open order to modify
|
|
@@ -1925,9 +1878,12 @@ class DriftClient {
|
|
|
1925
1878
|
* @param newOrderType: Optional - New order type for the order.
|
|
1926
1879
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
1927
1880
|
* @param isSpot: Set to true if the order is a spot order
|
|
1881
|
+
* @param auctionDuration: Only required if order type changed to market from something else
|
|
1882
|
+
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
1883
|
+
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
1928
1884
|
* @returns
|
|
1929
1885
|
*/
|
|
1930
|
-
async modifyOrderByUserOrderId({ userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, isSpot, }) {
|
|
1886
|
+
async modifyOrderByUserOrderId({ userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset, newOrderType, newTriggerPrice, newTriggerCondition, isSpot, auctionDuration, auctionStartPrice, auctionEndPrice, }) {
|
|
1931
1887
|
if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
|
|
1932
1888
|
throw new Error(`Must provide newBaseAmount or newLimitPrice or newOraclePriceOffset to modify order`);
|
|
1933
1889
|
}
|
|
@@ -1936,23 +1892,37 @@ class DriftClient {
|
|
|
1936
1892
|
throw new Error(`No open order with user order id ${userOrderId.toString()}`);
|
|
1937
1893
|
}
|
|
1938
1894
|
const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
|
|
1895
|
+
const orderTypeHasTrigger = newOrderType
|
|
1896
|
+
? types_1.isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
1897
|
+
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
1898
|
+
const orderTypeHasLimitPrice = newOrderType
|
|
1899
|
+
? types_1.isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
1900
|
+
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
1939
1901
|
const newOrderParams = {
|
|
1940
1902
|
orderType: newOrderType || openOrder.orderType,
|
|
1941
1903
|
marketType: openOrder.marketType,
|
|
1942
1904
|
direction: openOrder.direction,
|
|
1943
1905
|
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
1944
|
-
price:
|
|
1906
|
+
price: orderTypeHasLimitPrice
|
|
1907
|
+
? newLimitPrice || openOrder.price
|
|
1908
|
+
: undefined,
|
|
1945
1909
|
marketIndex: openOrder.marketIndex,
|
|
1946
1910
|
reduceOnly: openOrder.reduceOnly,
|
|
1947
|
-
postOnly: openOrder.postOnly
|
|
1911
|
+
postOnly: openOrder.postOnly
|
|
1912
|
+
? types_1.PostOnlyParams.MUST_POST_ONLY
|
|
1913
|
+
: types_1.PostOnlyParams.NONE,
|
|
1948
1914
|
immediateOrCancel: openOrder.immediateOrCancel,
|
|
1949
|
-
triggerPrice:
|
|
1950
|
-
|
|
1915
|
+
triggerPrice: orderTypeHasTrigger
|
|
1916
|
+
? newTriggerPrice || openOrder.triggerPrice
|
|
1917
|
+
: undefined,
|
|
1918
|
+
triggerCondition: orderTypeHasTrigger
|
|
1919
|
+
? newTriggerCondition || openOrder.triggerCondition
|
|
1920
|
+
: undefined,
|
|
1951
1921
|
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
1952
|
-
auctionDuration: openOrder.auctionDuration,
|
|
1922
|
+
auctionDuration: auctionDuration || openOrder.auctionDuration,
|
|
1953
1923
|
maxTs: openOrder.maxTs,
|
|
1954
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
1955
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
1924
|
+
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
1925
|
+
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
|
1956
1926
|
userOrderId: openOrder.userOrderId,
|
|
1957
1927
|
};
|
|
1958
1928
|
const placeOrderIx = isSpot
|
package/lib/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.17.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -4655,7 +4655,9 @@
|
|
|
4655
4655
|
},
|
|
4656
4656
|
{
|
|
4657
4657
|
"name": "postOnly",
|
|
4658
|
-
"type":
|
|
4658
|
+
"type": {
|
|
4659
|
+
"defined": "PostOnlyParam"
|
|
4660
|
+
}
|
|
4659
4661
|
},
|
|
4660
4662
|
{
|
|
4661
4663
|
"name": "immediateOrCancel",
|
|
@@ -5862,6 +5864,23 @@
|
|
|
5862
5864
|
]
|
|
5863
5865
|
}
|
|
5864
5866
|
},
|
|
5867
|
+
{
|
|
5868
|
+
"name": "PostOnlyParam",
|
|
5869
|
+
"type": {
|
|
5870
|
+
"kind": "enum",
|
|
5871
|
+
"variants": [
|
|
5872
|
+
{
|
|
5873
|
+
"name": "None"
|
|
5874
|
+
},
|
|
5875
|
+
{
|
|
5876
|
+
"name": "MustPostOnly"
|
|
5877
|
+
},
|
|
5878
|
+
{
|
|
5879
|
+
"name": "TryPostOnly"
|
|
5880
|
+
}
|
|
5881
|
+
]
|
|
5882
|
+
}
|
|
5883
|
+
},
|
|
5865
5884
|
{
|
|
5866
5885
|
"name": "TwapPeriod",
|
|
5867
5886
|
"type": {
|
package/lib/types.d.ts
CHANGED
|
@@ -886,7 +886,7 @@ export declare type OrderParams = {
|
|
|
886
886
|
price: BN;
|
|
887
887
|
marketIndex: number;
|
|
888
888
|
reduceOnly: boolean;
|
|
889
|
-
postOnly:
|
|
889
|
+
postOnly: PostOnlyParams;
|
|
890
890
|
immediateOrCancel: boolean;
|
|
891
891
|
triggerPrice: BN | null;
|
|
892
892
|
triggerCondition: OrderTriggerCondition;
|
|
@@ -897,6 +897,17 @@ export declare type OrderParams = {
|
|
|
897
897
|
auctionStartPrice: BN | null;
|
|
898
898
|
auctionEndPrice: BN | null;
|
|
899
899
|
};
|
|
900
|
+
export declare class PostOnlyParams {
|
|
901
|
+
static readonly NONE: {
|
|
902
|
+
none: {};
|
|
903
|
+
};
|
|
904
|
+
static readonly MUST_POST_ONLY: {
|
|
905
|
+
mustPostOnly: {};
|
|
906
|
+
};
|
|
907
|
+
static readonly TRY_POST_ONLY: {
|
|
908
|
+
tryPostOnly: {};
|
|
909
|
+
};
|
|
910
|
+
}
|
|
900
911
|
export declare type NecessaryOrderParams = {
|
|
901
912
|
orderType: OrderType;
|
|
902
913
|
marketIndex: number;
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultOrderParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SpotFulfillmentConfigStatus = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.UserStatus = exports.MarketStatus = exports.ExchangeStatus = void 0;
|
|
3
|
+
exports.DefaultOrderParams = exports.PostOnlyParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SpotFulfillmentConfigStatus = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.UserStatus = exports.MarketStatus = exports.ExchangeStatus = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
// # Utility Types / Enums / Constants
|
|
6
6
|
var ExchangeStatus;
|
|
@@ -232,6 +232,12 @@ LiquidationType.BORROW_BANKRUPTCY = {
|
|
|
232
232
|
LiquidationType.LIQUIDATE_SPOT = {
|
|
233
233
|
liquidateSpot: {},
|
|
234
234
|
};
|
|
235
|
+
class PostOnlyParams {
|
|
236
|
+
}
|
|
237
|
+
exports.PostOnlyParams = PostOnlyParams;
|
|
238
|
+
PostOnlyParams.NONE = { none: {} };
|
|
239
|
+
PostOnlyParams.MUST_POST_ONLY = { mustPostOnly: {} }; // Tx fails if order can't be post only
|
|
240
|
+
PostOnlyParams.TRY_POST_ONLY = { tryPostOnly: {} }; // Tx succeeds and order not placed if can't be post only
|
|
235
241
|
exports.DefaultOrderParams = {
|
|
236
242
|
orderType: OrderType.MARKET,
|
|
237
243
|
marketType: MarketType.PERP,
|
|
@@ -241,7 +247,7 @@ exports.DefaultOrderParams = {
|
|
|
241
247
|
price: _1.ZERO,
|
|
242
248
|
marketIndex: 0,
|
|
243
249
|
reduceOnly: false,
|
|
244
|
-
postOnly:
|
|
250
|
+
postOnly: PostOnlyParams.NONE,
|
|
245
251
|
immediateOrCancel: false,
|
|
246
252
|
triggerPrice: null,
|
|
247
253
|
triggerCondition: OrderTriggerCondition.ABOVE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -53,10 +53,11 @@
|
|
|
53
53
|
"eslint-plugin-prettier": "^3.4.0",
|
|
54
54
|
"mocha": "^10.0.0",
|
|
55
55
|
"prettier": "^2.4.1",
|
|
56
|
-
"ts-node": "^10.8.0"
|
|
56
|
+
"ts-node": "^10.8.0",
|
|
57
|
+
"typescript": "^4.9.5"
|
|
57
58
|
},
|
|
58
59
|
"description": "SDK for Drift Protocol",
|
|
59
60
|
"engines": {
|
|
60
61
|
"node": ">=12"
|
|
61
62
|
}
|
|
62
|
-
}
|
|
63
|
+
}
|
package/src/driftClient.ts
CHANGED
|
@@ -25,6 +25,9 @@ import {
|
|
|
25
25
|
TxParams,
|
|
26
26
|
SerumV3FulfillmentConfigAccount,
|
|
27
27
|
isVariant,
|
|
28
|
+
OrderTriggerCondition,
|
|
29
|
+
isOneOfVariant,
|
|
30
|
+
PostOnlyParams,
|
|
28
31
|
} from './types';
|
|
29
32
|
import * as anchor from '@project-serum/anchor';
|
|
30
33
|
import driftIDL from './idl/drift.json';
|
|
@@ -3049,51 +3052,35 @@ export class DriftClient {
|
|
|
3049
3052
|
newLimitPrice?: BN,
|
|
3050
3053
|
newOraclePriceOffset?: number
|
|
3051
3054
|
): Promise<TransactionSignature> {
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
if (!openOrder) {
|
|
3060
|
-
throw new Error(`No open order with id ${orderId.toString()}`);
|
|
3061
|
-
}
|
|
3062
|
-
const cancelOrderIx = await this.getCancelOrderIx(orderId);
|
|
3063
|
-
|
|
3064
|
-
const newOrderParams: OptionalOrderParams = {
|
|
3065
|
-
orderType: openOrder.orderType,
|
|
3066
|
-
marketType: openOrder.marketType,
|
|
3067
|
-
direction: openOrder.direction,
|
|
3068
|
-
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
3069
|
-
price: newLimitPrice || openOrder.price,
|
|
3070
|
-
marketIndex: openOrder.marketIndex,
|
|
3071
|
-
reduceOnly: openOrder.reduceOnly,
|
|
3072
|
-
postOnly: openOrder.postOnly,
|
|
3073
|
-
immediateOrCancel: openOrder.immediateOrCancel,
|
|
3074
|
-
triggerPrice: openOrder.triggerPrice,
|
|
3075
|
-
triggerCondition: openOrder.triggerCondition,
|
|
3076
|
-
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3077
|
-
auctionDuration: openOrder.auctionDuration,
|
|
3078
|
-
maxTs: openOrder.maxTs,
|
|
3079
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
3080
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
3081
|
-
userOrderId: openOrder.userOrderId,
|
|
3082
|
-
};
|
|
3083
|
-
const placeOrderIx = await this.getPlacePerpOrderIx(newOrderParams);
|
|
3055
|
+
return this.modifyOrder({
|
|
3056
|
+
orderId,
|
|
3057
|
+
newBaseAmount,
|
|
3058
|
+
newLimitPrice,
|
|
3059
|
+
newOraclePriceOffset,
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3084
3062
|
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3063
|
+
/**
|
|
3064
|
+
* Modifies an open order by closing it and replacing it with a new order.
|
|
3065
|
+
* @deprecated use modifyOrderByUserOrderId instead
|
|
3066
|
+
* @param userOrderId: The open order to modify
|
|
3067
|
+
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
3068
|
+
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
3069
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
3070
|
+
* @returns
|
|
3071
|
+
*/
|
|
3072
|
+
public async modifyPerpOrderByUserOrderId(
|
|
3073
|
+
userOrderId: number,
|
|
3074
|
+
newBaseAmount?: BN,
|
|
3075
|
+
newLimitPrice?: BN,
|
|
3076
|
+
newOraclePriceOffset?: number
|
|
3077
|
+
): Promise<TransactionSignature> {
|
|
3078
|
+
return this.modifyOrderByUserOrderId({
|
|
3079
|
+
userOrderId,
|
|
3080
|
+
newBaseAmount,
|
|
3081
|
+
newLimitPrice,
|
|
3082
|
+
newOraclePriceOffset,
|
|
3083
|
+
});
|
|
3097
3084
|
}
|
|
3098
3085
|
|
|
3099
3086
|
/**
|
|
@@ -3105,6 +3092,9 @@ export class DriftClient {
|
|
|
3105
3092
|
* @param newOrderType: Optional - New order type for the order.
|
|
3106
3093
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3107
3094
|
* @param isSpot: Optional - Set to true if the order is a spot order
|
|
3095
|
+
* @param auctionDuration: Only required if order type changed to market from something else
|
|
3096
|
+
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
3097
|
+
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
3108
3098
|
* @returns
|
|
3109
3099
|
*/
|
|
3110
3100
|
public async modifyOrder({
|
|
@@ -3114,7 +3104,11 @@ export class DriftClient {
|
|
|
3114
3104
|
newOraclePriceOffset,
|
|
3115
3105
|
newOrderType,
|
|
3116
3106
|
newTriggerPrice,
|
|
3107
|
+
newTriggerCondition,
|
|
3117
3108
|
isSpot,
|
|
3109
|
+
auctionDuration,
|
|
3110
|
+
auctionStartPrice,
|
|
3111
|
+
auctionEndPrice,
|
|
3118
3112
|
}: {
|
|
3119
3113
|
orderId: number;
|
|
3120
3114
|
newBaseAmount?: BN;
|
|
@@ -3122,7 +3116,11 @@ export class DriftClient {
|
|
|
3122
3116
|
newOraclePriceOffset?: number;
|
|
3123
3117
|
newOrderType?: OrderType;
|
|
3124
3118
|
newTriggerPrice?: BN;
|
|
3119
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
3125
3120
|
isSpot?: boolean;
|
|
3121
|
+
auctionDuration?: number;
|
|
3122
|
+
auctionStartPrice?: BN;
|
|
3123
|
+
auctionEndPrice?: BN;
|
|
3126
3124
|
}): Promise<TransactionSignature> {
|
|
3127
3125
|
if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
|
|
3128
3126
|
throw new Error(
|
|
@@ -3136,23 +3134,38 @@ export class DriftClient {
|
|
|
3136
3134
|
}
|
|
3137
3135
|
const cancelOrderIx = await this.getCancelOrderIx(orderId);
|
|
3138
3136
|
|
|
3137
|
+
const orderTypeHasTrigger = newOrderType
|
|
3138
|
+
? isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
3139
|
+
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
3140
|
+
const orderTypeHasLimitPrice = newOrderType
|
|
3141
|
+
? isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
3142
|
+
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
3143
|
+
|
|
3139
3144
|
const newOrderParams: OptionalOrderParams = {
|
|
3140
3145
|
orderType: newOrderType || openOrder.orderType,
|
|
3141
3146
|
marketType: openOrder.marketType,
|
|
3142
3147
|
direction: openOrder.direction,
|
|
3143
3148
|
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
3144
|
-
price:
|
|
3149
|
+
price: orderTypeHasLimitPrice
|
|
3150
|
+
? newLimitPrice || openOrder.price
|
|
3151
|
+
: undefined,
|
|
3145
3152
|
marketIndex: openOrder.marketIndex,
|
|
3146
3153
|
reduceOnly: openOrder.reduceOnly,
|
|
3147
|
-
postOnly: openOrder.postOnly
|
|
3154
|
+
postOnly: openOrder.postOnly
|
|
3155
|
+
? PostOnlyParams.MUST_POST_ONLY
|
|
3156
|
+
: PostOnlyParams.NONE,
|
|
3148
3157
|
immediateOrCancel: openOrder.immediateOrCancel,
|
|
3149
|
-
triggerPrice:
|
|
3150
|
-
|
|
3158
|
+
triggerPrice: orderTypeHasTrigger
|
|
3159
|
+
? newTriggerPrice || openOrder.triggerPrice
|
|
3160
|
+
: undefined,
|
|
3161
|
+
triggerCondition: orderTypeHasTrigger
|
|
3162
|
+
? newTriggerCondition || openOrder.triggerCondition
|
|
3163
|
+
: undefined,
|
|
3151
3164
|
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3152
|
-
auctionDuration: openOrder.auctionDuration,
|
|
3165
|
+
auctionDuration: auctionDuration || openOrder.auctionDuration,
|
|
3153
3166
|
maxTs: openOrder.maxTs,
|
|
3154
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
3155
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
3167
|
+
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
3168
|
+
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
|
3156
3169
|
userOrderId: openOrder.userOrderId,
|
|
3157
3170
|
};
|
|
3158
3171
|
const placeOrderIx = isSpot
|
|
@@ -3180,70 +3193,6 @@ export class DriftClient {
|
|
|
3180
3193
|
return txSig;
|
|
3181
3194
|
}
|
|
3182
3195
|
|
|
3183
|
-
/**
|
|
3184
|
-
* Modifies an open order by closing it and replacing it with a new order.
|
|
3185
|
-
* @deprecated use modifyOrderByUserOrderId instead
|
|
3186
|
-
* @param userOrderId: The open order to modify
|
|
3187
|
-
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
3188
|
-
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
3189
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
3190
|
-
* @returns
|
|
3191
|
-
*/
|
|
3192
|
-
public async modifyPerpOrderByUserOrderId(
|
|
3193
|
-
userOrderId: number,
|
|
3194
|
-
newBaseAmount?: BN,
|
|
3195
|
-
newLimitPrice?: BN,
|
|
3196
|
-
newOraclePriceOffset?: number
|
|
3197
|
-
): Promise<TransactionSignature> {
|
|
3198
|
-
if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
|
|
3199
|
-
throw new Error(
|
|
3200
|
-
`Must provide newBaseAmount or newLimitPrice or newOraclePriceOffset to modify order`
|
|
3201
|
-
);
|
|
3202
|
-
}
|
|
3203
|
-
|
|
3204
|
-
const openOrder = this.getUser().getOrderByUserOrderId(userOrderId);
|
|
3205
|
-
if (!openOrder) {
|
|
3206
|
-
throw new Error(
|
|
3207
|
-
`No open order with user order id ${userOrderId.toString()}`
|
|
3208
|
-
);
|
|
3209
|
-
}
|
|
3210
|
-
const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
|
|
3211
|
-
|
|
3212
|
-
const newOrderParams: OptionalOrderParams = {
|
|
3213
|
-
orderType: openOrder.orderType,
|
|
3214
|
-
marketType: openOrder.marketType,
|
|
3215
|
-
direction: openOrder.direction,
|
|
3216
|
-
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
3217
|
-
price: newLimitPrice || openOrder.price,
|
|
3218
|
-
marketIndex: openOrder.marketIndex,
|
|
3219
|
-
reduceOnly: openOrder.reduceOnly,
|
|
3220
|
-
postOnly: openOrder.postOnly,
|
|
3221
|
-
immediateOrCancel: openOrder.immediateOrCancel,
|
|
3222
|
-
triggerPrice: openOrder.triggerPrice,
|
|
3223
|
-
triggerCondition: openOrder.triggerCondition,
|
|
3224
|
-
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3225
|
-
auctionDuration: openOrder.auctionDuration,
|
|
3226
|
-
maxTs: openOrder.maxTs,
|
|
3227
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
3228
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
3229
|
-
userOrderId: openOrder.userOrderId,
|
|
3230
|
-
};
|
|
3231
|
-
const placeOrderIx = await this.getPlacePerpOrderIx(newOrderParams);
|
|
3232
|
-
|
|
3233
|
-
const tx = new Transaction();
|
|
3234
|
-
tx.add(
|
|
3235
|
-
ComputeBudgetProgram.requestUnits({
|
|
3236
|
-
units: 1_000_000,
|
|
3237
|
-
additionalFee: 0,
|
|
3238
|
-
})
|
|
3239
|
-
);
|
|
3240
|
-
tx.add(cancelOrderIx);
|
|
3241
|
-
tx.add(placeOrderIx);
|
|
3242
|
-
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
3243
|
-
this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
|
|
3244
|
-
return txSig;
|
|
3245
|
-
}
|
|
3246
|
-
|
|
3247
3196
|
/**
|
|
3248
3197
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
3249
3198
|
* @param userOrderId: The open order to modify
|
|
@@ -3253,6 +3202,9 @@ export class DriftClient {
|
|
|
3253
3202
|
* @param newOrderType: Optional - New order type for the order.
|
|
3254
3203
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3255
3204
|
* @param isSpot: Set to true if the order is a spot order
|
|
3205
|
+
* @param auctionDuration: Only required if order type changed to market from something else
|
|
3206
|
+
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
3207
|
+
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
3256
3208
|
* @returns
|
|
3257
3209
|
*/
|
|
3258
3210
|
public async modifyOrderByUserOrderId({
|
|
@@ -3262,7 +3214,11 @@ export class DriftClient {
|
|
|
3262
3214
|
newOraclePriceOffset,
|
|
3263
3215
|
newOrderType,
|
|
3264
3216
|
newTriggerPrice,
|
|
3217
|
+
newTriggerCondition,
|
|
3265
3218
|
isSpot,
|
|
3219
|
+
auctionDuration,
|
|
3220
|
+
auctionStartPrice,
|
|
3221
|
+
auctionEndPrice,
|
|
3266
3222
|
}: {
|
|
3267
3223
|
userOrderId: number;
|
|
3268
3224
|
newBaseAmount?: BN;
|
|
@@ -3270,7 +3226,11 @@ export class DriftClient {
|
|
|
3270
3226
|
newOraclePriceOffset?: number;
|
|
3271
3227
|
newOrderType?: OrderType;
|
|
3272
3228
|
newTriggerPrice?: BN;
|
|
3229
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
3273
3230
|
isSpot?: boolean;
|
|
3231
|
+
auctionDuration?: number;
|
|
3232
|
+
auctionStartPrice?: BN;
|
|
3233
|
+
auctionEndPrice?: BN;
|
|
3274
3234
|
}): Promise<TransactionSignature> {
|
|
3275
3235
|
if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
|
|
3276
3236
|
throw new Error(
|
|
@@ -3286,23 +3246,38 @@ export class DriftClient {
|
|
|
3286
3246
|
}
|
|
3287
3247
|
const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
|
|
3288
3248
|
|
|
3249
|
+
const orderTypeHasTrigger = newOrderType
|
|
3250
|
+
? isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
3251
|
+
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
3252
|
+
const orderTypeHasLimitPrice = newOrderType
|
|
3253
|
+
? isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
3254
|
+
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
3255
|
+
|
|
3289
3256
|
const newOrderParams: OptionalOrderParams = {
|
|
3290
3257
|
orderType: newOrderType || openOrder.orderType,
|
|
3291
3258
|
marketType: openOrder.marketType,
|
|
3292
3259
|
direction: openOrder.direction,
|
|
3293
3260
|
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
3294
|
-
price:
|
|
3261
|
+
price: orderTypeHasLimitPrice
|
|
3262
|
+
? newLimitPrice || openOrder.price
|
|
3263
|
+
: undefined,
|
|
3295
3264
|
marketIndex: openOrder.marketIndex,
|
|
3296
3265
|
reduceOnly: openOrder.reduceOnly,
|
|
3297
|
-
postOnly: openOrder.postOnly
|
|
3266
|
+
postOnly: openOrder.postOnly
|
|
3267
|
+
? PostOnlyParams.MUST_POST_ONLY
|
|
3268
|
+
: PostOnlyParams.NONE,
|
|
3298
3269
|
immediateOrCancel: openOrder.immediateOrCancel,
|
|
3299
|
-
triggerPrice:
|
|
3300
|
-
|
|
3270
|
+
triggerPrice: orderTypeHasTrigger
|
|
3271
|
+
? newTriggerPrice || openOrder.triggerPrice
|
|
3272
|
+
: undefined,
|
|
3273
|
+
triggerCondition: orderTypeHasTrigger
|
|
3274
|
+
? newTriggerCondition || openOrder.triggerCondition
|
|
3275
|
+
: undefined,
|
|
3301
3276
|
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3302
|
-
auctionDuration: openOrder.auctionDuration,
|
|
3277
|
+
auctionDuration: auctionDuration || openOrder.auctionDuration,
|
|
3303
3278
|
maxTs: openOrder.maxTs,
|
|
3304
|
-
auctionStartPrice: openOrder.auctionStartPrice,
|
|
3305
|
-
auctionEndPrice: openOrder.auctionEndPrice,
|
|
3279
|
+
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
3280
|
+
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
|
3306
3281
|
userOrderId: openOrder.userOrderId,
|
|
3307
3282
|
};
|
|
3308
3283
|
const placeOrderIx = isSpot
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.17.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -4655,7 +4655,9 @@
|
|
|
4655
4655
|
},
|
|
4656
4656
|
{
|
|
4657
4657
|
"name": "postOnly",
|
|
4658
|
-
"type":
|
|
4658
|
+
"type": {
|
|
4659
|
+
"defined": "PostOnlyParam"
|
|
4660
|
+
}
|
|
4659
4661
|
},
|
|
4660
4662
|
{
|
|
4661
4663
|
"name": "immediateOrCancel",
|
|
@@ -5862,6 +5864,23 @@
|
|
|
5862
5864
|
]
|
|
5863
5865
|
}
|
|
5864
5866
|
},
|
|
5867
|
+
{
|
|
5868
|
+
"name": "PostOnlyParam",
|
|
5869
|
+
"type": {
|
|
5870
|
+
"kind": "enum",
|
|
5871
|
+
"variants": [
|
|
5872
|
+
{
|
|
5873
|
+
"name": "None"
|
|
5874
|
+
},
|
|
5875
|
+
{
|
|
5876
|
+
"name": "MustPostOnly"
|
|
5877
|
+
},
|
|
5878
|
+
{
|
|
5879
|
+
"name": "TryPostOnly"
|
|
5880
|
+
}
|
|
5881
|
+
]
|
|
5882
|
+
}
|
|
5883
|
+
},
|
|
5865
5884
|
{
|
|
5866
5885
|
"name": "TwapPeriod",
|
|
5867
5886
|
"type": {
|
package/src/types.ts
CHANGED
|
@@ -846,7 +846,7 @@ export type OrderParams = {
|
|
|
846
846
|
price: BN;
|
|
847
847
|
marketIndex: number;
|
|
848
848
|
reduceOnly: boolean;
|
|
849
|
-
postOnly:
|
|
849
|
+
postOnly: PostOnlyParams;
|
|
850
850
|
immediateOrCancel: boolean;
|
|
851
851
|
triggerPrice: BN | null;
|
|
852
852
|
triggerCondition: OrderTriggerCondition;
|
|
@@ -858,6 +858,12 @@ export type OrderParams = {
|
|
|
858
858
|
auctionEndPrice: BN | null;
|
|
859
859
|
};
|
|
860
860
|
|
|
861
|
+
export class PostOnlyParams {
|
|
862
|
+
static readonly NONE = { none: {} };
|
|
863
|
+
static readonly MUST_POST_ONLY = { mustPostOnly: {} }; // Tx fails if order can't be post only
|
|
864
|
+
static readonly TRY_POST_ONLY = { tryPostOnly: {} }; // Tx succeeds and order not placed if can't be post only
|
|
865
|
+
}
|
|
866
|
+
|
|
861
867
|
export type NecessaryOrderParams = {
|
|
862
868
|
orderType: OrderType;
|
|
863
869
|
marketIndex: number;
|
|
@@ -878,7 +884,7 @@ export const DefaultOrderParams: OrderParams = {
|
|
|
878
884
|
price: ZERO,
|
|
879
885
|
marketIndex: 0,
|
|
880
886
|
reduceOnly: false,
|
|
881
|
-
postOnly:
|
|
887
|
+
postOnly: PostOnlyParams.NONE,
|
|
882
888
|
immediateOrCancel: false,
|
|
883
889
|
triggerPrice: null,
|
|
884
890
|
triggerCondition: OrderTriggerCondition.ABOVE,
|