@drift-labs/sdk 2.40.0-beta.3 → 2.40.0-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/idl/drift.json +51 -0
- package/lib/math/amm.js +7 -2
- package/package.json +1 -1
- package/src/idl/drift.json +51 -0
- package/src/math/amm.ts +9 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.40.0-beta.
|
|
1
|
+
2.40.0-beta.5
|
package/lib/idl/drift.json
CHANGED
|
@@ -6314,6 +6314,24 @@
|
|
|
6314
6314
|
]
|
|
6315
6315
|
}
|
|
6316
6316
|
},
|
|
6317
|
+
{
|
|
6318
|
+
"name": "MarketIdentifier",
|
|
6319
|
+
"type": {
|
|
6320
|
+
"kind": "struct",
|
|
6321
|
+
"fields": [
|
|
6322
|
+
{
|
|
6323
|
+
"name": "marketType",
|
|
6324
|
+
"type": {
|
|
6325
|
+
"defined": "MarketType"
|
|
6326
|
+
}
|
|
6327
|
+
},
|
|
6328
|
+
{
|
|
6329
|
+
"name": "marketIndex",
|
|
6330
|
+
"type": "u16"
|
|
6331
|
+
}
|
|
6332
|
+
]
|
|
6333
|
+
}
|
|
6334
|
+
},
|
|
6317
6335
|
{
|
|
6318
6336
|
"name": "HistoricalOracleData",
|
|
6319
6337
|
"type": {
|
|
@@ -8198,6 +8216,34 @@
|
|
|
8198
8216
|
]
|
|
8199
8217
|
}
|
|
8200
8218
|
},
|
|
8219
|
+
{
|
|
8220
|
+
"name": "MarginCalculationMode",
|
|
8221
|
+
"type": {
|
|
8222
|
+
"kind": "enum",
|
|
8223
|
+
"variants": [
|
|
8224
|
+
{
|
|
8225
|
+
"name": "Standard"
|
|
8226
|
+
},
|
|
8227
|
+
{
|
|
8228
|
+
"name": "Liquidation",
|
|
8229
|
+
"fields": [
|
|
8230
|
+
{
|
|
8231
|
+
"name": "margin_buffer",
|
|
8232
|
+
"type": "u128"
|
|
8233
|
+
},
|
|
8234
|
+
{
|
|
8235
|
+
"name": "market_to_track_margin_requirement",
|
|
8236
|
+
"type": {
|
|
8237
|
+
"option": {
|
|
8238
|
+
"defined": "MarketIdentifier"
|
|
8239
|
+
}
|
|
8240
|
+
}
|
|
8241
|
+
}
|
|
8242
|
+
]
|
|
8243
|
+
}
|
|
8244
|
+
]
|
|
8245
|
+
}
|
|
8246
|
+
},
|
|
8201
8247
|
{
|
|
8202
8248
|
"name": "OracleSource",
|
|
8203
8249
|
"type": {
|
|
@@ -10781,6 +10827,11 @@
|
|
|
10781
10827
|
"code": 6254,
|
|
10782
10828
|
"name": "UserReduceOnly",
|
|
10783
10829
|
"msg": "UserReduceOnly"
|
|
10830
|
+
},
|
|
10831
|
+
{
|
|
10832
|
+
"code": 6255,
|
|
10833
|
+
"name": "InvalidMarginCalculation",
|
|
10834
|
+
"msg": "InvalidMarginCalculation"
|
|
10784
10835
|
}
|
|
10785
10836
|
]
|
|
10786
10837
|
}
|
package/lib/math/amm.js
CHANGED
|
@@ -253,8 +253,13 @@ function calculateVolSpreadBN(lastOracleConfPct, reservePrice, markStd, oracleSt
|
|
|
253
253
|
const clampMax = numericConstants_1.PERCENTAGE_PRECISION.mul(new anchor_1.BN(16)).div(new anchor_1.BN(10));
|
|
254
254
|
const longVolSpreadFactor = (0, __1.clampBN)(longIntensity.mul(numericConstants_1.PERCENTAGE_PRECISION).div(anchor_1.BN.max(numericConstants_1.ONE, volume24H)), clampMin, clampMax);
|
|
255
255
|
const shortVolSpreadFactor = (0, __1.clampBN)(shortIntensity.mul(numericConstants_1.PERCENTAGE_PRECISION).div(anchor_1.BN.max(numericConstants_1.ONE, volume24H)), clampMin, clampMax);
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
// only consider confidence interval at full value when above 25 bps
|
|
257
|
+
let confComponent = lastOracleConfPct;
|
|
258
|
+
if (lastOracleConfPct.lte(numericConstants_1.PRICE_PRECISION.div(new anchor_1.BN(400)))) {
|
|
259
|
+
confComponent = lastOracleConfPct.div(new anchor_1.BN(10));
|
|
260
|
+
}
|
|
261
|
+
const longVolSpread = anchor_1.BN.max(confComponent, volSpread.mul(longVolSpreadFactor).div(numericConstants_1.PERCENTAGE_PRECISION));
|
|
262
|
+
const shortVolSpread = anchor_1.BN.max(confComponent, volSpread.mul(shortVolSpreadFactor).div(numericConstants_1.PERCENTAGE_PRECISION));
|
|
258
263
|
return [longVolSpread, shortVolSpread];
|
|
259
264
|
}
|
|
260
265
|
exports.calculateVolSpreadBN = calculateVolSpreadBN;
|
package/package.json
CHANGED
package/src/idl/drift.json
CHANGED
|
@@ -6314,6 +6314,24 @@
|
|
|
6314
6314
|
]
|
|
6315
6315
|
}
|
|
6316
6316
|
},
|
|
6317
|
+
{
|
|
6318
|
+
"name": "MarketIdentifier",
|
|
6319
|
+
"type": {
|
|
6320
|
+
"kind": "struct",
|
|
6321
|
+
"fields": [
|
|
6322
|
+
{
|
|
6323
|
+
"name": "marketType",
|
|
6324
|
+
"type": {
|
|
6325
|
+
"defined": "MarketType"
|
|
6326
|
+
}
|
|
6327
|
+
},
|
|
6328
|
+
{
|
|
6329
|
+
"name": "marketIndex",
|
|
6330
|
+
"type": "u16"
|
|
6331
|
+
}
|
|
6332
|
+
]
|
|
6333
|
+
}
|
|
6334
|
+
},
|
|
6317
6335
|
{
|
|
6318
6336
|
"name": "HistoricalOracleData",
|
|
6319
6337
|
"type": {
|
|
@@ -8198,6 +8216,34 @@
|
|
|
8198
8216
|
]
|
|
8199
8217
|
}
|
|
8200
8218
|
},
|
|
8219
|
+
{
|
|
8220
|
+
"name": "MarginCalculationMode",
|
|
8221
|
+
"type": {
|
|
8222
|
+
"kind": "enum",
|
|
8223
|
+
"variants": [
|
|
8224
|
+
{
|
|
8225
|
+
"name": "Standard"
|
|
8226
|
+
},
|
|
8227
|
+
{
|
|
8228
|
+
"name": "Liquidation",
|
|
8229
|
+
"fields": [
|
|
8230
|
+
{
|
|
8231
|
+
"name": "margin_buffer",
|
|
8232
|
+
"type": "u128"
|
|
8233
|
+
},
|
|
8234
|
+
{
|
|
8235
|
+
"name": "market_to_track_margin_requirement",
|
|
8236
|
+
"type": {
|
|
8237
|
+
"option": {
|
|
8238
|
+
"defined": "MarketIdentifier"
|
|
8239
|
+
}
|
|
8240
|
+
}
|
|
8241
|
+
}
|
|
8242
|
+
]
|
|
8243
|
+
}
|
|
8244
|
+
]
|
|
8245
|
+
}
|
|
8246
|
+
},
|
|
8201
8247
|
{
|
|
8202
8248
|
"name": "OracleSource",
|
|
8203
8249
|
"type": {
|
|
@@ -10781,6 +10827,11 @@
|
|
|
10781
10827
|
"code": 6254,
|
|
10782
10828
|
"name": "UserReduceOnly",
|
|
10783
10829
|
"msg": "UserReduceOnly"
|
|
10830
|
+
},
|
|
10831
|
+
{
|
|
10832
|
+
"code": 6255,
|
|
10833
|
+
"name": "InvalidMarginCalculation",
|
|
10834
|
+
"msg": "InvalidMarginCalculation"
|
|
10784
10835
|
}
|
|
10785
10836
|
]
|
|
10786
10837
|
}
|
package/src/math/amm.ts
CHANGED
|
@@ -471,12 +471,19 @@ export function calculateVolSpreadBN(
|
|
|
471
471
|
clampMax
|
|
472
472
|
);
|
|
473
473
|
|
|
474
|
+
// only consider confidence interval at full value when above 25 bps
|
|
475
|
+
let confComponent = lastOracleConfPct;
|
|
476
|
+
|
|
477
|
+
if (lastOracleConfPct.lte(PRICE_PRECISION.div(new BN(400)))) {
|
|
478
|
+
confComponent = lastOracleConfPct.div(new BN(10));
|
|
479
|
+
}
|
|
480
|
+
|
|
474
481
|
const longVolSpread = BN.max(
|
|
475
|
-
|
|
482
|
+
confComponent,
|
|
476
483
|
volSpread.mul(longVolSpreadFactor).div(PERCENTAGE_PRECISION)
|
|
477
484
|
);
|
|
478
485
|
const shortVolSpread = BN.max(
|
|
479
|
-
|
|
486
|
+
confComponent,
|
|
480
487
|
volSpread.mul(shortVolSpreadFactor).div(PERCENTAGE_PRECISION)
|
|
481
488
|
);
|
|
482
489
|
|