@drift-labs/sdk 2.37.1-beta.3 → 2.37.1-beta.5
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/lib/constants/perpMarkets.js +20 -0
- package/lib/math/auction.js +1 -1
- package/lib/types.d.ts +3 -0
- package/lib/types.js +1 -0
- package/lib/user.js +9 -6
- package/package.json +1 -1
- package/src/constants/perpMarkets.ts +20 -0
- package/src/math/auction.ts +1 -1
- package/src/types.ts +1 -0
- package/src/user.ts +14 -6
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.37.1-beta.
|
|
1
|
+
2.37.1-beta.5
|
|
@@ -144,6 +144,16 @@ exports.DevnetPerpMarkets = [
|
|
|
144
144
|
launchTs: 1689270550000,
|
|
145
145
|
oracleSource: __1.OracleSource.PYTH,
|
|
146
146
|
},
|
|
147
|
+
{
|
|
148
|
+
fullName: 'HNT',
|
|
149
|
+
category: ['IoT'],
|
|
150
|
+
symbol: 'HNT-PERP',
|
|
151
|
+
baseAssetSymbol: 'HNT',
|
|
152
|
+
marketIndex: 14,
|
|
153
|
+
oracle: new web3_js_1.PublicKey('6Eg8YdfFJQF2HHonzPUBSCCmyUEhrStg9VBLK957sBe6'),
|
|
154
|
+
launchTs: 16922949550000,
|
|
155
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
156
|
+
},
|
|
147
157
|
];
|
|
148
158
|
exports.MainnetPerpMarkets = [
|
|
149
159
|
{
|
|
@@ -286,6 +296,16 @@ exports.MainnetPerpMarkets = [
|
|
|
286
296
|
launchTs: 1689270550000,
|
|
287
297
|
oracleSource: __1.OracleSource.PYTH,
|
|
288
298
|
},
|
|
299
|
+
{
|
|
300
|
+
fullName: 'HNT',
|
|
301
|
+
category: ['IoT'],
|
|
302
|
+
symbol: 'HNT-PERP',
|
|
303
|
+
baseAssetSymbol: 'HNT',
|
|
304
|
+
marketIndex: 14,
|
|
305
|
+
oracle: new web3_js_1.PublicKey('7moA1i5vQUpfDwSpK6Pw9s56ahB7WFGidtbL2ujWrVvm'),
|
|
306
|
+
launchTs: 16922949550000,
|
|
307
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
308
|
+
},
|
|
289
309
|
];
|
|
290
310
|
exports.PerpMarkets = {
|
|
291
311
|
devnet: exports.DevnetPerpMarkets,
|
package/lib/math/auction.js
CHANGED
|
@@ -64,7 +64,7 @@ function getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice) {
|
|
|
64
64
|
const deltaDenominator = new _1.BN(order.auctionDuration);
|
|
65
65
|
const deltaNumerator = _1.BN.min(slotsElapsed, deltaDenominator);
|
|
66
66
|
if (deltaDenominator.eq(_1.ZERO)) {
|
|
67
|
-
return
|
|
67
|
+
return oraclePrice.add(order.auctionEndPrice);
|
|
68
68
|
}
|
|
69
69
|
let priceOffsetDelta;
|
|
70
70
|
if ((0, types_1.isVariant)(order.direction, 'long')) {
|
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
|
@@ -33,6 +33,7 @@ exports.UserStatus = UserStatus;
|
|
|
33
33
|
UserStatus.ACTIVE = { active: {} };
|
|
34
34
|
UserStatus.BEING_LIQUIDATED = { beingLiquidated: {} };
|
|
35
35
|
UserStatus.BANKRUPT = { bankrupt: {} };
|
|
36
|
+
UserStatus.REDUCE_ONLY = { reduceOnly: {} };
|
|
36
37
|
class ContractType {
|
|
37
38
|
}
|
|
38
39
|
exports.ContractType = ContractType;
|
package/lib/user.js
CHANGED
|
@@ -1606,12 +1606,15 @@ class User {
|
|
|
1606
1606
|
if (canBypass) {
|
|
1607
1607
|
withdrawLimit = _1.BN.max(withdrawLimit, userDepositAmount);
|
|
1608
1608
|
}
|
|
1609
|
-
const
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1609
|
+
const assetWeight = (0, spotBalance_1.calculateAssetWeight)(userDepositAmount, spotMarket, 'Initial');
|
|
1610
|
+
const amountWithdrawable = assetWeight.eq(numericConstants_1.ZERO)
|
|
1611
|
+
? userDepositAmount
|
|
1612
|
+
: freeCollateral
|
|
1613
|
+
.mul(numericConstants_1.MARGIN_PRECISION)
|
|
1614
|
+
.div(assetWeight)
|
|
1615
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
1616
|
+
.div(oracleData.price)
|
|
1617
|
+
.mul(precisionIncrease);
|
|
1615
1618
|
const maxWithdrawValue = _1.BN.min(_1.BN.min(amountWithdrawable, userDepositAmount), withdrawLimit.abs());
|
|
1616
1619
|
if (reduceOnly) {
|
|
1617
1620
|
return _1.BN.max(maxWithdrawValue, numericConstants_1.ZERO);
|
package/package.json
CHANGED
|
@@ -154,6 +154,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
154
154
|
launchTs: 1689270550000,
|
|
155
155
|
oracleSource: OracleSource.PYTH,
|
|
156
156
|
},
|
|
157
|
+
{
|
|
158
|
+
fullName: 'HNT',
|
|
159
|
+
category: ['IoT'],
|
|
160
|
+
symbol: 'HNT-PERP',
|
|
161
|
+
baseAssetSymbol: 'HNT',
|
|
162
|
+
marketIndex: 14,
|
|
163
|
+
oracle: new PublicKey('6Eg8YdfFJQF2HHonzPUBSCCmyUEhrStg9VBLK957sBe6'),
|
|
164
|
+
launchTs: 16922949550000,
|
|
165
|
+
oracleSource: OracleSource.PYTH,
|
|
166
|
+
},
|
|
157
167
|
];
|
|
158
168
|
|
|
159
169
|
export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
@@ -297,6 +307,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
297
307
|
launchTs: 1689270550000,
|
|
298
308
|
oracleSource: OracleSource.PYTH,
|
|
299
309
|
},
|
|
310
|
+
{
|
|
311
|
+
fullName: 'HNT',
|
|
312
|
+
category: ['IoT'],
|
|
313
|
+
symbol: 'HNT-PERP',
|
|
314
|
+
baseAssetSymbol: 'HNT',
|
|
315
|
+
marketIndex: 14,
|
|
316
|
+
oracle: new PublicKey('7moA1i5vQUpfDwSpK6Pw9s56ahB7WFGidtbL2ujWrVvm'),
|
|
317
|
+
launchTs: 16922949550000,
|
|
318
|
+
oracleSource: OracleSource.PYTH,
|
|
319
|
+
},
|
|
300
320
|
];
|
|
301
321
|
|
|
302
322
|
export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
|
package/src/math/auction.ts
CHANGED
|
@@ -79,7 +79,7 @@ export function getAuctionPriceForOracleOffsetAuction(
|
|
|
79
79
|
const deltaNumerator = BN.min(slotsElapsed, deltaDenominator);
|
|
80
80
|
|
|
81
81
|
if (deltaDenominator.eq(ZERO)) {
|
|
82
|
-
return
|
|
82
|
+
return oraclePrice.add(order.auctionEndPrice);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
let priceOffsetDelta;
|
package/src/types.ts
CHANGED
|
@@ -31,6 +31,7 @@ export class UserStatus {
|
|
|
31
31
|
static readonly ACTIVE = { active: {} };
|
|
32
32
|
static readonly BEING_LIQUIDATED = { beingLiquidated: {} };
|
|
33
33
|
static readonly BANKRUPT = { bankrupt: {} };
|
|
34
|
+
static readonly REDUCE_ONLY = { reduceOnly: {} };
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export class ContractType {
|
package/src/user.ts
CHANGED
|
@@ -2937,12 +2937,20 @@ export class User {
|
|
|
2937
2937
|
withdrawLimit = BN.max(withdrawLimit, userDepositAmount);
|
|
2938
2938
|
}
|
|
2939
2939
|
|
|
2940
|
-
const
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2940
|
+
const assetWeight = calculateAssetWeight(
|
|
2941
|
+
userDepositAmount,
|
|
2942
|
+
spotMarket,
|
|
2943
|
+
'Initial'
|
|
2944
|
+
);
|
|
2945
|
+
|
|
2946
|
+
const amountWithdrawable = assetWeight.eq(ZERO)
|
|
2947
|
+
? userDepositAmount
|
|
2948
|
+
: freeCollateral
|
|
2949
|
+
.mul(MARGIN_PRECISION)
|
|
2950
|
+
.div(assetWeight)
|
|
2951
|
+
.mul(PRICE_PRECISION)
|
|
2952
|
+
.div(oracleData.price)
|
|
2953
|
+
.mul(precisionIncrease);
|
|
2946
2954
|
|
|
2947
2955
|
const maxWithdrawValue = BN.min(
|
|
2948
2956
|
BN.min(amountWithdrawable, userDepositAmount),
|