@drift-labs/sdk 0.1.17 → 0.1.18-master.3
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/README.md +2 -1
- package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts +3 -3
- package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts.map +1 -1
- package/lib/accounts/defaultClearingHouseAccountSubscriber.js +2 -2
- package/lib/accounts/defaultUserAccountSubscriber.js +3 -3
- package/lib/accounts/types.d.ts +4 -4
- package/lib/accounts/types.d.ts.map +1 -1
- package/lib/admin.d.ts +1 -0
- package/lib/admin.d.ts.map +1 -1
- package/lib/admin.js +27 -5
- package/lib/clearingHouse.d.ts +2 -2
- package/lib/clearingHouse.d.ts.map +1 -1
- package/lib/clearingHouse.js +9 -9
- package/lib/clearingHouseUser.js +13 -13
- package/lib/examples/makeTradeExample.js +6 -6
- package/lib/idl/clearing_house.json +156 -9
- package/lib/math/amm.js +7 -7
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.d.ts.map +1 -1
- package/lib/math/funding.js +5 -2
- package/lib/math/market.js +1 -1
- package/lib/math/position.js +1 -1
- package/lib/math/trade.js +16 -16
- package/lib/pythClient.js +1 -1
- package/lib/types.d.ts +6 -3
- package/lib/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/accounts/defaultClearingHouseAccountSubscriber.ts +5 -5
- package/src/accounts/defaultUserAccountSubscriber.ts +2 -2
- package/src/accounts/types.ts +4 -4
- package/src/admin.ts +27 -2
- package/src/clearingHouse.ts +2 -2
- package/src/idl/clearing_house.json +156 -9
- package/src/math/funding.ts +5 -1
- package/src/types.ts +6 -3
package/src/clearingHouse.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
MarketsAccount,
|
|
9
9
|
StateAccount,
|
|
10
|
-
CurveHistoryAccount,
|
|
11
10
|
DepositHistoryAccount,
|
|
12
11
|
FundingPaymentHistoryAccount,
|
|
13
12
|
FundingRateHistoryAccount,
|
|
@@ -17,6 +16,7 @@ import {
|
|
|
17
16
|
TradeHistoryAccount,
|
|
18
17
|
UserAccount,
|
|
19
18
|
Market,
|
|
19
|
+
ExtendedCurveHistoryAccount,
|
|
20
20
|
} from './types';
|
|
21
21
|
import * as anchor from '@project-serum/anchor';
|
|
22
22
|
import clearingHouseIDL from './idl/clearing_house.json';
|
|
@@ -200,7 +200,7 @@ export class ClearingHouse {
|
|
|
200
200
|
return this.accountSubscriber.getDepositHistoryAccount();
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
public getCurveHistoryAccount():
|
|
203
|
+
public getCurveHistoryAccount(): ExtendedCurveHistoryAccount {
|
|
204
204
|
return this.accountSubscriber.getCurveHistoryAccount();
|
|
205
205
|
}
|
|
206
206
|
|
|
@@ -939,6 +939,11 @@
|
|
|
939
939
|
"isMut": true,
|
|
940
940
|
"isSigner": false
|
|
941
941
|
},
|
|
942
|
+
{
|
|
943
|
+
"name": "oracle",
|
|
944
|
+
"isMut": false,
|
|
945
|
+
"isSigner": false
|
|
946
|
+
},
|
|
942
947
|
{
|
|
943
948
|
"name": "curveHistory",
|
|
944
949
|
"isMut": true,
|
|
@@ -956,6 +961,32 @@
|
|
|
956
961
|
}
|
|
957
962
|
]
|
|
958
963
|
},
|
|
964
|
+
{
|
|
965
|
+
"name": "updateCurveHistory",
|
|
966
|
+
"accounts": [
|
|
967
|
+
{
|
|
968
|
+
"name": "admin",
|
|
969
|
+
"isMut": false,
|
|
970
|
+
"isSigner": true
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
"name": "state",
|
|
974
|
+
"isMut": true,
|
|
975
|
+
"isSigner": false
|
|
976
|
+
},
|
|
977
|
+
{
|
|
978
|
+
"name": "extendedCurveHistory",
|
|
979
|
+
"isMut": true,
|
|
980
|
+
"isSigner": false
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
"name": "curveHistory",
|
|
984
|
+
"isMut": false,
|
|
985
|
+
"isSigner": false
|
|
986
|
+
}
|
|
987
|
+
],
|
|
988
|
+
"args": []
|
|
989
|
+
},
|
|
959
990
|
{
|
|
960
991
|
"name": "updateMarginRatio",
|
|
961
992
|
"accounts": [
|
|
@@ -1368,7 +1399,7 @@
|
|
|
1368
1399
|
"type": "u64"
|
|
1369
1400
|
},
|
|
1370
1401
|
{
|
|
1371
|
-
"name": "
|
|
1402
|
+
"name": "curveRecords",
|
|
1372
1403
|
"type": {
|
|
1373
1404
|
"array": [
|
|
1374
1405
|
{
|
|
@@ -1381,6 +1412,29 @@
|
|
|
1381
1412
|
]
|
|
1382
1413
|
}
|
|
1383
1414
|
},
|
|
1415
|
+
{
|
|
1416
|
+
"name": "ExtendedCurveHistory",
|
|
1417
|
+
"type": {
|
|
1418
|
+
"kind": "struct",
|
|
1419
|
+
"fields": [
|
|
1420
|
+
{
|
|
1421
|
+
"name": "head",
|
|
1422
|
+
"type": "u64"
|
|
1423
|
+
},
|
|
1424
|
+
{
|
|
1425
|
+
"name": "curveRecords",
|
|
1426
|
+
"type": {
|
|
1427
|
+
"array": [
|
|
1428
|
+
{
|
|
1429
|
+
"defined": "ExtendedCurveRecord"
|
|
1430
|
+
},
|
|
1431
|
+
1024
|
|
1432
|
+
]
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
]
|
|
1436
|
+
}
|
|
1437
|
+
},
|
|
1384
1438
|
{
|
|
1385
1439
|
"name": "DepositHistory",
|
|
1386
1440
|
"type": {
|
|
@@ -1637,6 +1691,10 @@
|
|
|
1637
1691
|
"name": "maxDeposit",
|
|
1638
1692
|
"type": "u128"
|
|
1639
1693
|
},
|
|
1694
|
+
{
|
|
1695
|
+
"name": "extendedCurveHistory",
|
|
1696
|
+
"type": "publicKey"
|
|
1697
|
+
},
|
|
1640
1698
|
{
|
|
1641
1699
|
"name": "padding0",
|
|
1642
1700
|
"type": "u128"
|
|
@@ -1660,14 +1718,6 @@
|
|
|
1660
1718
|
{
|
|
1661
1719
|
"name": "padding5",
|
|
1662
1720
|
"type": "u128"
|
|
1663
|
-
},
|
|
1664
|
-
{
|
|
1665
|
-
"name": "padding6",
|
|
1666
|
-
"type": "u128"
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
"name": "padding7",
|
|
1670
|
-
"type": "u128"
|
|
1671
1721
|
}
|
|
1672
1722
|
]
|
|
1673
1723
|
}
|
|
@@ -1884,6 +1934,103 @@
|
|
|
1884
1934
|
]
|
|
1885
1935
|
}
|
|
1886
1936
|
},
|
|
1937
|
+
{
|
|
1938
|
+
"name": "ExtendedCurveRecord",
|
|
1939
|
+
"type": {
|
|
1940
|
+
"kind": "struct",
|
|
1941
|
+
"fields": [
|
|
1942
|
+
{
|
|
1943
|
+
"name": "ts",
|
|
1944
|
+
"type": "i64"
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
"name": "recordId",
|
|
1948
|
+
"type": "u128"
|
|
1949
|
+
},
|
|
1950
|
+
{
|
|
1951
|
+
"name": "marketIndex",
|
|
1952
|
+
"type": "u64"
|
|
1953
|
+
},
|
|
1954
|
+
{
|
|
1955
|
+
"name": "pegMultiplierBefore",
|
|
1956
|
+
"type": "u128"
|
|
1957
|
+
},
|
|
1958
|
+
{
|
|
1959
|
+
"name": "baseAssetReserveBefore",
|
|
1960
|
+
"type": "u128"
|
|
1961
|
+
},
|
|
1962
|
+
{
|
|
1963
|
+
"name": "quoteAssetReserveBefore",
|
|
1964
|
+
"type": "u128"
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
"name": "sqrtKBefore",
|
|
1968
|
+
"type": "u128"
|
|
1969
|
+
},
|
|
1970
|
+
{
|
|
1971
|
+
"name": "pegMultiplierAfter",
|
|
1972
|
+
"type": "u128"
|
|
1973
|
+
},
|
|
1974
|
+
{
|
|
1975
|
+
"name": "baseAssetReserveAfter",
|
|
1976
|
+
"type": "u128"
|
|
1977
|
+
},
|
|
1978
|
+
{
|
|
1979
|
+
"name": "quoteAssetReserveAfter",
|
|
1980
|
+
"type": "u128"
|
|
1981
|
+
},
|
|
1982
|
+
{
|
|
1983
|
+
"name": "sqrtKAfter",
|
|
1984
|
+
"type": "u128"
|
|
1985
|
+
},
|
|
1986
|
+
{
|
|
1987
|
+
"name": "baseAssetAmountLong",
|
|
1988
|
+
"type": "u128"
|
|
1989
|
+
},
|
|
1990
|
+
{
|
|
1991
|
+
"name": "baseAssetAmountShort",
|
|
1992
|
+
"type": "u128"
|
|
1993
|
+
},
|
|
1994
|
+
{
|
|
1995
|
+
"name": "baseAssetAmount",
|
|
1996
|
+
"type": "i128"
|
|
1997
|
+
},
|
|
1998
|
+
{
|
|
1999
|
+
"name": "openInterest",
|
|
2000
|
+
"type": "u128"
|
|
2001
|
+
},
|
|
2002
|
+
{
|
|
2003
|
+
"name": "totalFee",
|
|
2004
|
+
"type": "u128"
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
"name": "totalFeeMinusDistributions",
|
|
2008
|
+
"type": "u128"
|
|
2009
|
+
},
|
|
2010
|
+
{
|
|
2011
|
+
"name": "adjustmentCost",
|
|
2012
|
+
"type": "i128"
|
|
2013
|
+
},
|
|
2014
|
+
{
|
|
2015
|
+
"name": "oraclePrice",
|
|
2016
|
+
"type": "i128"
|
|
2017
|
+
},
|
|
2018
|
+
{
|
|
2019
|
+
"name": "tradeRecord",
|
|
2020
|
+
"type": "u128"
|
|
2021
|
+
},
|
|
2022
|
+
{
|
|
2023
|
+
"name": "padding",
|
|
2024
|
+
"type": {
|
|
2025
|
+
"array": [
|
|
2026
|
+
"u128",
|
|
2027
|
+
5
|
|
2028
|
+
]
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
]
|
|
2032
|
+
}
|
|
2033
|
+
},
|
|
1887
2034
|
{
|
|
1888
2035
|
"name": "DepositRecord",
|
|
1889
2036
|
"type": {
|
package/src/math/funding.ts
CHANGED
|
@@ -120,6 +120,7 @@ export async function calculateAllEstimatedFundingRate(
|
|
|
120
120
|
.mul(periodAdjustment)
|
|
121
121
|
.div(hoursInDay)
|
|
122
122
|
.div(MARK_PRICE_PRECISION.div(QUOTE_PRECISION));
|
|
123
|
+
|
|
123
124
|
let feePoolSize = calculateFundingPool(market);
|
|
124
125
|
if (interpRateQuote.lt(new BN(0))) {
|
|
125
126
|
feePoolSize = feePoolSize.mul(new BN(-1));
|
|
@@ -289,7 +290,10 @@ export function calculateFundingPool(market: Market): BN {
|
|
|
289
290
|
const totalFeeLB = market.amm.totalFee.div(new BN(2));
|
|
290
291
|
const feePool = BN.max(
|
|
291
292
|
ZERO,
|
|
292
|
-
market.amm.totalFeeMinusDistributions
|
|
293
|
+
market.amm.totalFeeMinusDistributions
|
|
294
|
+
.sub(totalFeeLB)
|
|
295
|
+
.mul(new BN(2))
|
|
296
|
+
.div(new BN(3))
|
|
293
297
|
);
|
|
294
298
|
return feePool;
|
|
295
299
|
}
|
package/src/types.ts
CHANGED
|
@@ -43,9 +43,9 @@ export type DepositHistoryAccount = {
|
|
|
43
43
|
depositRecords: DepositRecord[];
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export type
|
|
46
|
+
export type ExtendedCurveHistoryAccount = {
|
|
47
47
|
head: BN;
|
|
48
|
-
curveRecords:
|
|
48
|
+
curveRecords: ExtendedCurveRecord[];
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export type FundingRateHistoryAccount = {
|
|
@@ -77,7 +77,7 @@ export type DepositRecord = {
|
|
|
77
77
|
amount: BN;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
export type
|
|
80
|
+
export type ExtendedCurveRecord = {
|
|
81
81
|
ts: BN;
|
|
82
82
|
recordId: BN;
|
|
83
83
|
marketIndex: BN;
|
|
@@ -93,6 +93,8 @@ export type CurveRecord = {
|
|
|
93
93
|
baseAssetAmountShort: BN;
|
|
94
94
|
baseAssetAmount: BN;
|
|
95
95
|
openInterest: BN;
|
|
96
|
+
oraclePrice: BN;
|
|
97
|
+
tradeId: BN;
|
|
96
98
|
};
|
|
97
99
|
|
|
98
100
|
export type TradeRecord = {
|
|
@@ -197,6 +199,7 @@ export type StateAccount = {
|
|
|
197
199
|
discountMint: PublicKey;
|
|
198
200
|
oracleGuardRails: OracleGuardRails;
|
|
199
201
|
maxDeposit: BN;
|
|
202
|
+
extendedCurveHistory: PublicKey;
|
|
200
203
|
};
|
|
201
204
|
|
|
202
205
|
export type MarketsAccount = {
|