@drift-labs/sdk 0.1.17 → 0.1.18-master.0
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/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 +1 -1
- package/lib/accounts/types.d.ts +3 -3
- 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 +143 -9
- package/lib/math/amm.js +7 -7
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.js +1 -1
- 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 +5 -3
- package/lib/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/accounts/defaultClearingHouseAccountSubscriber.ts +5 -5
- package/src/accounts/types.ts +3 -3
- package/src/admin.ts +27 -2
- package/src/clearingHouse.ts +2 -2
- package/src/idl/clearing_house.json +143 -9
- package/src/types.ts +5 -3
|
@@ -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,90 @@
|
|
|
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
|
+
}
|
|
2020
|
+
},
|
|
1887
2021
|
{
|
|
1888
2022
|
"name": "DepositRecord",
|
|
1889
2023
|
"type": {
|
package/lib/math/amm.js
CHANGED
|
@@ -36,7 +36,7 @@ exports.calculatePrice = calculatePrice;
|
|
|
36
36
|
* @returns quoteAssetReserve and baseAssetReserve after swap. : Precision AMM_RESERVE_PRECISION
|
|
37
37
|
*/
|
|
38
38
|
function calculateAmmReservesAfterSwap(amm, inputAssetType, swapAmount, swapDirection) {
|
|
39
|
-
assert_1.assert(swapAmount.gte(numericConstants_1.ZERO), 'swapAmount must be greater than 0');
|
|
39
|
+
(0, assert_1.assert)(swapAmount.gte(numericConstants_1.ZERO), 'swapAmount must be greater than 0');
|
|
40
40
|
let newQuoteAssetReserve;
|
|
41
41
|
let newBaseAssetReserve;
|
|
42
42
|
if (inputAssetType === 'quote') {
|
|
@@ -105,7 +105,7 @@ function calculateAdjustKCost(market, marketIndex, numerator, denomenator) {
|
|
|
105
105
|
marketIndex: new anchor_1.BN(marketIndex),
|
|
106
106
|
quoteAssetAmount: new anchor_1.BN(0),
|
|
107
107
|
};
|
|
108
|
-
const currentValue = position_1.calculateBaseAssetValue(market, netUserPosition);
|
|
108
|
+
const currentValue = (0, position_1.calculateBaseAssetValue)(market, netUserPosition);
|
|
109
109
|
const marketNewK = Object.assign({}, market);
|
|
110
110
|
marketNewK.amm = Object.assign({}, market.amm);
|
|
111
111
|
marketNewK.amm.baseAssetReserve = market.amm.baseAssetReserve
|
|
@@ -116,7 +116,7 @@ function calculateAdjustKCost(market, marketIndex, numerator, denomenator) {
|
|
|
116
116
|
.div(denomenator);
|
|
117
117
|
marketNewK.amm.sqrtK = market.amm.sqrtK.mul(numerator).div(denomenator);
|
|
118
118
|
netUserPosition.quoteAssetAmount = currentValue;
|
|
119
|
-
const cost = __1.calculatePositionPNL(marketNewK, netUserPosition);
|
|
119
|
+
const cost = (0, __1.calculatePositionPNL)(marketNewK, netUserPosition);
|
|
120
120
|
return cost;
|
|
121
121
|
}
|
|
122
122
|
exports.calculateAdjustKCost = calculateAdjustKCost;
|
|
@@ -135,15 +135,15 @@ function calculateRepegCost(market, marketIndex, newPeg) {
|
|
|
135
135
|
marketIndex: new anchor_1.BN(marketIndex),
|
|
136
136
|
quoteAssetAmount: new anchor_1.BN(0),
|
|
137
137
|
};
|
|
138
|
-
const currentValue = position_1.calculateBaseAssetValue(market, netUserPosition);
|
|
138
|
+
const currentValue = (0, position_1.calculateBaseAssetValue)(market, netUserPosition);
|
|
139
139
|
netUserPosition.quoteAssetAmount = currentValue;
|
|
140
|
-
const prevMarketPrice = __1.calculateMarkPrice(market);
|
|
140
|
+
const prevMarketPrice = (0, __1.calculateMarkPrice)(market);
|
|
141
141
|
const marketNewPeg = Object.assign({}, market);
|
|
142
142
|
marketNewPeg.amm = Object.assign({}, market.amm);
|
|
143
143
|
// const marketNewPeg = JSON.parse(JSON.stringify(market));
|
|
144
144
|
marketNewPeg.amm.pegMultiplier = newPeg;
|
|
145
|
-
console.log('Price moves from', __1.convertToNumber(prevMarketPrice), 'to', __1.convertToNumber(__1.calculateMarkPrice(marketNewPeg)));
|
|
146
|
-
const cost = __1.calculatePositionPNL(marketNewPeg, netUserPosition);
|
|
145
|
+
console.log('Price moves from', (0, __1.convertToNumber)(prevMarketPrice), 'to', (0, __1.convertToNumber)((0, __1.calculateMarkPrice)(marketNewPeg)));
|
|
146
|
+
const cost = (0, __1.calculatePositionPNL)(marketNewPeg, netUserPosition);
|
|
147
147
|
return cost;
|
|
148
148
|
}
|
|
149
149
|
exports.calculateRepegCost = calculateRepegCost;
|
package/lib/math/conversion.js
CHANGED
|
@@ -10,6 +10,6 @@ const convertToNumber = (bigNumber, precision = numericConstants_1.MARK_PRICE_PR
|
|
|
10
10
|
};
|
|
11
11
|
exports.convertToNumber = convertToNumber;
|
|
12
12
|
const convertBaseAssetAmountToNumber = (baseAssetAmount) => {
|
|
13
|
-
return exports.convertToNumber(baseAssetAmount, numericConstants_1.MARK_PRICE_PRECISION.mul(numericConstants_1.PEG_PRECISION));
|
|
13
|
+
return (0, exports.convertToNumber)(baseAssetAmount, numericConstants_1.MARK_PRICE_PRECISION.mul(numericConstants_1.PEG_PRECISION));
|
|
14
14
|
};
|
|
15
15
|
exports.convertBaseAssetAmountToNumber = convertBaseAssetAmountToNumber;
|
package/lib/math/funding.js
CHANGED
|
@@ -40,7 +40,7 @@ function calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustm
|
|
|
40
40
|
const lastMarkPriceTwapTs = market.amm.lastMarkPriceTwapTs;
|
|
41
41
|
const timeSinceLastMarkChange = now.sub(lastMarkPriceTwapTs);
|
|
42
42
|
const markTwapTimeSinceLastUpdate = anchor_1.BN.max(secondsInHour, secondsInHour.sub(timeSinceLastMarkChange));
|
|
43
|
-
const baseAssetPriceWithMantissa = market_1.calculateMarkPrice(market);
|
|
43
|
+
const baseAssetPriceWithMantissa = (0, market_1.calculateMarkPrice)(market);
|
|
44
44
|
const markTwapWithMantissa = markTwapTimeSinceLastUpdate
|
|
45
45
|
.mul(lastMarkTwapWithMantissa)
|
|
46
46
|
.add(timeSinceLastMarkChange.mul(baseAssetPriceWithMantissa))
|
package/lib/math/market.js
CHANGED
|
@@ -9,6 +9,6 @@ const amm_1 = require("./amm");
|
|
|
9
9
|
* @return markPrice : Precision MARK_PRICE_PRECISION
|
|
10
10
|
*/
|
|
11
11
|
function calculateMarkPrice(market) {
|
|
12
|
-
return amm_1.calculatePrice(market.amm.baseAssetReserve, market.amm.quoteAssetReserve, market.amm.pegMultiplier);
|
|
12
|
+
return (0, amm_1.calculatePrice)(market.amm.baseAssetReserve, market.amm.quoteAssetReserve, market.amm.pegMultiplier);
|
|
13
13
|
}
|
|
14
14
|
exports.calculateMarkPrice = calculateMarkPrice;
|
package/lib/math/position.js
CHANGED
|
@@ -22,7 +22,7 @@ function calculateBaseAssetValue(market, userPosition) {
|
|
|
22
22
|
const directionToClose = userPosition.baseAssetAmount.gt(numericConstants_1.ZERO)
|
|
23
23
|
? types_1.PositionDirection.SHORT
|
|
24
24
|
: types_1.PositionDirection.LONG;
|
|
25
|
-
const [newQuoteAssetReserve, _] = amm_1.calculateAmmReservesAfterSwap(market.amm, 'base', userPosition.baseAssetAmount.abs(), amm_1.getSwapDirection('base', directionToClose));
|
|
25
|
+
const [newQuoteAssetReserve, _] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'base', userPosition.baseAssetAmount.abs(), (0, amm_1.getSwapDirection)('base', directionToClose));
|
|
26
26
|
switch (directionToClose) {
|
|
27
27
|
case types_1.PositionDirection.SHORT:
|
|
28
28
|
return market.amm.quoteAssetReserve
|
package/lib/math/trade.js
CHANGED
|
@@ -25,18 +25,18 @@ const MAXPCT = new anchor_1.BN(1000); //percentage units are [0,1000] => [0,1]
|
|
|
25
25
|
* 'newPrice' => the price of the asset after the trade : Precision MARK_PRICE_PRECISION
|
|
26
26
|
*/
|
|
27
27
|
function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quote') {
|
|
28
|
-
const oldPrice = market_1.calculateMarkPrice(market);
|
|
28
|
+
const oldPrice = (0, market_1.calculateMarkPrice)(market);
|
|
29
29
|
if (amount.eq(numericConstants_1.ZERO)) {
|
|
30
30
|
return [numericConstants_1.ZERO, numericConstants_1.ZERO, oldPrice, oldPrice];
|
|
31
31
|
}
|
|
32
32
|
const [acquiredBase, acquiredQuote] = calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType);
|
|
33
|
-
const entryPrice = amm_1.calculatePrice(acquiredBase, acquiredQuote, market.amm.pegMultiplier).mul(new anchor_1.BN(-1));
|
|
34
|
-
const newPrice = amm_1.calculatePrice(market.amm.baseAssetReserve.sub(acquiredBase), market.amm.quoteAssetReserve.sub(acquiredQuote), market.amm.pegMultiplier);
|
|
33
|
+
const entryPrice = (0, amm_1.calculatePrice)(acquiredBase, acquiredQuote, market.amm.pegMultiplier).mul(new anchor_1.BN(-1));
|
|
34
|
+
const newPrice = (0, amm_1.calculatePrice)(market.amm.baseAssetReserve.sub(acquiredBase), market.amm.quoteAssetReserve.sub(acquiredQuote), market.amm.pegMultiplier);
|
|
35
35
|
if (direction == types_1.PositionDirection.SHORT) {
|
|
36
|
-
assert_1.assert(newPrice.lt(oldPrice));
|
|
36
|
+
(0, assert_1.assert)(newPrice.lt(oldPrice));
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
assert_1.assert(oldPrice.lt(newPrice));
|
|
39
|
+
(0, assert_1.assert)(oldPrice.lt(newPrice));
|
|
40
40
|
}
|
|
41
41
|
const pctMaxSlippage = newPrice
|
|
42
42
|
.sub(oldPrice)
|
|
@@ -64,7 +64,7 @@ function calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType
|
|
|
64
64
|
if (amount.eq(numericConstants_1.ZERO)) {
|
|
65
65
|
return [numericConstants_1.ZERO, numericConstants_1.ZERO];
|
|
66
66
|
}
|
|
67
|
-
const [newQuoteAssetReserve, newBaseAssetReserve] = amm_1.calculateAmmReservesAfterSwap(market.amm, inputAssetType, amount, amm_1.getSwapDirection(inputAssetType, direction));
|
|
67
|
+
const [newQuoteAssetReserve, newBaseAssetReserve] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, inputAssetType, amount, (0, amm_1.getSwapDirection)(inputAssetType, direction));
|
|
68
68
|
const acquiredBase = market.amm.baseAssetReserve.sub(newBaseAssetReserve);
|
|
69
69
|
const acquiredQuote = market.amm.quoteAssetReserve.sub(newQuoteAssetReserve);
|
|
70
70
|
return [acquiredBase, acquiredQuote];
|
|
@@ -86,10 +86,10 @@ exports.calculateTradeAcquiredAmounts = calculateTradeAcquiredAmounts;
|
|
|
86
86
|
* ]
|
|
87
87
|
*/
|
|
88
88
|
function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAssetType = 'quote') {
|
|
89
|
-
assert_1.assert(market.amm.baseAssetReserve.gt(numericConstants_1.ZERO));
|
|
90
|
-
assert_1.assert(targetPrice.gt(numericConstants_1.ZERO));
|
|
91
|
-
assert_1.assert(pct.lte(MAXPCT) && pct.gt(numericConstants_1.ZERO));
|
|
92
|
-
const markPriceBefore = market_1.calculateMarkPrice(market);
|
|
89
|
+
(0, assert_1.assert)(market.amm.baseAssetReserve.gt(numericConstants_1.ZERO));
|
|
90
|
+
(0, assert_1.assert)(targetPrice.gt(numericConstants_1.ZERO));
|
|
91
|
+
(0, assert_1.assert)(pct.lte(MAXPCT) && pct.gt(numericConstants_1.ZERO));
|
|
92
|
+
const markPriceBefore = (0, market_1.calculateMarkPrice)(market);
|
|
93
93
|
if (targetPrice.gt(markPriceBefore)) {
|
|
94
94
|
const priceGap = targetPrice.sub(markPriceBefore);
|
|
95
95
|
const priceGapScaled = priceGap.mul(pct).div(MAXPCT);
|
|
@@ -114,11 +114,11 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
114
114
|
let markPriceAfter;
|
|
115
115
|
if (markPriceBefore.gt(targetPrice)) {
|
|
116
116
|
// overestimate y2
|
|
117
|
-
baseAssetReserveAfter = utils_1.squareRootBN(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).sub(biasModifier)).sub(new anchor_1.BN(1));
|
|
117
|
+
baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).sub(biasModifier)).sub(new anchor_1.BN(1));
|
|
118
118
|
quoteAssetReserveAfter = k
|
|
119
119
|
.div(numericConstants_1.MARK_PRICE_PRECISION)
|
|
120
120
|
.div(baseAssetReserveAfter);
|
|
121
|
-
markPriceAfter = amm_1.calculatePrice(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
121
|
+
markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
122
122
|
direction = types_1.PositionDirection.SHORT;
|
|
123
123
|
tradeSize = quoteAssetReserveBefore
|
|
124
124
|
.sub(quoteAssetReserveAfter)
|
|
@@ -129,11 +129,11 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
129
129
|
}
|
|
130
130
|
else if (markPriceBefore.lt(targetPrice)) {
|
|
131
131
|
// underestimate y2
|
|
132
|
-
baseAssetReserveAfter = utils_1.squareRootBN(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).add(biasModifier)).add(new anchor_1.BN(1));
|
|
132
|
+
baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).add(biasModifier)).add(new anchor_1.BN(1));
|
|
133
133
|
quoteAssetReserveAfter = k
|
|
134
134
|
.div(numericConstants_1.MARK_PRICE_PRECISION)
|
|
135
135
|
.div(baseAssetReserveAfter);
|
|
136
|
-
markPriceAfter = amm_1.calculatePrice(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
136
|
+
markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
137
137
|
direction = types_1.PositionDirection.LONG;
|
|
138
138
|
tradeSize = quoteAssetReserveAfter
|
|
139
139
|
.sub(quoteAssetReserveBefore)
|
|
@@ -160,8 +160,8 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
160
160
|
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
161
161
|
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
162
162
|
.div(baseSize.abs());
|
|
163
|
-
assert_1.assert(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
|
|
164
|
-
assert_1.assert(tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000, 'Target Price Calculation incorrect' +
|
|
163
|
+
(0, assert_1.assert)(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
|
|
164
|
+
(0, assert_1.assert)(tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000, 'Target Price Calculation incorrect' +
|
|
165
165
|
tp2.toString() +
|
|
166
166
|
'>=' +
|
|
167
167
|
tp1.toString() +
|
package/lib/pythClient.js
CHANGED
|
@@ -18,7 +18,7 @@ class PythClient {
|
|
|
18
18
|
getPriceData(pricePublicKey) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
const account = yield this.connection.getAccountInfo(pricePublicKey);
|
|
21
|
-
return client_1.parsePriceData(account.data);
|
|
21
|
+
return (0, client_1.parsePriceData)(account.data);
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -38,9 +38,9 @@ export declare type DepositHistoryAccount = {
|
|
|
38
38
|
head: BN;
|
|
39
39
|
depositRecords: DepositRecord[];
|
|
40
40
|
};
|
|
41
|
-
export declare type
|
|
41
|
+
export declare type ExtendedCurveHistoryAccount = {
|
|
42
42
|
head: BN;
|
|
43
|
-
curveRecords:
|
|
43
|
+
curveRecords: ExtendedCurveRecord[];
|
|
44
44
|
};
|
|
45
45
|
export declare type FundingRateHistoryAccount = {
|
|
46
46
|
head: BN;
|
|
@@ -67,7 +67,7 @@ export declare type DepositRecord = {
|
|
|
67
67
|
cumulativeDepositsBefore: BN;
|
|
68
68
|
amount: BN;
|
|
69
69
|
};
|
|
70
|
-
export declare type
|
|
70
|
+
export declare type ExtendedCurveRecord = {
|
|
71
71
|
ts: BN;
|
|
72
72
|
recordId: BN;
|
|
73
73
|
marketIndex: BN;
|
|
@@ -83,6 +83,7 @@ export declare type CurveRecord = {
|
|
|
83
83
|
baseAssetAmountShort: BN;
|
|
84
84
|
baseAssetAmount: BN;
|
|
85
85
|
openInterest: BN;
|
|
86
|
+
oraclePrice: BN;
|
|
86
87
|
};
|
|
87
88
|
export declare type TradeRecord = {
|
|
88
89
|
ts: BN;
|
|
@@ -182,6 +183,7 @@ export declare type StateAccount = {
|
|
|
182
183
|
discountMint: PublicKey;
|
|
183
184
|
oracleGuardRails: OracleGuardRails;
|
|
184
185
|
maxDeposit: BN;
|
|
186
|
+
extendedCurveHistory: PublicKey;
|
|
185
187
|
};
|
|
186
188
|
export declare type MarketsAccount = {
|
|
187
189
|
accountIndex: BN;
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,MAAM,OAAO,CAAC;AAGvB,qBAAa,aAAa;IACzB,MAAM,CAAC,QAAQ,CAAC,GAAG;;MAAe;IAClC,MAAM,CAAC,QAAQ,CAAC,MAAM;;MAAkB;CACxC;AACD,qBAAa,iBAAiB;IAC7B,MAAM,CAAC,QAAQ,CAAC,IAAI;;MAAgB;IACpC,MAAM,CAAC,QAAQ,CAAC,KAAK;;MAAiB;CACtC;AAED,qBAAa,YAAY;IACxB,MAAM,CAAC,QAAQ,CAAC,IAAI;;MAAgB;IACpC,MAAM,CAAC,QAAQ,CAAC,WAAW;;MAAuB;CAClD;AAED,oBAAY,SAAS;IACpB,IAAI,IAAI;IACR,GAAG,IAAI;IACP,IAAI,IAAI;CACR;AAED,oBAAY,gBAAgB,GACzB,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,GAAG,GACH,GAAG,GACH,GAAG,CAAC;AAGP,oBAAY,mBAAmB,GAAG;IACjC,IAAI,EAAE,EAAE,CAAC;IACT,YAAY,EAAE,WAAW,EAAE,CAAC;CAC5B,CAAC;AAEF,oBAAY,qBAAqB,GAAG;IACnC,IAAI,EAAE,EAAE,CAAC;IACT,cAAc,EAAE,aAAa,EAAE,CAAC;CAChC,CAAC;AAEF,oBAAY,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,C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EAAE,CAAC;YACtB,mBAAmB,EAAE,EAAE,CAAC;SACxB,CAAC;KACF,CAAC;IACF,gBAAgB,EAAE;QACjB,uBAAuB,EAAE,EAAE,CAAC;QAC5B,yBAAyB,EAAE,EAAE,CAAC;QAC9B,wBAAwB,EAAE,EAAE,CAAC;QAC7B,0BAA0B,EAAE,EAAE,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC9B,eAAe,EAAE;QAChB,6BAA6B,EAAE,EAAE,CAAC;QAClC,+BAA+B,EAAE,EAAE,CAAC;KACpC,CAAC;IACF,QAAQ,EAAE;QACT,gBAAgB,EAAE,EAAE,CAAC;QACrB,yBAAyB,EAAE,EAAE,CAAC;QAC9B,gBAAgB,EAAE,EAAE,CAAC;KACrB,CAAC;IACF,kBAAkB,EAAE,OAAO,CAAC;CAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
} from './types';
|
|
6
6
|
import { AccountSubscriber, NotSubscribedError } from './types';
|
|
7
7
|
import {
|
|
8
|
-
CurveHistoryAccount,
|
|
9
8
|
DepositHistoryAccount,
|
|
9
|
+
ExtendedCurveHistoryAccount,
|
|
10
10
|
FundingPaymentHistoryAccount,
|
|
11
11
|
FundingRateHistoryAccount,
|
|
12
12
|
LiquidationHistoryAccount,
|
|
@@ -32,7 +32,7 @@ export class DefaultClearingHouseAccountSubscriber
|
|
|
32
32
|
depositHistoryAccountSubscriber?: AccountSubscriber<DepositHistoryAccount>;
|
|
33
33
|
fundingPaymentHistoryAccountSubscriber?: AccountSubscriber<FundingPaymentHistoryAccount>;
|
|
34
34
|
fundingRateHistoryAccountSubscriber?: AccountSubscriber<FundingRateHistoryAccount>;
|
|
35
|
-
curveHistoryAccountSubscriber?: AccountSubscriber<
|
|
35
|
+
curveHistoryAccountSubscriber?: AccountSubscriber<ExtendedCurveHistoryAccount>;
|
|
36
36
|
liquidationHistoryAccountSubscriber?: AccountSubscriber<LiquidationHistoryAccount>;
|
|
37
37
|
|
|
38
38
|
optionalExtraSubscriptions: ClearingHouseAccountTypes[] = [];
|
|
@@ -126,9 +126,9 @@ export class DefaultClearingHouseAccountSubscriber
|
|
|
126
126
|
);
|
|
127
127
|
|
|
128
128
|
this.curveHistoryAccountSubscriber = new WebSocketAccountSubscriber(
|
|
129
|
-
'
|
|
129
|
+
'extendedCurveHistory',
|
|
130
130
|
this.program,
|
|
131
|
-
state.
|
|
131
|
+
state.extendedCurveHistory
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
const extraSusbcribersToUse: {
|
|
@@ -307,7 +307,7 @@ export class DefaultClearingHouseAccountSubscriber
|
|
|
307
307
|
return this.fundingRateHistoryAccountSubscriber.data;
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
public getCurveHistoryAccount():
|
|
310
|
+
public getCurveHistoryAccount(): ExtendedCurveHistoryAccount {
|
|
311
311
|
this.assertIsSubscribed();
|
|
312
312
|
this.assertOptionalIsSubscribed('curveHistoryAccount');
|
|
313
313
|
return this.curveHistoryAccountSubscriber.data;
|
package/src/accounts/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CurveHistoryAccount,
|
|
3
2
|
DepositHistoryAccount,
|
|
3
|
+
ExtendedCurveHistoryAccount,
|
|
4
4
|
FundingPaymentHistoryAccount,
|
|
5
5
|
FundingRateHistoryAccount,
|
|
6
6
|
LiquidationHistoryAccount,
|
|
@@ -34,7 +34,7 @@ export interface ClearingHouseAccountEvents {
|
|
|
34
34
|
tradeHistoryAccountUpdate: (payload: TradeHistoryAccount) => void;
|
|
35
35
|
liquidationHistoryAccountUpdate: (payload: LiquidationHistoryAccount) => void;
|
|
36
36
|
depositHistoryAccountUpdate: (payload: DepositHistoryAccount) => void;
|
|
37
|
-
curveHistoryAccountUpdate: (payload:
|
|
37
|
+
curveHistoryAccountUpdate: (payload: ExtendedCurveHistoryAccount) => void;
|
|
38
38
|
update: void;
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -64,7 +64,7 @@ export interface ClearingHouseAccountSubscriber {
|
|
|
64
64
|
getDepositHistoryAccount(): DepositHistoryAccount;
|
|
65
65
|
getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
|
|
66
66
|
getFundingRateHistoryAccount(): FundingRateHistoryAccount;
|
|
67
|
-
getCurveHistoryAccount():
|
|
67
|
+
getCurveHistoryAccount(): ExtendedCurveHistoryAccount;
|
|
68
68
|
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
69
69
|
}
|
|
70
70
|
|
package/src/admin.ts
CHANGED
|
@@ -153,7 +153,7 @@ export class Admin extends ClearingHouse {
|
|
|
153
153
|
await this.program.account.depositHistory.createInstruction(
|
|
154
154
|
depositHistory
|
|
155
155
|
),
|
|
156
|
-
await this.program.account.
|
|
156
|
+
await this.program.account.extendedCurveHistory.createInstruction(
|
|
157
157
|
curveHistory
|
|
158
158
|
),
|
|
159
159
|
],
|
|
@@ -230,13 +230,38 @@ export class Admin extends ClearingHouse {
|
|
|
230
230
|
marketIndex: BN
|
|
231
231
|
): Promise<TransactionSignature> {
|
|
232
232
|
const state = this.getStateAccount();
|
|
233
|
+
const markets = this.getMarketsAccount();
|
|
234
|
+
const marketData = markets.markets[marketIndex.toNumber()];
|
|
235
|
+
const ammData = marketData.amm;
|
|
236
|
+
|
|
233
237
|
return await this.program.rpc.updateK(sqrtK, marketIndex, {
|
|
234
238
|
accounts: {
|
|
235
239
|
state: await this.getStatePublicKey(),
|
|
236
240
|
admin: this.wallet.publicKey,
|
|
237
241
|
markets: state.markets,
|
|
242
|
+
curveHistory: state.extendedCurveHistory,
|
|
243
|
+
oracle: ammData.oracle,
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public async updateCurveHistory(): Promise<TransactionSignature> {
|
|
249
|
+
const extendedCurveHistory = anchor.web3.Keypair.generate();
|
|
250
|
+
|
|
251
|
+
const state = this.getStateAccount();
|
|
252
|
+
return await this.program.rpc.updateCurveHistory({
|
|
253
|
+
accounts: {
|
|
254
|
+
state: await this.getStatePublicKey(),
|
|
255
|
+
admin: this.wallet.publicKey,
|
|
238
256
|
curveHistory: state.curveHistory,
|
|
257
|
+
extendedCurveHistory: extendedCurveHistory.publicKey,
|
|
239
258
|
},
|
|
259
|
+
instructions: [
|
|
260
|
+
await this.program.account.extendedCurveHistory.createInstruction(
|
|
261
|
+
extendedCurveHistory
|
|
262
|
+
),
|
|
263
|
+
],
|
|
264
|
+
signers: [extendedCurveHistory],
|
|
240
265
|
});
|
|
241
266
|
}
|
|
242
267
|
|
|
@@ -289,7 +314,7 @@ export class Admin extends ClearingHouse {
|
|
|
289
314
|
admin: this.wallet.publicKey,
|
|
290
315
|
oracle: ammData.oracle,
|
|
291
316
|
markets: state.markets,
|
|
292
|
-
curveHistory: state.
|
|
317
|
+
curveHistory: state.extendedCurveHistory,
|
|
293
318
|
},
|
|
294
319
|
});
|
|
295
320
|
}
|
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
|
|