@drift-labs/sdk 0.2.0-master.11 → 0.2.0-master.12

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.
Files changed (72) hide show
  1. package/lib/clearingHouse.d.ts +7 -2
  2. package/lib/clearingHouse.js +157 -37
  3. package/lib/clearingHouseUser.d.ts +10 -15
  4. package/lib/clearingHouseUser.js +92 -74
  5. package/lib/config.js +1 -1
  6. package/lib/constants/banks.d.ts +2 -2
  7. package/lib/constants/banks.js +4 -3
  8. package/lib/constants/numericConstants.d.ts +2 -0
  9. package/lib/constants/numericConstants.js +3 -1
  10. package/lib/events/eventList.js +3 -0
  11. package/lib/events/types.d.ts +2 -1
  12. package/lib/factory/bigNum.d.ts +1 -0
  13. package/lib/factory/bigNum.js +37 -11
  14. package/lib/idl/clearing_house.json +97 -19
  15. package/lib/index.d.ts +1 -0
  16. package/lib/index.js +1 -0
  17. package/lib/math/bankBalance.d.ts +3 -1
  18. package/lib/math/bankBalance.js +54 -1
  19. package/lib/math/margin.d.ts +11 -0
  20. package/lib/math/margin.js +72 -0
  21. package/lib/math/market.d.ts +4 -1
  22. package/lib/math/market.js +35 -1
  23. package/lib/math/position.d.ts +8 -0
  24. package/lib/math/position.js +42 -12
  25. package/lib/orders.d.ts +1 -2
  26. package/lib/orders.js +2 -77
  27. package/lib/tokenFaucet.d.ts +1 -0
  28. package/lib/tokenFaucet.js +23 -12
  29. package/lib/tx/retryTxSender.js +9 -2
  30. package/lib/types.d.ts +24 -3
  31. package/lib/types.js +6 -0
  32. package/lib/util/getTokenAddress.d.ts +2 -0
  33. package/lib/util/getTokenAddress.js +9 -0
  34. package/package.json +1 -1
  35. package/src/clearingHouse.ts +301 -47
  36. package/src/clearingHouseConfig.js +2 -0
  37. package/src/clearingHouseUser.ts +213 -104
  38. package/src/clearingHouseUserConfig.js +2 -0
  39. package/src/config.ts +1 -1
  40. package/src/constants/banks.js +42 -0
  41. package/src/constants/banks.ts +6 -3
  42. package/src/constants/markets.js +42 -0
  43. package/src/constants/numericConstants.js +41 -0
  44. package/src/constants/numericConstants.ts +3 -0
  45. package/src/events/eventList.ts +3 -0
  46. package/src/events/types.ts +2 -0
  47. package/src/factory/bigNum.js +37 -11
  48. package/src/factory/bigNum.ts +43 -13
  49. package/src/idl/clearing_house.json +97 -19
  50. package/src/index.js +67 -98
  51. package/src/index.ts +1 -0
  52. package/src/math/bankBalance.ts +98 -1
  53. package/src/math/margin.ts +124 -0
  54. package/src/math/market.ts +66 -1
  55. package/src/math/position.ts +59 -9
  56. package/src/orders.ts +4 -157
  57. package/src/tokenFaucet.js +189 -0
  58. package/src/tokenFaucet.ts +38 -15
  59. package/src/tx/retryTxSender.ts +11 -3
  60. package/src/types.js +12 -1
  61. package/src/types.ts +25 -3
  62. package/src/{accounts/fetch.js → util/computeUnits.js} +11 -13
  63. package/src/util/getTokenAddress.js +9 -0
  64. package/src/util/getTokenAddress.ts +18 -0
  65. package/tests/bn/test.ts +2 -0
  66. package/src/addresses/pda.js +0 -104
  67. package/src/math/bankBalance.js +0 -75
  68. package/src/math/market.js +0 -57
  69. package/src/math/orders.js +0 -110
  70. package/src/math/position.js +0 -140
  71. package/src/orders.js +0 -134
  72. package/src/tx/retryTxSender.js +0 -188
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUOTE_ASSET_BANK_INDEX = exports.ONE_YEAR = exports.BID_ASK_SPREAD_PRECISION = exports.MARGIN_PRECISION = exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.PRICE_DIV_PEG = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION_EXP = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.LIQUIDATION_FEE_PRECISION = exports.BANK_BALANCE_PRECISION = exports.BANK_BALANCE_PRECISION_EXP = exports.BANK_WEIGHT_PRECISION = exports.BANK_RATE_PRECISION = exports.BANK_UTILIZATION_PRECISION = exports.BANK_CUMULATIVE_INTEREST_PRECISION = exports.BANK_INTEREST_PRECISION = exports.AMM_RESERVE_PRECISION_EXP = exports.PEG_PRECISION_EXP = exports.FUNDING_RATE_PRECISION_EXP = exports.MARK_PRICE_PRECISION_EXP = exports.FUNDING_PAYMENT_PRECISION_EXP = exports.QUOTE_PRECISION_EXP = exports.MAX_LEVERAGE = exports.TEN_MILLION = exports.BN_MAX = exports.TEN_THOUSAND = exports.TEN = exports.TWO = exports.ONE = exports.ZERO = void 0;
4
+ const __1 = require("../");
5
+ exports.ZERO = new __1.BN(0);
6
+ exports.ONE = new __1.BN(1);
7
+ exports.TWO = new __1.BN(2);
8
+ exports.TEN = new __1.BN(10);
9
+ exports.TEN_THOUSAND = new __1.BN(10000);
10
+ exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
11
+ exports.TEN_MILLION = exports.TEN_THOUSAND.mul(exports.TEN_THOUSAND);
12
+ exports.MAX_LEVERAGE = new __1.BN(5);
13
+ exports.QUOTE_PRECISION_EXP = new __1.BN(6);
14
+ exports.FUNDING_PAYMENT_PRECISION_EXP = new __1.BN(4);
15
+ exports.MARK_PRICE_PRECISION_EXP = new __1.BN(10);
16
+ exports.FUNDING_RATE_PRECISION_EXP = exports.MARK_PRICE_PRECISION_EXP.mul(exports.FUNDING_PAYMENT_PRECISION_EXP);
17
+ exports.PEG_PRECISION_EXP = new __1.BN(3);
18
+ exports.AMM_RESERVE_PRECISION_EXP = new __1.BN(13);
19
+ exports.BANK_INTEREST_PRECISION = new __1.BN(1000000);
20
+ exports.BANK_CUMULATIVE_INTEREST_PRECISION = new __1.BN(10000000000);
21
+ exports.BANK_UTILIZATION_PRECISION = new __1.BN(1000000);
22
+ exports.BANK_RATE_PRECISION = new __1.BN(1000000);
23
+ exports.BANK_WEIGHT_PRECISION = new __1.BN(100);
24
+ exports.BANK_BALANCE_PRECISION_EXP = new __1.BN(6);
25
+ exports.BANK_BALANCE_PRECISION = new __1.BN(10).pow(exports.BANK_BALANCE_PRECISION_EXP);
26
+ exports.LIQUIDATION_FEE_PRECISION = new __1.BN(1000000);
27
+ exports.QUOTE_PRECISION = new __1.BN(10).pow(exports.QUOTE_PRECISION_EXP);
28
+ exports.MARK_PRICE_PRECISION = new __1.BN(10).pow(exports.MARK_PRICE_PRECISION_EXP);
29
+ exports.FUNDING_PAYMENT_PRECISION = new __1.BN(10).pow(exports.FUNDING_PAYMENT_PRECISION_EXP);
30
+ exports.PEG_PRECISION = new __1.BN(10).pow(exports.PEG_PRECISION_EXP);
31
+ exports.AMM_RESERVE_PRECISION = new __1.BN(10).pow(exports.AMM_RESERVE_PRECISION_EXP);
32
+ exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION;
33
+ exports.BASE_PRECISION_EXP = exports.AMM_RESERVE_PRECISION_EXP;
34
+ exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.div(exports.QUOTE_PRECISION); // 10^7
35
+ exports.PRICE_DIV_PEG = exports.MARK_PRICE_PRECISION.div(exports.PEG_PRECISION); //10^7
36
+ exports.PRICE_TO_QUOTE_PRECISION = exports.MARK_PRICE_PRECISION.div(exports.QUOTE_PRECISION);
37
+ exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.mul(exports.PEG_PRECISION).div(exports.QUOTE_PRECISION); // 10^10
38
+ exports.MARGIN_PRECISION = exports.TEN_THOUSAND;
39
+ exports.BID_ASK_SPREAD_PRECISION = new __1.BN(1000000);
40
+ exports.ONE_YEAR = new __1.BN(31536000);
41
+ exports.QUOTE_ASSET_BANK_INDEX = new __1.BN(0);
@@ -28,6 +28,9 @@ export const BANK_BALANCE_PRECISION_EXP = new BN(6);
28
28
  export const BANK_BALANCE_PRECISION = new BN(10).pow(
29
29
  BANK_BALANCE_PRECISION_EXP
30
30
  );
