@drift-labs/sdk 2.20.0-beta.0 → 2.20.0-beta.2
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/bulkAccountLoader.d.ts +2 -1
- package/lib/accounts/bulkAccountLoader.js +7 -7
- package/lib/accounts/fetch.d.ts +1 -0
- package/lib/accounts/fetch.js +8 -4
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
- package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/accounts/types.d.ts +5 -4
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +13 -2
- package/lib/adminClient.js +61 -57
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +6 -5
- package/lib/dlob/DLOB.js +105 -75
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.d.ts +5 -2
- package/lib/driftClient.js +137 -95
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +14 -14
- package/lib/examples/loadDlob.js +2 -2
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +13 -13
- package/lib/factory/oracleClient.js +4 -4
- package/lib/idl/drift.json +82 -4
- package/lib/index.js +5 -1
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +23 -23
- package/lib/math/auction.js +6 -6
- package/lib/math/exchangeStatus.js +2 -2
- package/lib/math/funding.js +2 -2
- package/lib/math/margin.js +4 -4
- package/lib/math/market.js +15 -15
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +27 -24
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +9 -9
- package/lib/math/spotMarket.js +3 -3
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +42 -42
- package/lib/math/utils.js +1 -1
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/types.d.ts +1 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/tokenFaucet.js +5 -1
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +71 -44
- package/lib/user.js +63 -63
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -5
- package/src/accounts/fetch.ts +8 -0
- package/src/addresses/pda.ts +13 -0
- package/src/dlob/DLOB.ts +55 -8
- package/src/driftClient.ts +77 -0
- package/src/idl/drift.json +82 -4
- package/src/math/orders.ts +5 -1
- package/src/types.ts +29 -0
- package/src/userMap/userStatsMap.ts +1 -4
- package/tests/amm/test.ts +24 -28
- package/tests/dlob/test.ts +67 -73
package/lib/math/trade.js
CHANGED
|
@@ -33,15 +33,15 @@ const MAXPCT = new anchor_1.BN(1000); //percentage units are [0,1000] => [0,1]
|
|
|
33
33
|
function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quote', oraclePriceData, useSpread = true) {
|
|
34
34
|
let oldPrice;
|
|
35
35
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
36
|
-
if (types_2.isVariant(direction, 'long')) {
|
|
37
|
-
oldPrice = market_1.calculateAskPrice(market, oraclePriceData);
|
|
36
|
+
if ((0, types_2.isVariant)(direction, 'long')) {
|
|
37
|
+
oldPrice = (0, market_1.calculateAskPrice)(market, oraclePriceData);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
oldPrice = market_1.calculateBidPrice(market, oraclePriceData);
|
|
40
|
+
oldPrice = (0, market_1.calculateBidPrice)(market, oraclePriceData);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
oldPrice = market_1.calculateReservePrice(market, oraclePriceData);
|
|
44
|
+
oldPrice = (0, market_1.calculateReservePrice)(market, oraclePriceData);
|
|
45
45
|
}
|
|
46
46
|
if (amount.eq(numericConstants_1.ZERO)) {
|
|
47
47
|
return [numericConstants_1.ZERO, numericConstants_1.ZERO, oldPrice, oldPrice];
|
|
@@ -53,7 +53,7 @@ function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quo
|
|
|
53
53
|
.div(acquiredBaseReserve.abs());
|
|
54
54
|
let amm;
|
|
55
55
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
56
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = amm_1.calculateUpdatedAMMSpreadReserves(market.amm, direction, oraclePriceData);
|
|
56
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
|
|
57
57
|
amm = {
|
|
58
58
|
baseAssetReserve,
|
|
59
59
|
quoteAssetReserve,
|
|
@@ -64,12 +64,12 @@ function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quo
|
|
|
64
64
|
else {
|
|
65
65
|
amm = market.amm;
|
|
66
66
|
}
|
|
67
|
-
const newPrice = amm_1.calculatePrice(amm.baseAssetReserve.sub(acquiredBaseReserve), amm.quoteAssetReserve.sub(acquiredQuoteReserve), amm.pegMultiplier);
|
|
67
|
+
const newPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve.sub(acquiredBaseReserve), amm.quoteAssetReserve.sub(acquiredQuoteReserve), amm.pegMultiplier);
|
|
68
68
|
if (direction == types_1.PositionDirection.SHORT) {
|
|
69
|
-
assert_1.assert(newPrice.lte(oldPrice));
|
|
69
|
+
(0, assert_1.assert)(newPrice.lte(oldPrice));
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
assert_1.assert(oldPrice.lte(newPrice));
|
|
72
|
+
(0, assert_1.assert)(oldPrice.lte(newPrice));
|
|
73
73
|
}
|
|
74
74
|
const pctMaxSlippage = newPrice
|
|
75
75
|
.sub(oldPrice)
|
|
@@ -99,10 +99,10 @@ function calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType
|
|
|
99
99
|
if (amount.eq(numericConstants_1.ZERO)) {
|
|
100
100
|
return [numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO];
|
|
101
101
|
}
|
|
102
|
-
const swapDirection = amm_1.getSwapDirection(inputAssetType, direction);
|
|
102
|
+
const swapDirection = (0, amm_1.getSwapDirection)(inputAssetType, direction);
|
|
103
103
|
let amm;
|
|
104
104
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
105
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = amm_1.calculateUpdatedAMMSpreadReserves(market.amm, direction, oraclePriceData);
|
|
105
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
|
|
106
106
|
amm = {
|
|
107
107
|
baseAssetReserve,
|
|
108
108
|
quoteAssetReserve,
|
|
@@ -113,10 +113,10 @@ function calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType
|
|
|
113
113
|
else {
|
|
114
114
|
amm = market.amm;
|
|
115
115
|
}
|
|
116
|
-
const [newQuoteAssetReserve, newBaseAssetReserve] = amm_1.calculateAmmReservesAfterSwap(amm, inputAssetType, amount, swapDirection);
|
|
116
|
+
const [newQuoteAssetReserve, newBaseAssetReserve] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, inputAssetType, amount, swapDirection);
|
|
117
117
|
const acquiredBase = amm.baseAssetReserve.sub(newBaseAssetReserve);
|
|
118
118
|
const acquiredQuote = amm.quoteAssetReserve.sub(newQuoteAssetReserve);
|
|
119
|
-
const acquiredQuoteAssetAmount = amm_1.calculateQuoteAssetAmountSwapped(acquiredQuote.abs(), amm.pegMultiplier, swapDirection);
|
|
119
|
+
const acquiredQuoteAssetAmount = (0, amm_1.calculateQuoteAssetAmountSwapped)(acquiredQuote.abs(), amm.pegMultiplier, swapDirection);
|
|
120
120
|
return [acquiredBase, acquiredQuote, acquiredQuoteAssetAmount];
|
|
121
121
|
}
|
|
122
122
|
exports.calculateTradeAcquiredAmounts = calculateTradeAcquiredAmounts;
|
|
@@ -141,12 +141,12 @@ exports.calculateTradeAcquiredAmounts = calculateTradeAcquiredAmounts;
|
|
|
141
141
|
* ]
|
|
142
142
|
*/
|
|
143
143
|
function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAssetType = 'quote', oraclePriceData, useSpread = true) {
|
|
144
|
-
assert_1.assert(market.amm.baseAssetReserve.gt(numericConstants_1.ZERO));
|
|
145
|
-
assert_1.assert(targetPrice.gt(numericConstants_1.ZERO));
|
|
146
|
-
assert_1.assert(pct.lte(MAXPCT) && pct.gt(numericConstants_1.ZERO));
|
|
147
|
-
const reservePriceBefore = market_1.calculateReservePrice(market, oraclePriceData);
|
|
148
|
-
const bidPriceBefore = market_1.calculateBidPrice(market, oraclePriceData);
|
|
149
|
-
const askPriceBefore = market_1.calculateAskPrice(market, oraclePriceData);
|
|
144
|
+
(0, assert_1.assert)(market.amm.baseAssetReserve.gt(numericConstants_1.ZERO));
|
|
145
|
+
(0, assert_1.assert)(targetPrice.gt(numericConstants_1.ZERO));
|
|
146
|
+
(0, assert_1.assert)(pct.lte(MAXPCT) && pct.gt(numericConstants_1.ZERO));
|
|
147
|
+
const reservePriceBefore = (0, market_1.calculateReservePrice)(market, oraclePriceData);
|
|
148
|
+
const bidPriceBefore = (0, market_1.calculateBidPrice)(market, oraclePriceData);
|
|
149
|
+
const askPriceBefore = (0, market_1.calculateAskPrice)(market, oraclePriceData);
|
|
150
150
|
let direction;
|
|
151
151
|
if (targetPrice.gt(reservePriceBefore)) {
|
|
152
152
|
const priceGap = targetPrice.sub(reservePriceBefore);
|
|
@@ -166,7 +166,7 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
166
166
|
let quoteAssetReserveBefore;
|
|
167
167
|
let peg = market.amm.pegMultiplier;
|
|
168
168
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
169
|
-
const { baseAssetReserve, quoteAssetReserve, newPeg } = amm_1.calculateUpdatedAMMSpreadReserves(market.amm, direction, oraclePriceData);
|
|
169
|
+
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
|
|
170
170
|
baseAssetReserveBefore = baseAssetReserve;
|
|
171
171
|
quoteAssetReserveBefore = quoteAssetReserve;
|
|
172
172
|
peg = newPeg;
|
|
@@ -196,9 +196,9 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
196
196
|
}
|
|
197
197
|
else if (reservePriceBefore.gt(targetPrice)) {
|
|
198
198
|
// overestimate y2
|
|
199
|
-
baseAssetReserveAfter = utils_1.squareRootBN(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).sub(biasModifier)).sub(new anchor_1.BN(1));
|
|
199
|
+
baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).sub(biasModifier)).sub(new anchor_1.BN(1));
|
|
200
200
|
quoteAssetReserveAfter = k.div(numericConstants_1.PRICE_PRECISION).div(baseAssetReserveAfter);
|
|
201
|
-
markPriceAfter = amm_1.calculatePrice(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
201
|
+
markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
202
202
|
direction = types_1.PositionDirection.SHORT;
|
|
203
203
|
tradeSize = quoteAssetReserveBefore
|
|
204
204
|
.sub(quoteAssetReserveAfter)
|
|
@@ -209,9 +209,9 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
209
209
|
}
|
|
210
210
|
else if (reservePriceBefore.lt(targetPrice)) {
|
|
211
211
|
// underestimate y2
|
|
212
|
-
baseAssetReserveAfter = utils_1.squareRootBN(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).add(biasModifier)).add(new anchor_1.BN(1));
|
|
212
|
+
baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).add(biasModifier)).add(new anchor_1.BN(1));
|
|
213
213
|
quoteAssetReserveAfter = k.div(numericConstants_1.PRICE_PRECISION).div(baseAssetReserveAfter);
|
|
214
|
-
markPriceAfter = amm_1.calculatePrice(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
214
|
+
markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
215
215
|
direction = types_1.PositionDirection.LONG;
|
|
216
216
|
tradeSize = quoteAssetReserveAfter
|
|
217
217
|
.sub(quoteAssetReserveBefore)
|
|
@@ -238,8 +238,8 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
238
238
|
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
239
239
|
.mul(numericConstants_1.PRICE_PRECISION)
|
|
240
240
|
.div(baseSize.abs());
|
|
241
|
-
assert_1.assert(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
|
|
242
|
-
assert_1.assert(tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000, 'Target Price Calculation incorrect' +
|
|
241
|
+
(0, assert_1.assert)(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
|
|
242
|
+
(0, assert_1.assert)(tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000, 'Target Price Calculation incorrect' +
|
|
243
243
|
tp2.toString() +
|
|
244
244
|
'>=' +
|
|
245
245
|
tp1.toString() +
|
|
@@ -277,29 +277,29 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
277
277
|
quoteFilled: numericConstants_1.ZERO,
|
|
278
278
|
};
|
|
279
279
|
}
|
|
280
|
-
const takerIsLong = types_2.isVariant(direction, 'long');
|
|
280
|
+
const takerIsLong = (0, types_2.isVariant)(direction, 'long');
|
|
281
281
|
const limitOrders = dlob[takerIsLong ? 'getMakerLimitAsks' : 'getMakerLimitBids'](market.marketIndex, slot, types_1.MarketType.PERP, oraclePriceData, takerIsLong
|
|
282
|
-
? market_1.calculateBidPrice(market, oraclePriceData)
|
|
283
|
-
: market_1.calculateAskPrice(market, oraclePriceData));
|
|
284
|
-
const swapDirection = amm_1.getSwapDirection(assetType, direction);
|
|
285
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = amm_1.calculateUpdatedAMMSpreadReserves(market.amm, direction, oraclePriceData);
|
|
282
|
+
? (0, market_1.calculateBidPrice)(market, oraclePriceData)
|
|
283
|
+
: (0, market_1.calculateAskPrice)(market, oraclePriceData));
|
|
284
|
+
const swapDirection = (0, amm_1.getSwapDirection)(assetType, direction);
|
|
285
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
|
|
286
286
|
const amm = {
|
|
287
287
|
baseAssetReserve,
|
|
288
288
|
quoteAssetReserve,
|
|
289
289
|
sqrtK: sqrtK,
|
|
290
290
|
pegMultiplier: newPeg,
|
|
291
291
|
};
|
|
292
|
-
const [ammBids, ammAsks] = amm_1.calculateMarketOpenBidAsk(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
|
|
292
|
+
const [ammBids, ammAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
|
|
293
293
|
let ammLiquidity;
|
|
294
294
|
if (assetType === 'base') {
|
|
295
295
|
ammLiquidity = takerIsLong ? ammAsks.abs() : ammBids;
|
|
296
296
|
}
|
|
297
297
|
else {
|
|
298
|
-
const [afterSwapQuoteReserves, _] = amm_1.calculateAmmReservesAfterSwap(amm, 'base', takerIsLong ? ammAsks.abs() : ammBids, amm_1.getSwapDirection('base', direction));
|
|
299
|
-
ammLiquidity = amm_1.calculateQuoteAssetAmountSwapped(amm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), amm.pegMultiplier, swapDirection);
|
|
298
|
+
const [afterSwapQuoteReserves, _] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, 'base', takerIsLong ? ammAsks.abs() : ammBids, (0, amm_1.getSwapDirection)('base', direction));
|
|
299
|
+
ammLiquidity = (0, amm_1.calculateQuoteAssetAmountSwapped)(amm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), amm.pegMultiplier, swapDirection);
|
|
300
300
|
}
|
|
301
301
|
const invariant = amm.sqrtK.mul(amm.sqrtK);
|
|
302
|
-
let bestPrice = amm_1.calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
302
|
+
let bestPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
303
303
|
let cumulativeBaseFilled = numericConstants_1.ZERO;
|
|
304
304
|
let cumulativeQuoteFilled = numericConstants_1.ZERO;
|
|
305
305
|
let limitOrder = limitOrders.next().value;
|
|
@@ -316,7 +316,7 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
316
316
|
const limitOrderPrice = limitOrder === null || limitOrder === void 0 ? void 0 : limitOrder.getPrice(oraclePriceData, slot);
|
|
317
317
|
let maxAmmFill;
|
|
318
318
|
if (limitOrderPrice) {
|
|
319
|
-
const newBaseReserves = utils_1.squareRootBN(invariant
|
|
319
|
+
const newBaseReserves = (0, utils_1.squareRootBN)(invariant
|
|
320
320
|
.mul(numericConstants_1.PRICE_PRECISION)
|
|
321
321
|
.mul(amm.pegMultiplier)
|
|
322
322
|
.div(limitOrderPrice)
|
|
@@ -332,14 +332,14 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
332
332
|
maxAmmFill = anchor_1.BN.min(maxAmmFill, ammLiquidity);
|
|
333
333
|
if (maxAmmFill.gt(numericConstants_1.ZERO)) {
|
|
334
334
|
const baseFilled = anchor_1.BN.min(amount.sub(cumulativeBaseFilled), maxAmmFill);
|
|
335
|
-
const [afterSwapQuoteReserves, afterSwapBaseReserves] = amm_1.calculateAmmReservesAfterSwap(amm, 'base', baseFilled, swapDirection);
|
|
335
|
+
const [afterSwapQuoteReserves, afterSwapBaseReserves] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, 'base', baseFilled, swapDirection);
|
|
336
336
|
ammLiquidity = ammLiquidity.sub(baseFilled);
|
|
337
|
-
const quoteFilled = amm_1.calculateQuoteAssetAmountSwapped(amm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), amm.pegMultiplier, swapDirection);
|
|
337
|
+
const quoteFilled = (0, amm_1.calculateQuoteAssetAmountSwapped)(amm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), amm.pegMultiplier, swapDirection);
|
|
338
338
|
cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
|
|
339
339
|
cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
|
|
340
340
|
amm.baseAssetReserve = afterSwapBaseReserves;
|
|
341
341
|
amm.quoteAssetReserve = afterSwapQuoteReserves;
|
|
342
|
-
worstPrice = amm_1.calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
342
|
+
worstPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
343
343
|
if (cumulativeBaseFilled.eq(amount)) {
|
|
344
344
|
break;
|
|
345
345
|
}
|
|
@@ -367,7 +367,7 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
367
367
|
const limitOrderPrice = limitOrder === null || limitOrder === void 0 ? void 0 : limitOrder.getPrice(oraclePriceData, slot);
|
|
368
368
|
let maxAmmFill;
|
|
369
369
|
if (limitOrderPrice) {
|
|
370
|
-
const newQuoteReserves = utils_1.squareRootBN(invariant
|
|
370
|
+
const newQuoteReserves = (0, utils_1.squareRootBN)(invariant
|
|
371
371
|
.mul(numericConstants_1.PEG_PRECISION)
|
|
372
372
|
.mul(limitOrderPrice)
|
|
373
373
|
.div(amm.pegMultiplier)
|
|
@@ -383,7 +383,7 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
383
383
|
maxAmmFill = anchor_1.BN.min(maxAmmFill, ammLiquidity);
|
|
384
384
|
if (maxAmmFill.gt(numericConstants_1.ZERO)) {
|
|
385
385
|
const quoteFilled = anchor_1.BN.min(amount.sub(cumulativeQuoteFilled), maxAmmFill);
|
|
386
|
-
const [afterSwapQuoteReserves, afterSwapBaseReserves] = amm_1.calculateAmmReservesAfterSwap(amm, 'quote', quoteFilled, swapDirection);
|
|
386
|
+
const [afterSwapQuoteReserves, afterSwapBaseReserves] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, 'quote', quoteFilled, swapDirection);
|
|
387
387
|
ammLiquidity = ammLiquidity.sub(quoteFilled);
|
|
388
388
|
const baseFilled = afterSwapBaseReserves
|
|
389
389
|
.sub(amm.baseAssetReserve)
|
|
@@ -392,7 +392,7 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
392
392
|
cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
|
|
393
393
|
amm.baseAssetReserve = afterSwapBaseReserves;
|
|
394
394
|
amm.quoteAssetReserve = afterSwapQuoteReserves;
|
|
395
|
-
worstPrice = amm_1.calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
395
|
+
worstPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
396
396
|
if (cumulativeQuoteFilled.eq(amount)) {
|
|
397
397
|
break;
|
|
398
398
|
}
|
|
@@ -462,7 +462,7 @@ function calculateEstimatedSpotEntryPrice(assetType, amount, direction, market,
|
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
464
|
const basePrecision = new anchor_1.BN(Math.pow(10, market.decimals));
|
|
465
|
-
const takerIsLong = types_2.isVariant(direction, 'long');
|
|
465
|
+
const takerIsLong = (0, types_2.isVariant)(direction, 'long');
|
|
466
466
|
const dlobLimitOrders = dlob[takerIsLong ? 'getMakerLimitAsks' : 'getMakerLimitBids'](market.marketIndex, slot, types_1.MarketType.SPOT, oraclePriceData);
|
|
467
467
|
const serumLimitOrders = takerIsLong
|
|
468
468
|
? serumAsks.getL2(100)
|
package/lib/math/utils.js
CHANGED
|
@@ -13,7 +13,7 @@ const squareRootBN = (n) => {
|
|
|
13
13
|
if (n.lt(new __1.BN(2))) {
|
|
14
14
|
return n;
|
|
15
15
|
}
|
|
16
|
-
const smallCand = exports.squareRootBN(n.shrn(2)).shln(1);
|
|
16
|
+
const smallCand = (0, exports.squareRootBN)(n.shrn(2)).shln(1);
|
|
17
17
|
const largeCand = smallCand.add(new __1.BN(1));
|
|
18
18
|
if (largeCand.mul(largeCand).gt(n)) {
|
|
19
19
|
return smallCand;
|
|
@@ -11,7 +11,7 @@ class OracleClientCache {
|
|
|
11
11
|
if (this.cache.has(key)) {
|
|
12
12
|
return this.cache.get(key);
|
|
13
13
|
}
|
|
14
|
-
const client = oracleClient_1.getOracleClient(oracleSource, connection);
|
|
14
|
+
const client = (0, oracleClient_1.getOracleClient)(oracleSource, connection);
|
|
15
15
|
this.cache.set(key, client);
|
|
16
16
|
return client;
|
|
17
17
|
}
|
|
@@ -14,7 +14,7 @@ class PythClient {
|
|
|
14
14
|
return this.getOraclePriceDataFromBuffer(accountInfo.data);
|
|
15
15
|
}
|
|
16
16
|
getOraclePriceDataFromBuffer(buffer) {
|
|
17
|
-
const priceData = client_1.parsePriceData(buffer);
|
|
17
|
+
const priceData = (0, client_1.parsePriceData)(buffer);
|
|
18
18
|
return {
|
|
19
19
|
price: convertPythPrice(priceData.aggregate.price, priceData.exponent, this.multiple),
|
|
20
20
|
slot: new anchor_1.BN(priceData.lastSlot.toString()),
|
package/lib/oracles/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { BN } from '@project-serum/anchor';
|
|
4
4
|
import { PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { OracleSource } from '../types';
|
|
6
|
-
export
|
|
6
|
+
export type OraclePriceData = {
|
|
7
7
|
price: BN;
|
|
8
8
|
slot: BN;
|
|
9
9
|
confidence: BN;
|
|
@@ -11,7 +11,7 @@ export declare type OraclePriceData = {
|
|
|
11
11
|
twap?: BN;
|
|
12
12
|
twapConfidence?: BN;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type OracleInfo = {
|
|
15
15
|
publicKey: PublicKey;
|
|
16
16
|
source: OracleSource;
|
|
17
17
|
};
|
package/lib/serum/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
|
-
export
|
|
3
|
+
export type SerumMarketSubscriberConfig = {
|
|
4
4
|
connection: Connection;
|
|
5
5
|
programId: PublicKey;
|
|
6
6
|
marketAddress: PublicKey;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Connection } from '@solana/web3.js';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types/types/src';
|
|
5
|
-
|
|
5
|
+
type SlotSubscriberConfig = {};
|
|
6
6
|
export interface SlotSubscriberEvents {
|
|
7
7
|
newSlot: (newSlot: number) => void;
|
|
8
8
|
}
|
package/lib/tokenFaucet.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { TxSender, TxSigAndSlot } from './types';
|
|
3
3
|
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
4
4
|
import { AnchorProvider } from '@project-serum/anchor';
|
|
5
|
-
|
|
5
|
+
type ResolveReference = {
|
|
6
6
|
resolve?: () => void;
|
|
7
7
|
};
|
|
8
8
|
export declare class RetryTxSender implements TxSender {
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -113,7 +113,7 @@ class RetryTxSender {
|
|
|
113
113
|
catch (err) {
|
|
114
114
|
throw new Error('signature must be base58 encoded: ' + signature);
|
|
115
115
|
}
|
|
116
|
-
assert_1.default(decodedSignature.length === 64, 'signature has invalid length');
|
|
116
|
+
(0, assert_1.default)(decodedSignature.length === 64, 'signature has invalid length');
|
|
117
117
|
const start = Date.now();
|
|
118
118
|
const subscriptionCommitment = commitment || this.provider.opts.commitment;
|
|
119
119
|
const subscriptionIds = new Array();
|
package/lib/tx/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Provider } from '@project-serum/anchor';
|
|
2
2
|
import { AddressLookupTableAccount, ConfirmOptions, Signer, Transaction, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
3
|
-
export
|
|
3
|
+
export type TxSigAndSlot = {
|
|
4
4
|
txSig: TransactionSignature;
|
|
5
5
|
slot: number;
|
|
6
6
|
};
|