@drift-labs/sdk 0.1.18-orders.5 → 0.1.18-orders.9
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 +4 -2
- package/lib/clearingHouseUser.d.ts +5 -0
- package/lib/clearingHouseUser.js +7 -0
- package/lib/config.js +1 -1
- package/lib/constants/markets.js +8 -0
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +2 -1
- package/lib/idl/clearing_house.json +4 -4
- package/lib/math/orders.js +3 -1
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +3 -3
- package/src/clearingHouseUser.ts +10 -0
- package/src/config.ts +1 -1
- package/src/constants/markets.ts +8 -0
- package/src/constants/numericConstants.ts +1 -0
- package/src/idl/clearing_house.json +4 -4
- package/src/math/orders.ts +7 -2
- package/src/types.ts +1 -0
|
@@ -50,6 +50,11 @@ export declare class ClearingHouseUser {
|
|
|
50
50
|
* @returns Order
|
|
51
51
|
*/
|
|
52
52
|
getOrder(orderId: BN): Order | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* @param userOrderId
|
|
55
|
+
* @returns Order
|
|
56
|
+
*/
|
|
57
|
+
getOrderByUserOrderId(userOrderId: number): Order | undefined;
|
|
53
58
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
54
59
|
getUserOrdersAccountPublicKey(): Promise<PublicKey>;
|
|
55
60
|
exists(): Promise<boolean>;
|
package/lib/clearingHouseUser.js
CHANGED
|
@@ -100,6 +100,13 @@ class ClearingHouseUser {
|
|
|
100
100
|
getOrder(orderId) {
|
|
101
101
|
return this.getUserOrdersAccount().orders.find((order) => order.orderId.eq(orderId));
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* @param userOrderId
|
|
105
|
+
* @returns Order
|
|
106
|
+
*/
|
|
107
|
+
getOrderByUserOrderId(userOrderId) {
|
|
108
|
+
return this.getUserOrdersAccount().orders.find((order) => order.userOrderId === userOrderId);
|
|
109
|
+
}
|
|
103
110
|
getUserAccountPublicKey() {
|
|
104
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
112
|
if (this.userAccountPublicKey) {
|
package/lib/config.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.configs = {
|
|
|
5
5
|
devnet: {
|
|
6
6
|
ENV: 'devnet',
|
|
7
7
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
8
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
8
|
+
CLEARING_HOUSE_PROGRAM_ID: 'AsW7LnXB9UA1uec9wi9MctYTgTz7YH9snhxd16GsFaGX',
|
|
9
9
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
10
10
|
},
|
|
11
11
|
'mainnet-beta': {
|
package/lib/constants/markets.js
CHANGED
|
@@ -99,6 +99,14 @@ exports.Markets = [
|
|
|
99
99
|
mainnetPythOracle: '8JPJJkmDScpcNmBRKGZuPuG2GYAveQgP3t5gFuMymwvF',
|
|
100
100
|
launchTs: 1644382122000,
|
|
101
101
|
},
|
|
102
|
+
{
|
|
103
|
+
symbol: 'LTC-PERP',
|
|
104
|
+
baseAssetSymbol: 'LTC',
|
|
105
|
+
marketIndex: new __1.BN(12),
|
|
106
|
+
devnetPythOracle: 'BLArYBCUYhdWiY8PCUTpvFE21iaJq85dvxLk9bYMobcU',
|
|
107
|
+
mainnetPythOracle: '8RMnV1eD55iqUFJLMguPkYBkq8DCtx81XcmAja93LvRR',
|
|
108
|
+
launchTs: 1645027429000,
|
|
109
|
+
},
|
|
102
110
|
// {
|
|
103
111
|
// symbol: 'mSOL-PERP',
|
|
104
112
|
// baseAssetSymbol: 'mSOL',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.PARTIAL_LIQUIDATION_RATIO = exports.FULL_LIQUIDATION_RATIO = exports.MAX_LEVERAGE = exports.BN_MAX = exports.TEN_THOUSAND = exports.ONE = exports.ZERO = void 0;
|
|
3
|
+
exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.PARTIAL_LIQUIDATION_RATIO = exports.FULL_LIQUIDATION_RATIO = exports.MAX_LEVERAGE = exports.BN_MAX = exports.TEN_THOUSAND = exports.TWO = exports.ONE = exports.ZERO = void 0;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
exports.ZERO = new __1.BN(0);
|
|
6
6
|
exports.ONE = new __1.BN(1);
|
|
7
|
+
exports.TWO = new __1.BN(2);
|
|
7
8
|
exports.TEN_THOUSAND = new __1.BN(10000);
|
|
8
9
|
exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
|
|
9
10
|
exports.MAX_LEVERAGE = new __1.BN(5);
|
|
@@ -572,7 +572,7 @@
|
|
|
572
572
|
},
|
|
573
573
|
{
|
|
574
574
|
"name": "markets",
|
|
575
|
-
"isMut":
|
|
575
|
+
"isMut": false,
|
|
576
576
|
"isSigner": false
|
|
577
577
|
},
|
|
578
578
|
{
|
|
@@ -628,7 +628,7 @@
|
|
|
628
628
|
},
|
|
629
629
|
{
|
|
630
630
|
"name": "markets",
|
|
631
|
-
"isMut":
|
|
631
|
+
"isMut": false,
|
|
632
632
|
"isSigner": false
|
|
633
633
|
},
|
|
634
634
|
{
|
|
@@ -2291,11 +2291,11 @@
|
|
|
2291
2291
|
"type": "u128"
|
|
2292
2292
|
},
|
|
2293
2293
|
{
|
|
2294
|
-
"name": "
|
|
2294
|
+
"name": "extendedCurveHistory",
|
|
2295
2295
|
"type": "publicKey"
|
|
2296
2296
|
},
|
|
2297
2297
|
{
|
|
2298
|
-
"name": "
|
|
2298
|
+
"name": "orderState",
|
|
2299
2299
|
"type": "publicKey"
|
|
2300
2300
|
},
|
|
2301
2301
|
{
|
package/lib/math/orders.js
CHANGED
|
@@ -22,9 +22,11 @@ function isOrderRiskIncreasing(user, order) {
|
|
|
22
22
|
types_1.isVariant(order.direction, 'short')) {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
|
+
const baseAssetAmountToFill = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
25
26
|
// if order will flip position
|
|
26
|
-
if (position.baseAssetAmount.abs().
|
|
27
|
+
if (baseAssetAmountToFill.gt(position.baseAssetAmount.abs().mul(numericConstants_1.TWO))) {
|
|
27
28
|
return true;
|
|
28
29
|
}
|
|
30
|
+
return false;
|
|
29
31
|
}
|
|
30
32
|
exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -117,10 +117,10 @@ export class BulkAccountLoader {
|
|
|
117
117
|
for (const [_, callback] of this.errorCallbacks) {
|
|
118
118
|
callback(e);
|
|
119
119
|
}
|
|
120
|
+
} finally {
|
|
121
|
+
this.loadPromiseResolver();
|
|
122
|
+
this.loadPromise = undefined;
|
|
120
123
|
}
|
|
121
|
-
|
|
122
|
-
this.loadPromiseResolver();
|
|
123
|
-
this.loadPromise = undefined;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
async loadChunk(accountsToLoad: AccountToLoad[]): Promise<void> {
|
package/src/clearingHouseUser.ts
CHANGED
|
@@ -155,6 +155,16 @@ export class ClearingHouseUser {
|
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @param userOrderId
|
|
160
|
+
* @returns Order
|
|
161
|
+
*/
|
|
162
|
+
public getOrderByUserOrderId(userOrderId: number): Order | undefined {
|
|
163
|
+
return this.getUserOrdersAccount().orders.find(
|
|
164
|
+
(order) => order.userOrderId === userOrderId
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
public async getUserAccountPublicKey(): Promise<PublicKey> {
|
|
159
169
|
if (this.userAccountPublicKey) {
|
|
160
170
|
return this.userAccountPublicKey;
|
package/src/config.ts
CHANGED
|
@@ -11,7 +11,7 @@ export const configs: { [key in DriftEnv]: DriftConfig } = {
|
|
|
11
11
|
devnet: {
|
|
12
12
|
ENV: 'devnet',
|
|
13
13
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
14
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
14
|
+
CLEARING_HOUSE_PROGRAM_ID: 'AsW7LnXB9UA1uec9wi9MctYTgTz7YH9snhxd16GsFaGX',
|
|
15
15
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
16
16
|
},
|
|
17
17
|
'mainnet-beta': {
|
package/src/constants/markets.ts
CHANGED
|
@@ -106,6 +106,14 @@ export const Markets: Market[] = [
|
|
|
106
106
|
mainnetPythOracle: '8JPJJkmDScpcNmBRKGZuPuG2GYAveQgP3t5gFuMymwvF',
|
|
107
107
|
launchTs: 1644382122000,
|
|
108
108
|
},
|
|
109
|
+
{
|
|
110
|
+
symbol: 'LTC-PERP',
|
|
111
|
+
baseAssetSymbol: 'LTC',
|
|
112
|
+
marketIndex: new BN(12),
|
|
113
|
+
devnetPythOracle: 'BLArYBCUYhdWiY8PCUTpvFE21iaJq85dvxLk9bYMobcU',
|
|
114
|
+
mainnetPythOracle: '8RMnV1eD55iqUFJLMguPkYBkq8DCtx81XcmAja93LvRR',
|
|
115
|
+
launchTs: 1645027429000,
|
|
116
|
+
},
|
|
109
117
|
// {
|
|
110
118
|
// symbol: 'mSOL-PERP',
|
|
111
119
|
// baseAssetSymbol: 'mSOL',
|
|
@@ -572,7 +572,7 @@
|
|
|
572
572
|
},
|
|
573
573
|
{
|
|
574
574
|
"name": "markets",
|
|
575
|
-
"isMut":
|
|
575
|
+
"isMut": false,
|
|
576
576
|
"isSigner": false
|
|
577
577
|
},
|
|
578
578
|
{
|
|
@@ -628,7 +628,7 @@
|
|
|
628
628
|
},
|
|
629
629
|
{
|
|
630
630
|
"name": "markets",
|
|
631
|
-
"isMut":
|
|
631
|
+
"isMut": false,
|
|
632
632
|
"isSigner": false
|
|
633
633
|
},
|
|
634
634
|
{
|
|
@@ -2291,11 +2291,11 @@
|
|
|
2291
2291
|
"type": "u128"
|
|
2292
2292
|
},
|
|
2293
2293
|
{
|
|
2294
|
-
"name": "
|
|
2294
|
+
"name": "extendedCurveHistory",
|
|
2295
2295
|
"type": "publicKey"
|
|
2296
2296
|
},
|
|
2297
2297
|
{
|
|
2298
|
-
"name": "
|
|
2298
|
+
"name": "orderState",
|
|
2299
2299
|
"type": "publicKey"
|
|
2300
2300
|
},
|
|
2301
2301
|
{
|
package/src/math/orders.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClearingHouseUser } from '../clearingHouseUser';
|
|
2
2
|
import { isVariant, Order } from '../types';
|
|
3
|
-
import { ZERO } from '../constants/numericConstants';
|
|
3
|
+
import { ZERO, TWO } from '../constants/numericConstants';
|
|
4
4
|
|
|
5
5
|
export function isOrderRiskIncreasing(
|
|
6
6
|
user: ClearingHouseUser,
|
|
@@ -32,8 +32,13 @@ export function isOrderRiskIncreasing(
|
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const baseAssetAmountToFill = order.baseAssetAmount.sub(
|
|
36
|
+
order.baseAssetAmountFilled
|
|
37
|
+
);
|
|
35
38
|
// if order will flip position
|
|
36
|
-
if (position.baseAssetAmount.abs().
|
|
39
|
+
if (baseAssetAmountToFill.gt(position.baseAssetAmount.abs().mul(TWO))) {
|
|
37
40
|
return true;
|
|
38
41
|
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
39
44
|
}
|