31
+ export const BANK_IMF_PRECISION_EXP = new BN(6);
32
+
33
+ export const BANK_IMF_PRECISION = new BN(10).pow(BANK_IMF_PRECISION_EXP);
31
34
  export const LIQUIDATION_FEE_PRECISION = new BN(1000000);
32
35
 
33
36
  export const QUOTE_PRECISION = new BN(10).pow(QUOTE_PRECISION_EXP);
@@ -53,7 +53,10 @@ export class EventList<Type extends EventType> {
53
53
  newNode.next = currentNode.next;
54
54
  if (currentNode.next !== undefined) {
55
55
  newNode.next.prev = newNode;
56
+ } else {
57
+ this.tail = newNode;
56
58
  }
59
+
57
60
  currentNode.next = newNode;
58
61
  newNode.prev = currentNode;
59
62
  }
@@ -5,6 +5,7 @@ import {
5
5
  FundingRateRecord,
6
6
  LiquidationRecord,
7
7
  OrderRecord,
8
+ SettlePnlRecord,
8
9
  } from '../index';
9
10
 
10
11
  export type EventSubscriptionOptions = {
@@ -59,6 +60,7 @@ export type EventMap = {
59
60
  LiquidationRecord: Event<LiquidationRecord>;
60
61
  FundingRateRecord: Event<FundingRateRecord>;
61
62
  OrderRecord: Event<OrderRecord>;
63
+ SettlePnlRecord: Event<SettlePnlRecord>;
62
64
  };
63
65
 
64
66
  export type EventType = keyof EventMap;
@@ -10,6 +10,9 @@ class BigNum {
10
10
  this.val = new anchor_1.BN(val);
11
11
  this.precision = new anchor_1.BN(precisionVal);
12
12
  }
13
+ bigNumFromParam(bn) {
14
+ return anchor_1.BN.isBN(bn) ? BigNum.from(bn) : bn;
15
+ }
13
16
  add(bn) {
14
17
  assert_1.assert(bn.precision.eq(this.precision), 'Adding unequal precisions');
15
18
  return BigNum.from(this.val.add(bn.val), this.precision);
@@ -19,7 +22,7 @@ class BigNum {
19
22
  return BigNum.from(this.val.sub(bn.val), this.precision);
20
23
  }
21
24
  mul(bn) {
22
- const mulVal = bn instanceof BigNum ? bn : BigNum.from(bn);
25
+ const mulVal = this.bigNumFromParam(bn);
23
26
  return BigNum.from(this.val.mul(mulVal.val), this.precision.add(mulVal.precision));
24
27
  }
25
28
  /**
@@ -28,12 +31,12 @@ class BigNum {
28
31
  * @returns
29
32
  */
30
33
  scalarMul(bn) {
31
- if (bn instanceof anchor_1.BN)
34
+ if (anchor_1.BN.isBN(bn))
32
35
  return BigNum.from(this.val.mul(bn), this.precision);
33
36
  return BigNum.from(this.val.mul(bn.val), this.precision.add(bn.precision)).shift(bn.precision.neg());
34
37
  }
35
38
  div(bn) {
36
- if (bn instanceof anchor_1.BN)
39
+ if (anchor_1.BN.isBN(bn))
37
40
  return BigNum.from(this.val.div(bn), this.precision);
38
41
  return BigNum.from(this.val.div(bn.val), this.precision.sub(bn.precision));
39
42
  }
@@ -73,35 +76,35 @@ class BigNum {
73
76
  .toPrecision(precision);
74
77
  }
75
78
  gt(bn, ignorePrecision) {
76
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
79
+ const comparisonVal = this.bigNumFromParam(bn);
77
80
  if (!ignorePrecision && !comparisonVal.eq(numericConstants_1.ZERO)) {
78
81
  assert_1.assert(comparisonVal.precision.eq(this.precision), 'Trying to compare numbers with different precision. Yo can opt to ignore precision using the ignorePrecision parameter');
79
82
  }
80
83
  return this.val.gt(comparisonVal.val);
81
84
  }
82
85
  lt(bn, ignorePrecision) {
83
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
86
+ const comparisonVal = this.bigNumFromParam(bn);
84
87
  if (!ignorePrecision && !comparisonVal.val.eq(numericConstants_1.ZERO)) {
85
88
  assert_1.assert(comparisonVal.precision.eq(this.precision), 'Trying to compare numbers with different precision. Yo can opt to ignore precision using the ignorePrecision parameter');
86
89
  }
87
90
  return this.val.lt(comparisonVal.val);
88
91
  }
89
92
  gte(bn, ignorePrecision) {
90
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
93
+ const comparisonVal = this.bigNumFromParam(bn);
91
94
  if (!ignorePrecision && !comparisonVal.val.eq(numericConstants_1.ZERO)) {
92
95
  assert_1.assert(comparisonVal.precision.eq(this.precision), 'Trying to compare numbers with different precision. Yo can opt to ignore precision using the ignorePrecision parameter');
93
96
  }
94
97
  return this.val.gte(comparisonVal.val);
95
98
  }
96
99
  lte(bn, ignorePrecision) {
97
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
100
+ const comparisonVal = this.bigNumFromParam(bn);
98
101
  if (!ignorePrecision && !comparisonVal.val.eq(numericConstants_1.ZERO)) {
99
102
  assert_1.assert(comparisonVal.precision.eq(this.precision), 'Trying to compare numbers with different precision. Yo can opt to ignore precision using the ignorePrecision parameter');
100
103
  }
101
104
  return this.val.lte(comparisonVal.val);
102
105
  }
103
106
  eq(bn, ignorePrecision) {
104
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
107
+ const comparisonVal = this.bigNumFromParam(bn);
105
108
  if (!ignorePrecision && !comparisonVal.val.eq(numericConstants_1.ZERO)) {
106
109
  assert_1.assert(comparisonVal.precision.eq(this.precision), 'Trying to compare numbers with different precision. Yo can opt to ignore precision using the ignorePrecision parameter');
107
110
  }
@@ -149,8 +152,14 @@ class BigNum {
149
152
  // remove leading zeroes
150
153
  printString = printString.replace(/^0+/, '');
151
154
  // add zero if leading delim
152
- if (printString[0] === BigNum.delim)
153
- printString = `0${printString}`;
155
+ if (this.isNeg()) {
156
+ if (printString[1] === BigNum.delim)
157
+ printString = printString.replace('-.', '-0.');
158
+ }
159
+ else {
160
+ if (printString[0] === BigNum.delim)
161
+ printString = `0${printString}`;
162
+ }
154
163
  // remove trailing delim
155
164
  if (printString[printString.length - 1] === BigNum.delim)
156
165
  printString = printString.slice(0, printString.length - 1);
@@ -261,10 +270,27 @@ class BigNum {
261
270
  * @returns
262
271
  */
263
272
  toNotional(useTradePrecision, precisionOverride) {
273
+ var _a;
264
274
  const prefix = `${this.lt(BigNum.zero()) ? `-` : ``}$`;
265
- const val = useTradePrecision || precisionOverride
275
+ const usingCustomPrecision = true && (useTradePrecision || precisionOverride);
276
+ let val = usingCustomPrecision
266
277
  ? this.prettyPrint(useTradePrecision, precisionOverride)
267
278
  : BigNum.fromPrint(this.toFixed(2), new anchor_1.BN(2)).prettyPrint();
279
+ // Append two trailing zeroes if not using custom precision
280
+ if (!usingCustomPrecision) {
281
+ const [_, rightSide] = val.split(BigNum.delim);
282
+ const trailingLength = (_a = rightSide === null || rightSide === void 0 ? void 0 : rightSide.length) !== null && _a !== void 0 ? _a : 0;
283
+ if (trailingLength < 2) {
284
+ const numHasDecimals = this.print().includes(BigNum.delim);
285
+ // Handle case where pretty print won't include the decimal point
286
+ if (trailingLength === 0 && numHasDecimals) {
287
+ val = `${val}.00`;
288
+ }
289
+ else {
290
+ val = `${val}${new Array(2 - trailingLength).fill('0').join('')}`;
291
+ }
292
+ }
293
+ }
268
294
  return `${prefix}${val.replace('-', '')}`;
269
295
  }
270
296
  toMillified(precision = 3) {
@@ -17,6 +17,10 @@ export class BigNum {
17
17
  this.precision = new BN(precisionVal);
18
18
  }
19
19
 
20
+ private bigNumFromParam(bn: BigNum | BN) {
21
+ return BN.isBN(bn) ? BigNum.from(bn) : bn;
22
+ }
23
+
20
24
  public add(bn: BigNum): BigNum {
21
25
  assert(bn.precision.eq(this.precision), 'Adding unequal precisions');
22
26
 
@@ -30,7 +34,7 @@ export class BigNum {
30
34
  }
31
35
 
32
36
  public mul(bn: BigNum | BN): BigNum {
33
- const mulVal = bn instanceof BigNum ? bn : BigNum.from(bn);
37
+ const mulVal = this.bigNumFromParam(bn);
34
38
 
35
39
  return BigNum.from(
36
40
  this.val.mul(mulVal.val),
@@ -44,7 +48,7 @@ export class BigNum {
44
48
  * @returns
45
49
  */
46
50
  public scalarMul(bn: BigNum | BN): BigNum {
47
- if (bn instanceof BN) return BigNum.from(this.val.mul(bn), this.precision);
51
+ if (BN.isBN(bn)) return BigNum.from(this.val.mul(bn), this.precision);
48
52
 
49
53
  return BigNum.from(
50
54
  this.val.mul(bn.val),
@@ -53,7 +57,8 @@ export class BigNum {
53
57
  }
54
58
 
55
59
  public div(bn: BigNum | BN): BigNum {
56
- if (bn instanceof BN) return BigNum.from(this.val.div(bn), this.precision);
60
+ if (BN.isBN(bn)) return BigNum.from(this.val.div(bn), this.precision);
61
+
57
62
  return BigNum.from(this.val.div(bn.val), this.precision.sub(bn.precision));
58
63
  }
59
64
 
@@ -101,7 +106,7 @@ export class BigNum {
101
106
  }
102
107
 
103
108
  public gt(bn: BigNum | BN, ignorePrecision?: boolean): boolean {
104
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
109
+ const comparisonVal = this.bigNumFromParam(bn);
105
110
 
106
111
  if (!ignorePrecision && !comparisonVal.eq(ZERO)) {
107
112
  assert(
@@ -114,7 +119,7 @@ export class BigNum {
114
119
  }
115
120
 
116
121
  public lt(bn: BigNum | BN, ignorePrecision?: boolean): boolean {
117
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
122
+ const comparisonVal = this.bigNumFromParam(bn);
118
123
 
119
124
  if (!ignorePrecision && !comparisonVal.val.eq(ZERO)) {
120
125
  assert(
@@ -127,7 +132,7 @@ export class BigNum {
127
132
  }
128
133
 
129
134
  public gte(bn: BigNum | BN, ignorePrecision?: boolean): boolean {
130
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
135
+ const comparisonVal = this.bigNumFromParam(bn);
131
136
 
132
137
  if (!ignorePrecision && !comparisonVal.val.eq(ZERO)) {
133
138
  assert(
@@ -140,7 +145,7 @@ export class BigNum {
140
145
  }
141
146
 
142
147
  public lte(bn: BigNum | BN, ignorePrecision?: boolean): boolean {
143
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
148
+ const comparisonVal = this.bigNumFromParam(bn);
144
149
 
145
150
  if (!ignorePrecision && !comparisonVal.val.eq(ZERO)) {
146
151
  assert(
@@ -153,7 +158,7 @@ export class BigNum {
153
158
  }
154
159
 
155
160
  public eq(bn: BigNum | BN, ignorePrecision?: boolean): boolean {
156
- const comparisonVal = bn instanceof BigNum ? bn : BigNum.from(bn);
161
+ const comparisonVal = this.bigNumFromParam(bn);
157
162
 
158
163
  if (!ignorePrecision && !comparisonVal.val.eq(ZERO)) {
159
164
  assert(
@@ -225,7 +230,12 @@ export class BigNum {
225
230
  printString = printString.replace(/^0+/, '');
226
231
 
227
232
  // add zero if leading delim
228
- if (printString[0] === BigNum.delim) printString = `0${printString}`;
233
+ if (this.isNeg()) {
234
+ if (printString[1] === BigNum.delim)
235
+ printString = printString.replace('-.', '-0.');
236
+ } else {
237
+ if (printString[0] === BigNum.delim) printString = `0${printString}`;
238
+ }
229
239
 
230
240
  // remove trailing delim
231
241
  if (printString[printString.length - 1] === BigNum.delim)
@@ -392,10 +402,30 @@ export class BigNum {
392
402
  ): string {
393
403
  const prefix = `${this.lt(BigNum.zero()) ? `-` : ``}$`;
394
404
 
395
- const val =
396
- useTradePrecision || precisionOverride
397
- ? this.prettyPrint(useTradePrecision, precisionOverride)
398
- : BigNum.fromPrint(this.toFixed(2), new BN(2)).prettyPrint();
405
+ const usingCustomPrecision =
406
+ true && (useTradePrecision || precisionOverride);
407
+
408
+ let val = usingCustomPrecision
409
+ ? this.prettyPrint(useTradePrecision, precisionOverride)
410
+ : BigNum.fromPrint(this.toFixed(2), new BN(2)).prettyPrint();
411
+
412
+ // Append two trailing zeroes if not using custom precision
413
+ if (!usingCustomPrecision) {
414
+ const [_, rightSide] = val.split(BigNum.delim);
415
+
416
+ const trailingLength = rightSide?.length ?? 0;
417
+
418
+ if (trailingLength < 2) {
419
+ const numHasDecimals = this.print().includes(BigNum.delim);
420
+
421
+ // Handle case where pretty print won't include the decimal point
422
+ if (trailingLength === 0 && numHasDecimals) {
423
+ val = `${val}.00`;
424
+ } else {
425
+ val = `${val}${new Array(2 - trailingLength).fill('0').join('')}`;
426
+ }
427
+ }
428
+ }
399
429
 
400
430
  return `${prefix}${val.replace('-', '')}`;
401
431
  }
@@ -2027,14 +2027,6 @@
2027
2027
  "defined": "PoolBalance"
2028
2028
  }
2029
2029
  },
2030
- {
2031
- "name": "unsettledProfit",
2032
- "type": "u128"
2033
- },
2034
- {
2035
- "name": "unsettledLoss",
2036
- "type": "u128"
2037
- },
2038
2030
  {
2039
2031
  "name": "imfFactor",
2040
2032
  "type": "u128"
@@ -2275,6 +2267,10 @@
2275
2267
  ]
2276
2268
  }
2277
2269
  },
2270
+ {
2271
+ "name": "nextLiquidationId",
2272
+ "type": "u16"
2273
+ },
2278
2274
  {
2279
2275
  "name": "beingLiquidated",
2280
2276
  "type": "bool"
@@ -2413,7 +2409,7 @@
2413
2409
  },
2414
2410
  {
2415
2411
  "name": "quoteAssetAmount",
2416
- "type": "u128"
2412
+ "type": "i128"
2417
2413
  },
2418
2414
  {
2419
2415
  "name": "userPnl",
@@ -2615,11 +2611,19 @@
2615
2611
  },
2616
2612
  {
2617
2613
  "name": "quoteAssetAmountLong",
2618
- "type": "u128"
2614
+ "type": "i128"
2619
2615
  },
2620
2616
  {
2621
2617
  "name": "quoteAssetAmountShort",
2622
- "type": "u128"
2618
+ "type": "i128"
2619
+ },
2620
+ {
2621
+ "name": "quoteEntryAmountLong",
2622
+ "type": "i128"
2623
+ },
2624
+ {
2625
+ "name": "quoteEntryAmountShort",
2626
+ "type": "i128"
2623
2627
  },
2624
2628
  {
2625
2629
  "name": "lastFundingRate",
@@ -3061,11 +3065,11 @@
3061
3065
  },
3062
3066
  {
3063
3067
  "name": "quoteAssetAmount",
3064
- "type": "u128"
3068
+ "type": "i128"
3065
3069
  },
3066
3070
  {
3067
3071
  "name": "quoteEntryAmount",
3068
- "type": "u128"
3072
+ "type": "i128"
3069
3073
  },
3070
3074
  {
3071
3075
  "name": "lastCumulativeFundingRate",
@@ -3083,10 +3087,6 @@
3083
3087
  "name": "openOrders",
3084
3088
  "type": "u128"
3085
3089
  },
3086
- {
3087
- "name": "unsettledPnl",
3088
- "type": "i128"
3089
- },
3090
3090
  {
3091
3091
  "name": "openBids",
3092
3092
  "type": "i128"
@@ -3279,6 +3279,29 @@
3279
3279
  ]
3280
3280
  }
3281
3281
  },
3282
+ {
3283
+ "name": "PositionUpdateType",
3284
+ "type": {
3285
+ "kind": "enum",
3286
+ "variants": [
3287
+ {
3288
+ "name": "Open"
3289
+ },
3290
+ {
3291
+ "name": "Increase"
3292
+ },
3293
+ {
3294
+ "name": "Reduce"
3295
+ },
3296
+ {
3297
+ "name": "Close"
3298
+ },
3299
+ {
3300
+ "name": "Flip"
3301
+ }
3302
+ ]
3303
+ }
3304
+ },
3282
3305
  {
3283
3306
  "name": "LiquidationMultiplierType",
3284
3307
  "type": {
@@ -3813,12 +3836,12 @@
3813
3836
  "index": false
3814
3837
  },
3815
3838
  {
3816
- "name": "makerUnsettledPnl",
3839
+ "name": "makerPnl",
3817
3840
  "type": "i128",
3818
3841
  "index": false
3819
3842
  },
3820
3843
  {
3821
- "name": "takerUnsettledPnl",
3844
+ "name": "takerPnl",
3822
3845
  "type": "i128",
3823
3846
  "index": false
3824
3847
  },
@@ -3923,6 +3946,11 @@
3923
3946
  "type": "i128",
3924
3947
  "index": false
3925
3948
  },
3949
+ {
3950
+ "name": "liquidationId",
3951
+ "type": "u16",
3952
+ "index": false
3953
+ },
3926
3954
  {
3927
3955
  "name": "liquidatePerp",
3928
3956
  "type": {
@@ -3952,6 +3980,46 @@
3952
3980
  "index": false
3953
3981
  }
3954
3982
  ]
3983
+ },
3984
+ {
3985
+ "name": "SettlePnlRecord",
3986
+ "fields": [
3987
+ {
3988
+ "name": "ts",
3989
+ "type": "i64",
3990
+ "index": false
3991
+ },
3992
+ {
3993
+ "name": "marketIndex",
3994
+ "type": "u64",
3995
+ "index": false
3996
+ },
3997
+ {
3998
+ "name": "pnl",
3999
+ "type": "i128",
4000
+ "index": false
4001
+ },
4002
+ {
4003
+ "name": "baseAssetAmount",
4004
+ "type": "i128",
4005
+ "index": false
4006
+ },
4007
+ {
4008
+ "name": "quoteAssetAmountAfter",
4009
+ "type": "i128",
4010
+ "index": false
4011
+ },
4012
+ {
4013
+ "name": "quoteEntryAmount",
4014
+ "type": "i128",
4015
+ "index": false
4016
+ },
4017
+ {
4018
+ "name": "oraclePrice",
4019
+ "type": "i128",
4020
+ "index": false
4021
+ }
4022
+ ]
3955
4023
  }
3956
4024
  ],
3957
4025
  "errors": [
@@ -4457,6 +4525,16 @@
4457
4525
  },
4458
4526
  {
4459
4527
  "code": 6100,
4528
+ "name": "InvalidPositionLastFundingRate",
4529
+ "msg": "InvalidPositionLastFundingRate"
4530
+ },
4531
+ {
4532
+ "code": 6101,
4533
+ "name": "InvalidPositionDelta",
4534
+ "msg": "InvalidPositionDelta"
4535
+ },
4536
+ {
4537
+ "code": 6102,
4460
4538
  "name": "DefaultError",
4461
4539
  "msg": "DefaultError"
4462
4540
  }