@drift-labs/sdk 0.2.0-master.26 → 0.2.0-master.28
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/pollingClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
- package/lib/accounts/types.d.ts +2 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
- package/lib/admin.d.ts +5 -2
- package/lib/admin.js +30 -4
- package/lib/clearingHouse.d.ts +3 -0
- package/lib/clearingHouse.js +19 -1
- package/lib/clearingHouseUser.d.ts +11 -9
- package/lib/clearingHouseUser.js +184 -108
- package/lib/config.js +1 -1
- package/lib/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +557 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/idl/clearing_house.json +123 -203
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/math/market.d.ts +3 -2
- package/lib/math/market.js +17 -12
- package/lib/math/orders.d.ts +3 -3
- package/lib/math/orders.js +31 -16
- package/lib/math/position.d.ts +3 -3
- package/lib/math/position.js +23 -16
- package/lib/math/repeg.js +8 -0
- package/lib/math/spotBalance.d.ts +3 -0
- package/lib/math/spotBalance.js +18 -1
- package/lib/math/spotPosition.d.ts +5 -1
- package/lib/math/spotPosition.js +16 -1
- package/lib/types.d.ts +25 -24
- package/lib/types.js +9 -3
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/package.json +6 -3
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
- package/src/accounts/types.ts +1 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
- package/src/admin.ts +50 -8
- package/src/clearingHouse.ts +30 -1
- package/src/clearingHouseUser.ts +366 -167
- package/src/config.ts +1 -1
- package/src/dlob/DLOB.ts +884 -0
- package/src/dlob/DLOBNode.ts +163 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/idl/clearing_house.json +123 -203
- package/src/index.ts +5 -0
- package/src/math/market.ts +22 -13
- package/src/math/orders.ts +29 -21
- package/src/math/position.ts +36 -22
- package/src/math/repeg.ts +9 -0
- package/src/math/spotBalance.ts +26 -0
- package/src/math/spotPosition.ts +42 -1
- package/src/types.ts +26 -24
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/tests/bn/test.ts +2 -3
- package/tests/dlob/helpers.ts +322 -0
- package/tests/dlob/test.ts +2865 -0
- package/my-script/.env +0 -7
- package/my-script/getUserStats.ts +0 -106
- package/my-script/multiConnections.ts +0 -119
- package/my-script/test-regex.ts +0 -11
- package/my-script/utils.ts +0 -52
- package/src/accounts/bulkAccountLoader.js +0 -249
- package/src/accounts/bulkUserStatsSubscription.js +0 -75
- package/src/accounts/bulkUserSubscription.js +0 -75
- package/src/accounts/fetch.js +0 -92
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
- package/src/accounts/pollingOracleSubscriber.js +0 -156
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
- package/src/accounts/pollingUserAccountSubscriber.js +0 -208
- package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
- package/src/accounts/types.js +0 -28
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -138
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
- package/src/addresses/pda.js +0 -186
- package/src/admin.js +0 -1284
- package/src/assert/assert.js +0 -9
- package/src/clearingHouse.js +0 -3433
- package/src/clearingHouseConfig.js +0 -2
- package/src/clearingHouseUser.js +0 -874
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/clearingHouseUserStats.js +0 -115
- package/src/clearingHouseUserStatsConfig.js +0 -2
- package/src/config.js +0 -80
- package/src/constants/numericConstants.js +0 -48
- package/src/constants/perpMarkets.js +0 -42
- package/src/constants/spotMarkets.js +0 -51
- package/src/events/eventList.js +0 -120
- package/src/events/eventSubscriber.js +0 -202
- package/src/events/fetchLogs.js +0 -117
- package/src/events/pollingLogProvider.js +0 -113
- package/src/events/sort.js +0 -41
- package/src/events/txEventCache.js +0 -74
- package/src/events/types.js +0 -25
- package/src/events/webSocketLogProvider.js +0 -76
- package/src/factory/bigNum.js +0 -393
- package/src/factory/oracleClient.js +0 -20
- package/src/index.js +0 -75
- package/src/math/amm.js +0 -422
- package/src/math/auction.js +0 -42
- package/src/math/conversion.js +0 -12
- package/src/math/funding.js +0 -296
- package/src/math/insurance.js +0 -27
- package/src/math/margin.js +0 -77
- package/src/math/market.js +0 -105
- package/src/math/oracles.js +0 -56
- package/src/math/orders.js +0 -153
- package/src/math/position.js +0 -172
- package/src/math/repeg.js +0 -128
- package/src/math/spotBalance.js +0 -176
- package/src/math/spotMarket.js +0 -8
- package/src/math/spotPosition.js +0 -8
- package/src/math/trade.js +0 -260
- package/src/math/utils.js +0 -27
- package/src/oracles/oracleClientCache.js +0 -20
- package/src/oracles/pythClient.js +0 -81
- package/src/oracles/quoteAssetOracleClient.js +0 -63
- package/src/oracles/switchboardClient.js +0 -101
- package/src/oracles/types.js +0 -2
- package/src/orderParams.js +0 -28
- package/src/serum/serumSubscriber.js +0 -102
- package/src/serum/types.js +0 -2
- package/src/slot/SlotSubscriber.js +0 -86
- package/src/token/index.js +0 -38
- package/src/tokenFaucet.js +0 -323
- package/src/tx/retryTxSender.js +0 -280
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -18
- package/src/types.js +0 -216
- package/src/userName.js +0 -20
- package/src/util/computeUnits.js +0 -62
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -61
- package/src/wallet.js +0 -72
|
@@ -1784,6 +1784,31 @@
|
|
|
1784
1784
|
}
|
|
1785
1785
|
]
|
|
1786
1786
|
},
|
|
1787
|
+
{
|
|
1788
|
+
"name": "updateUserCustomMarginRatio",
|
|
1789
|
+
"accounts": [
|
|
1790
|
+
{
|
|
1791
|
+
"name": "user",
|
|
1792
|
+
"isMut": true,
|
|
1793
|
+
"isSigner": false
|
|
1794
|
+
},
|
|
1795
|
+
{
|
|
1796
|
+
"name": "authority",
|
|
1797
|
+
"isMut": false,
|
|
1798
|
+
"isSigner": true
|
|
1799
|
+
}
|
|
1800
|
+
],
|
|
1801
|
+
"args": [
|
|
1802
|
+
{
|
|
1803
|
+
"name": "userId",
|
|
1804
|
+
"type": "u8"
|
|
1805
|
+
},
|
|
1806
|
+
{
|
|
1807
|
+
"name": "marginRatio",
|
|
1808
|
+
"type": "u32"
|
|
1809
|
+
}
|
|
1810
|
+
]
|
|
1811
|
+
},
|
|
1787
1812
|
{
|
|
1788
1813
|
"name": "settleFundingPayment",
|
|
1789
1814
|
"accounts": [
|
|
@@ -1942,7 +1967,11 @@
|
|
|
1942
1967
|
],
|
|
1943
1968
|
"args": [
|
|
1944
1969
|
{
|
|
1945
|
-
"name": "
|
|
1970
|
+
"name": "liquidatorFee",
|
|
1971
|
+
"type": "u128"
|
|
1972
|
+
},
|
|
1973
|
+
{
|
|
1974
|
+
"name": "ifLiquidationFee",
|
|
1946
1975
|
"type": "u128"
|
|
1947
1976
|
}
|
|
1948
1977
|
]
|
|
@@ -1994,7 +2023,11 @@
|
|
|
1994
2023
|
],
|
|
1995
2024
|
"args": [
|
|
1996
2025
|
{
|
|
1997
|
-
"name": "
|
|
2026
|
+
"name": "liquidatorFee",
|
|
2027
|
+
"type": "u128"
|
|
2028
|
+
},
|
|
2029
|
+
{
|
|
2030
|
+
"name": "ifLiquidationFee",
|
|
1998
2031
|
"type": "u128"
|
|
1999
2032
|
}
|
|
2000
2033
|
]
|
|
@@ -2056,10 +2089,6 @@
|
|
|
2056
2089
|
{
|
|
2057
2090
|
"name": "totalIfFactor",
|
|
2058
2091
|
"type": "u32"
|
|
2059
|
-
},
|
|
2060
|
-
{
|
|
2061
|
-
"name": "liquidationIfFactor",
|
|
2062
|
-
"type": "u32"
|
|
2063
2092
|
}
|
|
2064
2093
|
]
|
|
2065
2094
|
},
|
|
@@ -2146,7 +2175,7 @@
|
|
|
2146
2175
|
]
|
|
2147
2176
|
},
|
|
2148
2177
|
{
|
|
2149
|
-
"name": "
|
|
2178
|
+
"name": "updateConcentrationCoef",
|
|
2150
2179
|
"accounts": [
|
|
2151
2180
|
{
|
|
2152
2181
|
"name": "admin",
|
|
@@ -2166,13 +2195,13 @@
|
|
|
2166
2195
|
],
|
|
2167
2196
|
"args": [
|
|
2168
2197
|
{
|
|
2169
|
-
"name": "
|
|
2170
|
-
"type": "
|
|
2198
|
+
"name": "concentrationScale",
|
|
2199
|
+
"type": "u128"
|
|
2171
2200
|
}
|
|
2172
2201
|
]
|
|
2173
2202
|
},
|
|
2174
2203
|
{
|
|
2175
|
-
"name": "
|
|
2204
|
+
"name": "updateCurveUpdateIntensity",
|
|
2176
2205
|
"accounts": [
|
|
2177
2206
|
{
|
|
2178
2207
|
"name": "admin",
|
|
@@ -2192,63 +2221,13 @@
|
|
|
2192
2221
|
],
|
|
2193
2222
|
"args": [
|
|
2194
2223
|
{
|
|
2195
|
-
"name": "
|
|
2196
|
-
"type": "
|
|
2197
|
-
}
|
|
2198
|
-
]
|
|
2199
|
-
},
|
|
2200
|
-
{
|
|
2201
|
-
"name": "updatePartialLiquidationClosePercentage",
|
|
2202
|
-
"accounts": [
|
|
2203
|
-
{
|
|
2204
|
-
"name": "admin",
|
|
2205
|
-
"isMut": false,
|
|
2206
|
-
"isSigner": true
|
|
2207
|
-
},
|
|
2208
|
-
{
|
|
2209
|
-
"name": "state",
|
|
2210
|
-
"isMut": true,
|
|
2211
|
-
"isSigner": false
|
|
2212
|
-
}
|
|
2213
|
-
],
|
|
2214
|
-
"args": [
|
|
2215
|
-
{
|
|
2216
|
-
"name": "numerator",
|
|
2217
|
-
"type": "u128"
|
|
2218
|
-
},
|
|
2219
|
-
{
|
|
2220
|
-
"name": "denominator",
|
|
2221
|
-
"type": "u128"
|
|
2222
|
-
}
|
|
2223
|
-
]
|
|
2224
|
-
},
|
|
2225
|
-
{
|
|
2226
|
-
"name": "updatePartialLiquidationPenaltyPercentage",
|
|
2227
|
-
"accounts": [
|
|
2228
|
-
{
|
|
2229
|
-
"name": "admin",
|
|
2230
|
-
"isMut": false,
|
|
2231
|
-
"isSigner": true
|
|
2232
|
-
},
|
|
2233
|
-
{
|
|
2234
|
-
"name": "state",
|
|
2235
|
-
"isMut": true,
|
|
2236
|
-
"isSigner": false
|
|
2237
|
-
}
|
|
2238
|
-
],
|
|
2239
|
-
"args": [
|
|
2240
|
-
{
|
|
2241
|
-
"name": "numerator",
|
|
2242
|
-
"type": "u128"
|
|
2243
|
-
},
|
|
2244
|
-
{
|
|
2245
|
-
"name": "denominator",
|
|
2246
|
-
"type": "u128"
|
|
2224
|
+
"name": "curveUpdateIntensity",
|
|
2225
|
+
"type": "u8"
|
|
2247
2226
|
}
|
|
2248
2227
|
]
|
|
2249
2228
|
},
|
|
2250
2229
|
{
|
|
2251
|
-
"name": "
|
|
2230
|
+
"name": "updateLpCooldownTime",
|
|
2252
2231
|
"accounts": [
|
|
2253
2232
|
{
|
|
2254
2233
|
"name": "admin",
|
|
@@ -2257,60 +2236,19 @@
|
|
|
2257
2236
|
},
|
|
2258
2237
|
{
|
|
2259
2238
|
"name": "state",
|
|
2260
|
-
"isMut": true,
|
|
2261
|
-
"isSigner": false
|
|
2262
|
-
}
|
|
2263
|
-
],
|
|
2264
|
-
"args": [
|
|
2265
|
-
{
|
|
2266
|
-
"name": "numerator",
|
|
2267
|
-
"type": "u128"
|
|
2268
|
-
},
|
|
2269
|
-
{
|
|
2270
|
-
"name": "denominator",
|
|
2271
|
-
"type": "u128"
|
|
2272
|
-
}
|
|
2273
|
-
]
|
|
2274
|
-
},
|
|
2275
|
-
{
|
|
2276
|
-
"name": "updatePartialLiquidationLiquidatorShareDenominator",
|
|
2277
|
-
"accounts": [
|
|
2278
|
-
{
|
|
2279
|
-
"name": "admin",
|
|
2280
2239
|
"isMut": false,
|
|
2281
|
-
"isSigner": true
|
|
2282
|
-
},
|
|
2283
|
-
{
|
|
2284
|
-
"name": "state",
|
|
2285
|
-
"isMut": true,
|
|
2286
2240
|
"isSigner": false
|
|
2287
|
-
}
|
|
2288
|
-
],
|
|
2289
|
-
"args": [
|
|
2290
|
-
{
|
|
2291
|
-
"name": "denominator",
|
|
2292
|
-
"type": "u64"
|
|
2293
|
-
}
|
|
2294
|
-
]
|
|
2295
|
-
},
|
|
2296
|
-
{
|
|
2297
|
-
"name": "updateFullLiquidationLiquidatorShareDenominator",
|
|
2298
|
-
"accounts": [
|
|
2299
|
-
{
|
|
2300
|
-
"name": "admin",
|
|
2301
|
-
"isMut": false,
|
|
2302
|
-
"isSigner": true
|
|
2303
2241
|
},
|
|
2304
2242
|
{
|
|
2305
|
-
"name": "
|
|
2243
|
+
"name": "market",
|
|
2306
2244
|
"isMut": true,
|
|
2307
2245
|
"isSigner": false
|
|
2308
2246
|
}
|
|
2309
2247
|
],
|
|
2310
2248
|
"args": [
|
|
2311
2249
|
{
|
|
2312
|
-
"name": "
|
|
2313
|
-
"type": "
|
|
2250
|
+
"name": "lpCooldownTime",
|
|
2251
|
+
"type": "i64"
|
|
2314
2252
|
}
|
|
2315
2253
|
]
|
|
2316
2254
|
},
|
|
@@ -2719,7 +2657,7 @@
|
|
|
2719
2657
|
]
|
|
2720
2658
|
},
|
|
2721
2659
|
{
|
|
2722
|
-
"name": "
|
|
2660
|
+
"name": "updatePerpAuctionDuration",
|
|
2723
2661
|
"accounts": [
|
|
2724
2662
|
{
|
|
2725
2663
|
"name": "admin",
|
|
@@ -2734,11 +2672,28 @@
|
|
|
2734
2672
|
],
|
|
2735
2673
|
"args": [
|
|
2736
2674
|
{
|
|
2737
|
-
"name": "
|
|
2675
|
+
"name": "minPerpAuctionDuration",
|
|
2738
2676
|
"type": "u8"
|
|
2677
|
+
}
|
|
2678
|
+
]
|
|
2679
|
+
},
|
|
2680
|
+
{
|
|
2681
|
+
"name": "updateSpotAuctionDuration",
|
|
2682
|
+
"accounts": [
|
|
2683
|
+
{
|
|
2684
|
+
"name": "admin",
|
|
2685
|
+
"isMut": false,
|
|
2686
|
+
"isSigner": true
|
|
2739
2687
|
},
|
|
2740
2688
|
{
|
|
2741
|
-
"name": "
|
|
2689
|
+
"name": "state",
|
|
2690
|
+
"isMut": true,
|
|
2691
|
+
"isSigner": false
|
|
2692
|
+
}
|
|
2693
|
+
],
|
|
2694
|
+
"args": [
|
|
2695
|
+
{
|
|
2696
|
+
"name": "defaultSpotAuctionDuration",
|
|
2742
2697
|
"type": "u8"
|
|
2743
2698
|
}
|
|
2744
2699
|
]
|
|
@@ -3173,7 +3128,11 @@
|
|
|
3173
3128
|
"type": "u128"
|
|
3174
3129
|
},
|
|
3175
3130
|
{
|
|
3176
|
-
"name": "
|
|
3131
|
+
"name": "liquidatorFee",
|
|
3132
|
+
"type": "u128"
|
|
3133
|
+
},
|
|
3134
|
+
{
|
|
3135
|
+
"name": "ifLiquidationFee",
|
|
3177
3136
|
"type": "u128"
|
|
3178
3137
|
},
|
|
3179
3138
|
{
|
|
@@ -3363,12 +3322,12 @@
|
|
|
3363
3322
|
"type": "u128"
|
|
3364
3323
|
},
|
|
3365
3324
|
{
|
|
3366
|
-
"name": "
|
|
3325
|
+
"name": "liquidatorFee",
|
|
3367
3326
|
"type": "u128"
|
|
3368
3327
|
},
|
|
3369
3328
|
{
|
|
3370
|
-
"name": "
|
|
3371
|
-
"type": "
|
|
3329
|
+
"name": "ifLiquidationFee",
|
|
3330
|
+
"type": "u128"
|
|
3372
3331
|
},
|
|
3373
3332
|
{
|
|
3374
3333
|
"name": "withdrawGuardThreshold",
|
|
@@ -3488,50 +3447,6 @@
|
|
|
3488
3447
|
"name": "insuranceVault",
|
|
3489
3448
|
"type": "publicKey"
|
|
3490
3449
|
},
|
|
3491
|
-
{
|
|
3492
|
-
"name": "marginRatioInitial",
|
|
3493
|
-
"type": "u128"
|
|
3494
|
-
},
|
|
3495
|
-
{
|
|
3496
|
-
"name": "marginRatioMaintenance",
|
|
3497
|
-
"type": "u128"
|
|
3498
|
-
},
|
|
3499
|
-
{
|
|
3500
|
-
"name": "marginRatioPartial",
|
|
3501
|
-
"type": "u128"
|
|
3502
|
-
},
|
|
3503
|
-
{
|
|
3504
|
-
"name": "partialLiquidationClosePercentageNumerator",
|
|
3505
|
-
"type": "u128"
|
|
3506
|
-
},
|
|
3507
|
-
{
|
|
3508
|
-
"name": "partialLiquidationClosePercentageDenominator",
|
|
3509
|
-
"type": "u128"
|
|
3510
|
-
},
|
|
3511
|
-
{
|
|
3512
|
-
"name": "partialLiquidationPenaltyPercentageNumerator",
|
|
3513
|
-
"type": "u128"
|
|
3514
|
-
},
|
|
3515
|
-
{
|
|
3516
|
-
"name": "partialLiquidationPenaltyPercentageDenominator",
|
|
3517
|
-
"type": "u128"
|
|
3518
|
-
},
|
|
3519
|
-
{
|
|
3520
|
-
"name": "fullLiquidationPenaltyPercentageNumerator",
|
|
3521
|
-
"type": "u128"
|
|
3522
|
-
},
|
|
3523
|
-
{
|
|
3524
|
-
"name": "fullLiquidationPenaltyPercentageDenominator",
|
|
3525
|
-
"type": "u128"
|
|
3526
|
-
},
|
|
3527
|
-
{
|
|
3528
|
-
"name": "partialLiquidationLiquidatorShareDenominator",
|
|
3529
|
-
"type": "u64"
|
|
3530
|
-
},
|
|
3531
|
-
{
|
|
3532
|
-
"name": "fullLiquidationLiquidatorShareDenominator",
|
|
3533
|
-
"type": "u64"
|
|
3534
|
-
},
|
|
3535
3450
|
{
|
|
3536
3451
|
"name": "perpFeeStructure",
|
|
3537
3452
|
"type": {
|
|
@@ -3575,25 +3490,21 @@
|
|
|
3575
3490
|
"type": "u8"
|
|
3576
3491
|
},
|
|
3577
3492
|
{
|
|
3578
|
-
"name": "
|
|
3493
|
+
"name": "defaultMarketOrderTimeInForce",
|
|
3579
3494
|
"type": "u8"
|
|
3580
3495
|
},
|
|
3581
3496
|
{
|
|
3582
|
-
"name": "
|
|
3497
|
+
"name": "defaultSpotAuctionDuration",
|
|
3583
3498
|
"type": "u8"
|
|
3584
3499
|
},
|
|
3585
3500
|
{
|
|
3586
|
-
"name": "
|
|
3587
|
-
"type": "
|
|
3501
|
+
"name": "liquidationMarginBufferRatio",
|
|
3502
|
+
"type": "u32"
|
|
3588
3503
|
},
|
|
3589
3504
|
{
|
|
3590
3505
|
"name": "settlementDuration",
|
|
3591
3506
|
"type": "u16"
|
|
3592
3507
|
},
|
|
3593
|
-
{
|
|
3594
|
-
"name": "liquidationMarginBufferRatio",
|
|
3595
|
-
"type": "u32"
|
|
3596
|
-
},
|
|
3597
3508
|
{
|
|
3598
3509
|
"name": "signer",
|
|
3599
3510
|
"type": "publicKey"
|
|
@@ -3601,14 +3512,6 @@
|
|
|
3601
3512
|
{
|
|
3602
3513
|
"name": "signerNonce",
|
|
3603
3514
|
"type": "u8"
|
|
3604
|
-
},
|
|
3605
|
-
{
|
|
3606
|
-
"name": "padding0",
|
|
3607
|
-
"type": "u128"
|
|
3608
|
-
},
|
|
3609
|
-
{
|
|
3610
|
-
"name": "padding1",
|
|
3611
|
-
"type": "u128"
|
|
3612
3515
|
}
|
|
3613
3516
|
]
|
|
3614
3517
|
}
|
|
@@ -3683,6 +3586,10 @@
|
|
|
3683
3586
|
{
|
|
3684
3587
|
"name": "bankrupt",
|
|
3685
3588
|
"type": "bool"
|
|
3589
|
+
},
|
|
3590
|
+
{
|
|
3591
|
+
"name": "customMarginRatio",
|
|
3592
|
+
"type": "u32"
|
|
3686
3593
|
}
|
|
3687
3594
|
]
|
|
3688
3595
|
}
|
|
@@ -3812,25 +3719,27 @@
|
|
|
3812
3719
|
"defined": "OrderTriggerCondition"
|
|
3813
3720
|
}
|
|
3814
3721
|
},
|
|
3815
|
-
{
|
|
3816
|
-
"name": "positionLimit",
|
|
3817
|
-
"type": "u128"
|
|
3818
|
-
},
|
|
3819
3722
|
{
|
|
3820
3723
|
"name": "oraclePriceOffset",
|
|
3821
3724
|
"type": "i128"
|
|
3822
3725
|
},
|
|
3823
3726
|
{
|
|
3824
3727
|
"name": "auctionDuration",
|
|
3825
|
-
"type":
|
|
3728
|
+
"type": {
|
|
3729
|
+
"option": "u8"
|
|
3730
|
+
}
|
|
3826
3731
|
},
|
|
3827
3732
|
{
|
|
3828
|
-
"name": "
|
|
3829
|
-
"type":
|
|
3733
|
+
"name": "timeInForce",
|
|
3734
|
+
"type": {
|
|
3735
|
+
"option": "u8"
|
|
3736
|
+
}
|
|
3830
3737
|
},
|
|
3831
3738
|
{
|
|
3832
|
-
"name": "
|
|
3833
|
-
"type":
|
|
3739
|
+
"name": "auctionStartPrice",
|
|
3740
|
+
"type": {
|
|
3741
|
+
"option": "u128"
|
|
3742
|
+
}
|
|
3834
3743
|
}
|
|
3835
3744
|
]
|
|
3836
3745
|
}
|
|
@@ -3844,16 +3753,6 @@
|
|
|
3844
3753
|
"name": "marketIndex",
|
|
3845
3754
|
"type": "u64"
|
|
3846
3755
|
},
|
|
3847
|
-
{
|
|
3848
|
-
"name": "orderIds",
|
|
3849
|
-
"type": {
|
|
3850
|
-
"vec": "u64"
|
|
3851
|
-
}
|
|
3852
|
-
},
|
|
3853
|
-
{
|
|
3854
|
-
"name": "canceledOrdersFee",
|
|
3855
|
-
"type": "u128"
|
|
3856
|
-
},
|
|
3857
3756
|
{
|
|
3858
3757
|
"name": "oraclePrice",
|
|
3859
3758
|
"type": "i128"
|
|
@@ -3889,6 +3788,10 @@
|
|
|
3889
3788
|
{
|
|
3890
3789
|
"name": "liquidatorOrderId",
|
|
3891
3790
|
"type": "u64"
|
|
3791
|
+
},
|
|
3792
|
+
{
|
|
3793
|
+
"name": "ifFee",
|
|
3794
|
+
"type": "u64"
|
|
3892
3795
|
}
|
|
3893
3796
|
]
|
|
3894
3797
|
}
|
|
@@ -3921,6 +3824,10 @@
|
|
|
3921
3824
|
{
|
|
3922
3825
|
"name": "liabilityTransfer",
|
|
3923
3826
|
"type": "u128"
|
|
3827
|
+
},
|
|
3828
|
+
{
|
|
3829
|
+
"name": "ifFee",
|
|
3830
|
+
"type": "u64"
|
|
3924
3831
|
}
|
|
3925
3832
|
]
|
|
3926
3833
|
}
|
|
@@ -4104,6 +4011,10 @@
|
|
|
4104
4011
|
"name": "quoteAssetReserve",
|
|
4105
4012
|
"type": "u128"
|
|
4106
4013
|
},
|
|
4014
|
+
{
|
|
4015
|
+
"name": "concentrationCoef",
|
|
4016
|
+
"type": "u128"
|
|
4017
|
+
},
|
|
4107
4018
|
{
|
|
4108
4019
|
"name": "minBaseAssetReserve",
|
|
4109
4020
|
"type": "u128"
|
|
@@ -4328,6 +4239,10 @@
|
|
|
4328
4239
|
"name": "netRevenueSinceLastFunding",
|
|
4329
4240
|
"type": "i64"
|
|
4330
4241
|
},
|
|
4242
|
+
{
|
|
4243
|
+
"name": "totalLiquidationFee",
|
|
4244
|
+
"type": "u128"
|
|
4245
|
+
},
|
|
4331
4246
|
{
|
|
4332
4247
|
"name": "feePool",
|
|
4333
4248
|
"type": {
|
|
@@ -4461,7 +4376,7 @@
|
|
|
4461
4376
|
}
|
|
4462
4377
|
},
|
|
4463
4378
|
{
|
|
4464
|
-
"name": "
|
|
4379
|
+
"name": "flatFillerFee",
|
|
4465
4380
|
"type": "u128"
|
|
4466
4381
|
}
|
|
4467
4382
|
]
|
|
@@ -4671,7 +4586,7 @@
|
|
|
4671
4586
|
"type": "i128"
|
|
4672
4587
|
},
|
|
4673
4588
|
{
|
|
4674
|
-
"name": "
|
|
4589
|
+
"name": "settledPnl",
|
|
4675
4590
|
"type": "i64"
|
|
4676
4591
|
},
|
|
4677
4592
|
{
|
|
@@ -4835,13 +4750,8 @@
|
|
|
4835
4750
|
"type": "u8"
|
|
4836
4751
|
},
|
|
4837
4752
|
{
|
|
4838
|
-
"name": "
|
|
4839
|
-
"type":
|
|
4840
|
-
"array": [
|
|
4841
|
-
"u16",
|
|
4842
|
-
3
|
|
4843
|
-
]
|
|
4844
|
-
}
|
|
4753
|
+
"name": "timeInForce",
|
|
4754
|
+
"type": "u8"
|
|
4845
4755
|
}
|
|
4846
4756
|
]
|
|
4847
4757
|
}
|
|
@@ -5008,7 +4918,7 @@
|
|
|
5008
4918
|
"name": "MarketOrderFilledToLimitPrice"
|
|
5009
4919
|
},
|
|
5010
4920
|
{
|
|
5011
|
-
"name": "
|
|
4921
|
+
"name": "OrderExpired"
|
|
5012
4922
|
},
|
|
5013
4923
|
{
|
|
5014
4924
|
"name": "CanceledForLiquidation"
|
|
@@ -5126,6 +5036,9 @@
|
|
|
5126
5036
|
},
|
|
5127
5037
|
{
|
|
5128
5038
|
"name": "Settlement"
|
|
5039
|
+
},
|
|
5040
|
+
{
|
|
5041
|
+
"name": "Delisted"
|
|
5129
5042
|
}
|
|
5130
5043
|
]
|
|
5131
5044
|
}
|
|
@@ -5959,6 +5872,13 @@
|
|
|
5959
5872
|
"type": "bool",
|
|
5960
5873
|
"index": false
|
|
5961
5874
|
},
|
|
5875
|
+
{
|
|
5876
|
+
"name": "canceledOrderIds",
|
|
5877
|
+
"type": {
|
|
5878
|
+
"vec": "u64"
|
|
5879
|
+
},
|
|
5880
|
+
"index": false
|
|
5881
|
+
},
|
|
5962
5882
|
{
|
|
5963
5883
|
"name": "liquidatePerp",
|
|
5964
5884
|
"type": {
|
package/lib/index.d.ts
CHANGED
|
@@ -57,4 +57,9 @@ export * from './util/tps';
|
|
|
57
57
|
export * from './math/spotBalance';
|
|
58
58
|
export * from './constants/spotMarkets';
|
|
59
59
|
export * from './clearingHouseConfig';
|
|
60
|
+
export * from './dlob/DLOB';
|
|
61
|
+
export * from './dlob/DLOBNode';
|
|
62
|
+
export * from './dlob/NodeList';
|
|
63
|
+
export * from './userMap/userMap';
|
|
64
|
+
export * from './userMap/userStatsMap';
|
|
60
65
|
export { BN, PublicKey, pyth };
|
package/lib/index.js
CHANGED
|
@@ -80,3 +80,8 @@ __exportStar(require("./util/tps"), exports);
|
|
|
80
80
|
__exportStar(require("./math/spotBalance"), exports);
|
|
81
81
|
__exportStar(require("./constants/spotMarkets"), exports);
|
|
82
82
|
__exportStar(require("./clearingHouseConfig"), exports);
|
|
83
|
+
__exportStar(require("./dlob/DLOB"), exports);
|
|
84
|
+
__exportStar(require("./dlob/DLOBNode"), exports);
|
|
85
|
+
__exportStar(require("./dlob/NodeList"), exports);
|
|
86
|
+
__exportStar(require("./userMap/userMap"), exports);
|
|
87
|
+
__exportStar(require("./userMap/userStatsMap"), exports);
|
package/lib/math/market.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function calculateBidPrice(market: PerpMarketAccount, oraclePrice
|
|
|
20
20
|
* Calculates market ask price
|
|
21
21
|
*
|
|
22
22
|
* @param market
|
|
23
|
-
* @return
|
|
23
|
+
* @return askPrice : Precision MARK_PRICE_PRECISION
|
|
24
24
|
*/
|
|
25
25
|
export declare function calculateAskPrice(market: PerpMarketAccount, oraclePriceData: OraclePriceData): BN;
|
|
26
26
|
export declare function calculateNewMarketAfterTrade(baseAssetAmount: BN, direction: PositionDirection, market: PerpMarketAccount): PerpMarketAccount;
|
|
@@ -29,4 +29,5 @@ export declare function calculateOracleSpread(price: BN, oraclePriceData: Oracle
|
|
|
29
29
|
export declare function calculateMarketMarginRatio(market: PerpMarketAccount, size: BN, marginCategory: MarginCategory): number;
|
|
30
30
|
export declare function calculateUnrealizedAssetWeight(market: PerpMarketAccount, quoteSpotMarket: SpotMarketAccount, unrealizedPnl: BN, marginCategory: MarginCategory, oraclePriceData: OraclePriceData): BN;
|
|
31
31
|
export declare function calculateMarketAvailablePNL(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount): BN;
|
|
32
|
-
export declare function
|
|
32
|
+
export declare function calculateNetUserPnl(perpMarket: PerpMarketAccount, oraclePriceData: OraclePriceData): BN;
|
|
33
|
+
export declare function calculateNetUserPnlImbalance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount, oraclePriceData: OraclePriceData): BN;
|
package/lib/math/market.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.calculateNetUserPnlImbalance = exports.calculateNetUserPnl = exports.calculateMarketAvailablePNL = exports.calculateUnrealizedAssetWeight = exports.calculateMarketMarginRatio = exports.calculateOracleSpread = exports.calculateMarkOracleSpread = exports.calculateNewMarketAfterTrade = exports.calculateAskPrice = exports.calculateBidPrice = exports.calculateMarkPrice = void 0;
|
|
4
4
|
const anchor_1 = require("@project-serum/anchor");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const amm_1 = require("./amm");
|
|
@@ -33,7 +33,7 @@ exports.calculateBidPrice = calculateBidPrice;
|
|
|
33
33
|
* Calculates market ask price
|
|
34
34
|
*
|
|
35
35
|
* @param market
|
|
36
|
-
* @return
|
|
36
|
+
* @return askPrice : Precision MARK_PRICE_PRECISION
|
|
37
37
|
*/
|
|
38
38
|
function calculateAskPrice(market, oraclePriceData) {
|
|
39
39
|
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, types_1.PositionDirection.LONG, oraclePriceData);
|
|
@@ -78,7 +78,7 @@ function calculateUnrealizedAssetWeight(market, quoteSpotMarket, unrealizedPnl,
|
|
|
78
78
|
case 'Initial':
|
|
79
79
|
assetWeight = new anchor_1.BN(market.unrealizedInitialAssetWeight);
|
|
80
80
|
if (market.unrealizedMaxImbalance.gt(numericConstants_1.ZERO)) {
|
|
81
|
-
const netUnsettledPnl =
|
|
81
|
+
const netUnsettledPnl = calculateNetUserPnlImbalance(market, quoteSpotMarket, oraclePriceData);
|
|
82
82
|
if (netUnsettledPnl.gt(market.unrealizedMaxImbalance)) {
|
|
83
83
|
assetWeight = assetWeight
|
|
84
84
|
.mul(market.unrealizedMaxImbalance)
|
|
@@ -98,17 +98,22 @@ function calculateMarketAvailablePNL(perpMarket, spotMarket) {
|
|
|
98
98
|
return (0, spotBalance_1.getTokenAmount)(perpMarket.pnlPool.balance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
99
99
|
}
|
|
100
100
|
exports.calculateMarketAvailablePNL = calculateMarketAvailablePNL;
|
|
101
|
-
function
|
|
102
|
-
const netUserPositionValue =
|
|
101
|
+
function calculateNetUserPnl(perpMarket, oraclePriceData) {
|
|
102
|
+
const netUserPositionValue = perpMarket.amm.netBaseAssetAmount
|
|
103
103
|
.mul(oraclePriceData.price)
|
|
104
104
|
.div(numericConstants_1.BASE_PRECISION)
|
|
105
105
|
.div(numericConstants_1.PRICE_TO_QUOTE_PRECISION);
|
|
106
|
-
const netUserCostBasis =
|
|
107
|
-
.add(
|
|
108
|
-
.sub(
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
const netUserCostBasis = perpMarket.amm.quoteAssetAmountLong
|
|
107
|
+
.add(perpMarket.amm.quoteAssetAmountShort)
|
|
108
|
+
.sub(perpMarket.amm.cumulativeSocialLoss);
|
|
109
|
+
const netUserPnl = netUserPositionValue.add(netUserCostBasis);
|
|
110
|
+
return netUserPnl;
|
|
111
|
+
}
|
|
112
|
+
exports.calculateNetUserPnl = calculateNetUserPnl;
|
|
113
|
+
function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData) {
|
|
114
|
+
const netUserPnl = calculateNetUserPnl(perpMarket, oraclePriceData);
|
|
115
|
+
const pnlPool = (0, spotBalance_1.getTokenAmount)(perpMarket.pnlPool.balance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
116
|
+
const imbalance = netUserPnl.sub(pnlPool);
|
|
112
117
|
return imbalance;
|
|
113
118
|
}
|
|
114
|
-
exports.
|
|
119
|
+
exports.calculateNetUserPnlImbalance = calculateNetUserPnlImbalance;
|
package/lib/math/orders.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare function isOrderRiskIncreasing(user: ClearingHouseUser, order: Or
|
|
|
7
7
|
export declare function isOrderRiskIncreasingInSameDirection(user: ClearingHouseUser, order: Order): boolean;
|
|
8
8
|
export declare function isOrderReduceOnly(user: ClearingHouseUser, order: Order): boolean;
|
|
9
9
|
export declare function standardizeBaseAssetAmount(baseAssetAmount: BN, stepSize: BN): BN;
|
|
10
|
-
export declare function getLimitPrice(order: Order,
|
|
11
|
-
export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number
|
|
10
|
+
export declare function getLimitPrice(order: Order, oraclePriceData: OraclePriceData, slot: number, perpMarket?: PerpMarketAccount): BN;
|
|
11
|
+
export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number): boolean;
|
|
12
12
|
export declare function calculateBaseAssetAmountForAmmToFulfill(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number): BN;
|
|
13
13
|
export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, market: PerpMarketAccount, limitPrice: BN, oraclePriceData: OraclePriceData): BN;
|
|
14
|
-
export declare function isOrderExpired(order: Order, slot: number
|
|
14
|
+
export declare function isOrderExpired(order: Order, slot: number): boolean;
|