@sonarwatch/portfolio-plugins 0.12.37 → 0.12.39
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +1847 -1839
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/plugins/balancer/helpers/pools.js +21 -21
- package/src/plugins/drift/constants.d.ts +1 -0
- package/src/plugins/drift/constants.js +2 -1
- package/src/plugins/drift/constants.js.map +1 -1
- package/src/plugins/drift/depositsFetcher.js +63 -1
- package/src/plugins/drift/depositsFetcher.js.map +1 -1
- package/src/plugins/drift/filters.d.ts +1 -0
- package/src/plugins/drift/filters.js +4 -1
- package/src/plugins/drift/filters.js.map +1 -1
- package/src/plugins/drift/index.js +2 -1
- package/src/plugins/drift/index.js.map +1 -1
- package/src/plugins/drift/perpHelpers/amm.d.ts +74 -0
- package/src/plugins/drift/perpHelpers/amm.js +567 -0
- package/src/plugins/drift/perpHelpers/amm.js.map +1 -0
- package/src/plugins/drift/perpHelpers/assert.d.ts +1 -0
- package/src/plugins/drift/perpHelpers/assert.js +10 -0
- package/src/plugins/drift/perpHelpers/assert.js.map +1 -0
- package/src/plugins/drift/perpHelpers/constants.d.ts +27 -0
- package/src/plugins/drift/perpHelpers/constants.js +35 -0
- package/src/plugins/drift/perpHelpers/constants.js.map +1 -0
- package/src/plugins/drift/perpHelpers/convert.d.ts +0 -0
- package/src/plugins/drift/perpHelpers/convert.js +2 -0
- package/src/plugins/drift/perpHelpers/convert.js.map +1 -0
- package/src/plugins/drift/perpHelpers/getOraclePrice.d.ts +4 -0
- package/src/plugins/drift/perpHelpers/getOraclePrice.js +61 -0
- package/src/plugins/drift/perpHelpers/getOraclePrice.js.map +1 -0
- package/src/plugins/drift/perpHelpers/getPerpMarket.d.ts +4 -0
- package/src/plugins/drift/perpHelpers/getPerpMarket.js +33 -0
- package/src/plugins/drift/perpHelpers/getPerpMarket.js.map +1 -0
- package/src/plugins/drift/perpHelpers/margin.d.ts +10 -0
- package/src/plugins/drift/perpHelpers/margin.js +82 -0
- package/src/plugins/drift/perpHelpers/margin.js.map +1 -0
- package/src/plugins/drift/perpHelpers/math.d.ts +4 -0
- package/src/plugins/drift/perpHelpers/math.js +29 -0
- package/src/plugins/drift/perpHelpers/math.js.map +1 -0
- package/src/plugins/drift/perpHelpers/oracle.d.ts +6 -0
- package/src/plugins/drift/perpHelpers/oracle.js +54 -0
- package/src/plugins/drift/perpHelpers/oracle.js.map +1 -0
- package/src/plugins/drift/perpHelpers/orders.d.ts +2 -0
- package/src/plugins/drift/perpHelpers/orders.js +9 -0
- package/src/plugins/drift/perpHelpers/orders.js.map +1 -0
- package/src/plugins/drift/perpHelpers/position.d.ts +44 -0
- package/src/plugins/drift/perpHelpers/position.js +184 -0
- package/src/plugins/drift/perpHelpers/position.js.map +1 -0
- package/src/plugins/drift/perpHelpers/prelaunchOracle.d.ts +3 -0
- package/src/plugins/drift/perpHelpers/prelaunchOracle.js +20 -0
- package/src/plugins/drift/perpHelpers/prelaunchOracle.js.map +1 -0
- package/src/plugins/drift/perpHelpers/pyth.d.ts +5 -0
- package/src/plugins/drift/perpHelpers/pyth.js +42 -0
- package/src/plugins/drift/perpHelpers/pyth.js.map +1 -0
- package/src/plugins/drift/perpHelpers/repeg.d.ts +14 -0
- package/src/plugins/drift/perpHelpers/repeg.js +162 -0
- package/src/plugins/drift/perpHelpers/repeg.js.map +1 -0
- package/src/plugins/drift/perpHelpers/switchboard.d.ts +3 -0
- package/src/plugins/drift/perpHelpers/switchboard.js +31 -0
- package/src/plugins/drift/perpHelpers/switchboard.js.map +1 -0
- package/src/plugins/drift/perpHelpers/types.d.ts +28 -0
- package/src/plugins/drift/perpHelpers/types.js +19 -0
- package/src/plugins/drift/perpHelpers/types.js.map +1 -0
- package/src/plugins/drift/prepMarketsJob.d.ts +3 -0
- package/src/plugins/drift/prepMarketsJob.js +38 -0
- package/src/plugins/drift/prepMarketsJob.js.map +1 -0
- package/src/plugins/drift/struct.d.ts +82 -76
- package/src/plugins/drift/struct.js +79 -74
- package/src/plugins/drift/struct.js.map +1 -1
- package/src/plugins/drift/types.d.ts +1 -0
- package/src/plugins/jupiter/exchange/perpetualFetcher.js +3 -6
- package/src/plugins/jupiter/exchange/perpetualFetcher.js.map +1 -1
- package/src/plugins/jupiter/exchange/valueAverageFetcher.js.map +1 -1
- package/src/plugins/jupiter/helpers.d.ts +2 -2
- package/src/plugins/jupiter/helpers.js.map +1 -1
- package/src/plugins/sushiswap/helpers.js +24 -24
- package/src/plugins/uniswap-v2/helpers.js +22 -22
- package/src/plugins/zeta/airdropFetcher.js +14 -14
- package/src/utils/sei/constants.js +8 -8
- package/src/utils/sei/getQueryBalanceByOwner.js +4 -4
@@ -0,0 +1,567 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.calculateReferencePriceOffset = exports.calculateMarketOpenBidAsk = exports.calculateInventoryLiquidityRatio = exports.calculateInventoryScale = exports.calculateEffectiveLeverage = exports.calculatePrice = exports.calculateVolSpreadBN = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateAmmReservesAfterSwap = exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.calculateOptimalPegAndBudget = exports.calculateUpdatedAMM = exports.calculateUpdatedAMMSpreadReserves = void 0;
|
7
|
+
/* eslint-disable no-param-reassign */
|
8
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
10
|
+
const types_1 = require("./types");
|
11
|
+
const constants_1 = require("./constants");
|
12
|
+
const orders_1 = require("./orders");
|
13
|
+
const math_1 = require("./math");
|
14
|
+
const assert_1 = require("./assert");
|
15
|
+
const oracle_1 = require("./oracle");
|
16
|
+
const repeg_1 = require("./repeg");
|
17
|
+
function calculateUpdatedAMMSpreadReserves(amm, direction, oraclePriceData) {
|
18
|
+
const newAmm = calculateUpdatedAMM(amm, oraclePriceData);
|
19
|
+
const [shortReserves, longReserves] = calculateSpreadReserves(newAmm, oraclePriceData);
|
20
|
+
const dirReserves = (0, types_1.isVariant)(direction, 'long')
|
21
|
+
? longReserves
|
22
|
+
: shortReserves;
|
23
|
+
const result = {
|
24
|
+
baseAssetReserve: dirReserves.baseAssetReserve,
|
25
|
+
quoteAssetReserve: dirReserves.quoteAssetReserve,
|
26
|
+
sqrtK: newAmm.sqrtK,
|
27
|
+
newPeg: newAmm.pegMultiplier,
|
28
|
+
};
|
29
|
+
return result;
|
30
|
+
}
|
31
|
+
exports.calculateUpdatedAMMSpreadReserves = calculateUpdatedAMMSpreadReserves;
|
32
|
+
function calculateUpdatedAMM(amm, oraclePriceData) {
|
33
|
+
if (amm.curveUpdateIntensity === 0 || oraclePriceData === undefined) {
|
34
|
+
return amm;
|
35
|
+
}
|
36
|
+
const newAmm = Object.assign({}, amm);
|
37
|
+
const [prepegCost, pKNumer, pKDenom, newPeg] = calculateNewAmm(amm, oraclePriceData);
|
38
|
+
newAmm.baseAssetReserve = newAmm.baseAssetReserve.mul(pKNumer).div(pKDenom);
|
39
|
+
newAmm.sqrtK = newAmm.sqrtK.mul(pKNumer).div(pKDenom);
|
40
|
+
const invariant = newAmm.sqrtK.mul(newAmm.sqrtK);
|
41
|
+
newAmm.quoteAssetReserve = invariant.div(newAmm.baseAssetReserve);
|
42
|
+
newAmm.pegMultiplier = newPeg;
|
43
|
+
const directionToClose = amm.baseAssetAmountWithAmm.gt(constants_1.ZERO)
|
44
|
+
? types_1.PositionDirection.SHORT
|
45
|
+
: types_1.PositionDirection.LONG;
|
46
|
+
const [newQuoteAssetReserve] = calculateAmmReservesAfterSwap(newAmm, 'base', amm.baseAssetAmountWithAmm.abs(), getSwapDirection('base', directionToClose));
|
47
|
+
newAmm.terminalQuoteAssetReserve = newQuoteAssetReserve;
|
48
|
+
newAmm.totalFeeMinusDistributions =
|
49
|
+
newAmm.totalFeeMinusDistributions.sub(prepegCost);
|
50
|
+
newAmm.netRevenueSinceLastFunding =
|
51
|
+
newAmm.netRevenueSinceLastFunding.sub(prepegCost);
|
52
|
+
return newAmm;
|
53
|
+
}
|
54
|
+
exports.calculateUpdatedAMM = calculateUpdatedAMM;
|
55
|
+
function calculateNewAmm(amm, oraclePriceData) {
|
56
|
+
let pKNumer = new bn_js_1.default(1);
|
57
|
+
let pKDenom = new bn_js_1.default(1);
|
58
|
+
const [targetPrice, _newPeg, budget] = calculateOptimalPegAndBudget(amm, oraclePriceData);
|
59
|
+
let prePegCost = (0, repeg_1.calculateRepegCost)(amm, _newPeg);
|
60
|
+
let newPeg = _newPeg;
|
61
|
+
if (prePegCost.gte(budget) && prePegCost.gt(constants_1.ZERO)) {
|
62
|
+
[pKNumer, pKDenom] = [new bn_js_1.default(999), new bn_js_1.default(1000)];
|
63
|
+
const deficitMadeup = (0, repeg_1.calculateAdjustKCost)(amm, pKNumer, pKDenom);
|
64
|
+
(0, assert_1.assert)(deficitMadeup.lte(new bn_js_1.default(0)));
|
65
|
+
prePegCost = budget.add(deficitMadeup.abs());
|
66
|
+
const newAmm = Object.assign({}, amm);
|
67
|
+
newAmm.baseAssetReserve = newAmm.baseAssetReserve.mul(pKNumer).div(pKDenom);
|
68
|
+
newAmm.sqrtK = newAmm.sqrtK.mul(pKNumer).div(pKDenom);
|
69
|
+
const invariant = newAmm.sqrtK.mul(newAmm.sqrtK);
|
70
|
+
newAmm.quoteAssetReserve = invariant.div(newAmm.baseAssetReserve);
|
71
|
+
const directionToClose = amm.baseAssetAmountWithAmm.gt(constants_1.ZERO)
|
72
|
+
? types_1.PositionDirection.SHORT
|
73
|
+
: types_1.PositionDirection.LONG;
|
74
|
+
const [newQuoteAssetReserve] = calculateAmmReservesAfterSwap(newAmm, 'base', amm.baseAssetAmountWithAmm.abs(), getSwapDirection('base', directionToClose));
|
75
|
+
newAmm.terminalQuoteAssetReserve = newQuoteAssetReserve;
|
76
|
+
newPeg = (0, repeg_1.calculateBudgetedPeg)(newAmm, prePegCost, targetPrice);
|
77
|
+
prePegCost = (0, repeg_1.calculateRepegCost)(newAmm, newPeg);
|
78
|
+
}
|
79
|
+
return [prePegCost, pKNumer, pKDenom, newPeg];
|
80
|
+
}
|
81
|
+
function calculateOptimalPegAndBudget(amm, oraclePriceData) {
|
82
|
+
const reservePriceBefore = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
83
|
+
const targetPrice = oraclePriceData.price;
|
84
|
+
const newPeg = calculatePegFromTargetPrice(targetPrice, amm.baseAssetReserve, amm.quoteAssetReserve);
|
85
|
+
const prePegCost = (0, repeg_1.calculateRepegCost)(amm, newPeg);
|
86
|
+
const totalFeeLB = amm.totalExchangeFee.div(new bn_js_1.default(2));
|
87
|
+
const budget = bn_js_1.default.max(constants_1.ZERO, amm.totalFeeMinusDistributions.sub(totalFeeLB));
|
88
|
+
let checkLowerBound = true;
|
89
|
+
if (budget.lt(prePegCost)) {
|
90
|
+
const halfMaxPriceSpread = new bn_js_1.default(amm.maxSpread)
|
91
|
+
.div(new bn_js_1.default(2))
|
92
|
+
.mul(targetPrice)
|
93
|
+
.div(constants_1.BID_ASK_SPREAD_PRECISION);
|
94
|
+
let newTargetPrice;
|
95
|
+
let newOptimalPeg;
|
96
|
+
let newBudget;
|
97
|
+
const targetPriceGap = reservePriceBefore.sub(targetPrice);
|
98
|
+
if (targetPriceGap.abs().gt(halfMaxPriceSpread)) {
|
99
|
+
const markAdj = targetPriceGap.abs().sub(halfMaxPriceSpread);
|
100
|
+
if (targetPriceGap.lt(new bn_js_1.default(0))) {
|
101
|
+
newTargetPrice = reservePriceBefore.add(markAdj);
|
102
|
+
}
|
103
|
+
else {
|
104
|
+
newTargetPrice = reservePriceBefore.sub(markAdj);
|
105
|
+
}
|
106
|
+
newOptimalPeg = calculatePegFromTargetPrice(newTargetPrice, amm.baseAssetReserve, amm.quoteAssetReserve);
|
107
|
+
newBudget = (0, repeg_1.calculateRepegCost)(amm, newOptimalPeg);
|
108
|
+
checkLowerBound = false;
|
109
|
+
return [newTargetPrice, newOptimalPeg, newBudget, false];
|
110
|
+
}
|
111
|
+
if (amm.totalFeeMinusDistributions.lt(amm.totalExchangeFee.div(new bn_js_1.default(2)))) {
|
112
|
+
checkLowerBound = false;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
return [targetPrice, newPeg, budget, checkLowerBound];
|
116
|
+
}
|
117
|
+
exports.calculateOptimalPegAndBudget = calculateOptimalPegAndBudget;
|
118
|
+
function calculateSpreadReserves(amm, oraclePriceData, now) {
|
119
|
+
function calculateSpreadReserve(spread, direction,
|
120
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
121
|
+
amm) {
|
122
|
+
if (spread === 0) {
|
123
|
+
return {
|
124
|
+
baseAssetReserve: amm.baseAssetReserve,
|
125
|
+
quoteAssetReserve: amm.quoteAssetReserve,
|
126
|
+
};
|
127
|
+
}
|
128
|
+
let spreadFraction = new bn_js_1.default(spread / 2);
|
129
|
+
// make non-zero
|
130
|
+
if (spreadFraction.eq(constants_1.ZERO)) {
|
131
|
+
spreadFraction = spread >= 0 ? new bn_js_1.default(1) : new bn_js_1.default(-1);
|
132
|
+
}
|
133
|
+
const quoteAssetReserveDelta = amm.quoteAssetReserve.div(constants_1.BID_ASK_SPREAD_PRECISION.div(spreadFraction));
|
134
|
+
let quoteAssetReserve;
|
135
|
+
if (quoteAssetReserveDelta.gte(constants_1.ZERO)) {
|
136
|
+
quoteAssetReserve = amm.quoteAssetReserve.add(quoteAssetReserveDelta.abs());
|
137
|
+
}
|
138
|
+
else {
|
139
|
+
quoteAssetReserve = amm.quoteAssetReserve.sub(quoteAssetReserveDelta.abs());
|
140
|
+
}
|
141
|
+
const baseAssetReserve = amm.sqrtK.mul(amm.sqrtK).div(quoteAssetReserve);
|
142
|
+
return {
|
143
|
+
baseAssetReserve,
|
144
|
+
quoteAssetReserve,
|
145
|
+
};
|
146
|
+
}
|
147
|
+
const reservePrice = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
148
|
+
// always allow 10 bps of price offset, up to a fifth of the market's max_spread
|
149
|
+
let maxOffset = 0;
|
150
|
+
let referencePriceOffset = constants_1.ZERO;
|
151
|
+
if (amm.curveUpdateIntensity > 100) {
|
152
|
+
maxOffset = Math.max(amm.maxSpread / 5, (constants_1.PERCENTAGE_PRECISION.toNumber() / 10000) *
|
153
|
+
(amm.curveUpdateIntensity - 100));
|
154
|
+
const liquidityFraction = calculateInventoryLiquidityRatio(amm.baseAssetAmountWithAmm, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve);
|
155
|
+
const liquidityFractionSigned = liquidityFraction.mul((0, math_1.sigNum)(amm.baseAssetAmountWithAmm.add(amm.baseAssetAmountWithUnsettledLp)));
|
156
|
+
referencePriceOffset = calculateReferencePriceOffset(reservePrice, amm.last24HAvgFundingRate, liquidityFractionSigned, new bn_js_1.default(amm.historicalOracleData.lastOraclePriceTwap5Min.toString(10), 10), amm.lastMarkPriceTwap5Min, new bn_js_1.default(amm.historicalOracleData.lastOraclePriceTwap.toString(10), 10), amm.lastMarkPriceTwap, maxOffset);
|
157
|
+
}
|
158
|
+
const [longSpread, shortSpread] = calculateSpread(amm, oraclePriceData, now, reservePrice);
|
159
|
+
const askReserves = calculateSpreadReserve(longSpread + referencePriceOffset.toNumber(), types_1.PositionDirection.LONG, amm);
|
160
|
+
const bidReserves = calculateSpreadReserve(-shortSpread + referencePriceOffset.toNumber(), types_1.PositionDirection.SHORT, amm);
|
161
|
+
return [bidReserves, askReserves];
|
162
|
+
}
|
163
|
+
exports.calculateSpreadReserves = calculateSpreadReserves;
|
164
|
+
/**
|
165
|
+
* Helper function calculating constant product curve output. Agnostic to whether input asset is quote or base
|
166
|
+
*
|
167
|
+
* @param inputAssetReserve
|
168
|
+
* @param swapAmount
|
169
|
+
* @param swapDirection
|
170
|
+
* @param invariant
|
171
|
+
* @returns newInputAssetReserve and newOutputAssetReserve after swap. : Precision AMM_RESERVE_PRECISION
|
172
|
+
*/
|
173
|
+
function calculateSwapOutput(inputAssetReserve, swapAmount, swapDirection, invariant) {
|
174
|
+
let newInputAssetReserve;
|
175
|
+
if (swapDirection === types_1.SwapDirection.ADD) {
|
176
|
+
newInputAssetReserve = inputAssetReserve.add(swapAmount);
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
newInputAssetReserve = inputAssetReserve.sub(swapAmount);
|
180
|
+
}
|
181
|
+
const newOutputAssetReserve = invariant.div(newInputAssetReserve);
|
182
|
+
return [newInputAssetReserve, newOutputAssetReserve];
|
183
|
+
}
|
184
|
+
exports.calculateSwapOutput = calculateSwapOutput;
|
185
|
+
/**
|
186
|
+
* Translate long/shorting quote/base asset into amm operation
|
187
|
+
*
|
188
|
+
* @param inputAssetType
|
189
|
+
* @param positionDirection
|
190
|
+
*/
|
191
|
+
function getSwapDirection(inputAssetType, positionDirection) {
|
192
|
+
if ((0, types_1.isVariant)(positionDirection, 'long') && inputAssetType === 'base') {
|
193
|
+
return types_1.SwapDirection.REMOVE;
|
194
|
+
}
|
195
|
+
if ((0, types_1.isVariant)(positionDirection, 'short') && inputAssetType === 'quote') {
|
196
|
+
return types_1.SwapDirection.REMOVE;
|
197
|
+
}
|
198
|
+
return types_1.SwapDirection.ADD;
|
199
|
+
}
|
200
|
+
exports.getSwapDirection = getSwapDirection;
|
201
|
+
/**
|
202
|
+
* Helper function calculating terminal price of amm
|
203
|
+
*
|
204
|
+
* @param market
|
205
|
+
* @returns cost : Precision PRICE_PRECISION
|
206
|
+
*/
|
207
|
+
function calculateTerminalPrice(market) {
|
208
|
+
const directionToClose = market.amm.baseAssetAmountWithAmm.gt(constants_1.ZERO)
|
209
|
+
? types_1.PositionDirection.SHORT
|
210
|
+
: types_1.PositionDirection.LONG;
|
211
|
+
const [newQuoteAssetReserve, newBaseAssetReserve] = calculateAmmReservesAfterSwap(market.amm, 'base', market.amm.baseAssetAmountWithAmm.abs(), getSwapDirection('base', directionToClose));
|
212
|
+
const terminalPrice = newQuoteAssetReserve
|
213
|
+
.mul(constants_1.PRICE_PRECISION)
|
214
|
+
.mul(market.amm.pegMultiplier)
|
215
|
+
.div(constants_1.PEG_PRECISION)
|
216
|
+
.div(newBaseAssetReserve);
|
217
|
+
return terminalPrice;
|
218
|
+
}
|
219
|
+
exports.calculateTerminalPrice = calculateTerminalPrice;
|
220
|
+
function calculateMaxBaseAssetAmountToTrade(amm, limit_price, direction, oraclePriceData, now) {
|
221
|
+
const invariant = amm.sqrtK.mul(amm.sqrtK);
|
222
|
+
const newBaseAssetReserveSquared = invariant
|
223
|
+
.mul(constants_1.PRICE_PRECISION)
|
224
|
+
.mul(amm.pegMultiplier)
|
225
|
+
.div(limit_price)
|
226
|
+
.div(constants_1.PEG_PRECISION);
|
227
|
+
const newBaseAssetReserve = (0, math_1.squareRootBN)(newBaseAssetReserveSquared);
|
228
|
+
const [shortSpreadReserves, longSpreadReserves] = calculateSpreadReserves(amm, oraclePriceData, now);
|
229
|
+
const baseAssetReserveBefore = (0, types_1.isVariant)(direction, 'long')
|
230
|
+
? longSpreadReserves.baseAssetReserve
|
231
|
+
: shortSpreadReserves.baseAssetReserve;
|
232
|
+
if (newBaseAssetReserve.gt(baseAssetReserveBefore)) {
|
233
|
+
return [
|
234
|
+
newBaseAssetReserve.sub(baseAssetReserveBefore),
|
235
|
+
types_1.PositionDirection.SHORT,
|
236
|
+
];
|
237
|
+
}
|
238
|
+
if (newBaseAssetReserve.lt(baseAssetReserveBefore)) {
|
239
|
+
return [
|
240
|
+
baseAssetReserveBefore.sub(newBaseAssetReserve),
|
241
|
+
types_1.PositionDirection.LONG,
|
242
|
+
];
|
243
|
+
}
|
244
|
+
return [new bn_js_1.default(0), types_1.PositionDirection.LONG];
|
245
|
+
}
|
246
|
+
exports.calculateMaxBaseAssetAmountToTrade = calculateMaxBaseAssetAmountToTrade;
|
247
|
+
function calculateQuoteAssetAmountSwapped(quoteAssetReserves, pegMultiplier, swapDirection) {
|
248
|
+
if ((0, types_1.isVariant)(swapDirection, 'remove')) {
|
249
|
+
quoteAssetReserves = quoteAssetReserves.add(constants_1.ONE);
|
250
|
+
}
|
251
|
+
let quoteAssetAmount = quoteAssetReserves
|
252
|
+
.mul(pegMultiplier)
|
253
|
+
.div(constants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO);
|
254
|
+
if ((0, types_1.isVariant)(swapDirection, 'remove')) {
|
255
|
+
quoteAssetAmount = quoteAssetAmount.add(constants_1.ONE);
|
256
|
+
}
|
257
|
+
return quoteAssetAmount;
|
258
|
+
}
|
259
|
+
exports.calculateQuoteAssetAmountSwapped = calculateQuoteAssetAmountSwapped;
|
260
|
+
function calculateMaxBaseAssetAmountFillable(amm, orderDirection) {
|
261
|
+
const maxFillSize = amm.baseAssetReserve.div(new bn_js_1.default(amm.maxFillReserveFraction));
|
262
|
+
let maxBaseAssetAmountOnSide;
|
263
|
+
if ((0, types_1.isVariant)(orderDirection, 'long')) {
|
264
|
+
maxBaseAssetAmountOnSide = bn_js_1.default.max(constants_1.ZERO, amm.baseAssetReserve.sub(amm.minBaseAssetReserve));
|
265
|
+
}
|
266
|
+
else {
|
267
|
+
maxBaseAssetAmountOnSide = bn_js_1.default.max(constants_1.ZERO, amm.maxBaseAssetReserve.sub(amm.baseAssetReserve));
|
268
|
+
}
|
269
|
+
return (0, orders_1.standardizeBaseAssetAmount)(bn_js_1.default.min(maxFillSize, maxBaseAssetAmountOnSide), amm.orderStepSize);
|
270
|
+
}
|
271
|
+
exports.calculateMaxBaseAssetAmountFillable = calculateMaxBaseAssetAmountFillable;
|
272
|
+
function calculateAmmReservesAfterSwap(amm, inputAssetType, swapAmount, swapDirection) {
|
273
|
+
(0, assert_1.assert)(swapAmount.gte(constants_1.ZERO), 'swapAmount must be greater than 0');
|
274
|
+
let newQuoteAssetReserve;
|
275
|
+
let newBaseAssetReserve;
|
276
|
+
if (inputAssetType === 'quote') {
|
277
|
+
swapAmount = swapAmount
|
278
|
+
.mul(constants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO)
|
279
|
+
.div(amm.pegMultiplier);
|
280
|
+
[newQuoteAssetReserve, newBaseAssetReserve] = calculateSwapOutput(amm.quoteAssetReserve, swapAmount, swapDirection, amm.sqrtK.mul(amm.sqrtK));
|
281
|
+
}
|
282
|
+
else {
|
283
|
+
[newBaseAssetReserve, newQuoteAssetReserve] = calculateSwapOutput(amm.baseAssetReserve, swapAmount, swapDirection, amm.sqrtK.mul(amm.sqrtK));
|
284
|
+
}
|
285
|
+
return [newQuoteAssetReserve, newBaseAssetReserve];
|
286
|
+
}
|
287
|
+
exports.calculateAmmReservesAfterSwap = calculateAmmReservesAfterSwap;
|
288
|
+
function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOracleConfPct, maxSpread, quoteAssetReserve, terminalQuoteAssetReserve, pegMultiplier, baseAssetAmountWithAmm, reservePrice, totalFeeMinusDistributions, netRevenueSinceLastFunding, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve, markStd, oracleStd, longIntensity, shortIntensity, volume24H, returnTerms = false) {
|
289
|
+
(0, assert_1.assert)(Number.isInteger(baseSpread));
|
290
|
+
(0, assert_1.assert)(Number.isInteger(maxSpread));
|
291
|
+
const spreadTerms = {
|
292
|
+
longVolSpread: 0,
|
293
|
+
shortVolSpread: 0,
|
294
|
+
longSpreadwPS: 0,
|
295
|
+
shortSpreadwPS: 0,
|
296
|
+
maxTargetSpread: 0,
|
297
|
+
inventorySpreadScale: 0,
|
298
|
+
longSpreadwInvScale: 0,
|
299
|
+
shortSpreadwInvScale: 0,
|
300
|
+
effectiveLeverage: 0,
|
301
|
+
effectiveLeverageCapped: 0,
|
302
|
+
longSpreadwEL: 0,
|
303
|
+
shortSpreadwEL: 0,
|
304
|
+
revenueRetreatAmount: 0,
|
305
|
+
halfRevenueRetreatAmount: 0,
|
306
|
+
longSpreadwRevRetreat: 0,
|
307
|
+
shortSpreadwRevRetreat: 0,
|
308
|
+
longSpreadwOffsetShrink: 0,
|
309
|
+
shortSpreadwOffsetShrink: 0,
|
310
|
+
totalSpread: 0,
|
311
|
+
longSpread: 0,
|
312
|
+
shortSpread: 0,
|
313
|
+
};
|
314
|
+
const [longVolSpread, shortVolSpread] = calculateVolSpreadBN(lastOracleConfPct, reservePrice, markStd, oracleStd, longIntensity, shortIntensity, volume24H);
|
315
|
+
spreadTerms.longVolSpread = longVolSpread.toNumber();
|
316
|
+
spreadTerms.shortVolSpread = shortVolSpread.toNumber();
|
317
|
+
let longSpread = Math.max(baseSpread / 2, longVolSpread.toNumber());
|
318
|
+
let shortSpread = Math.max(baseSpread / 2, shortVolSpread.toNumber());
|
319
|
+
if (lastOracleReservePriceSpreadPct.gt(constants_1.ZERO)) {
|
320
|
+
shortSpread = Math.max(shortSpread, lastOracleReservePriceSpreadPct.abs().toNumber() +
|
321
|
+
shortVolSpread.toNumber());
|
322
|
+
}
|
323
|
+
else if (lastOracleReservePriceSpreadPct.lt(constants_1.ZERO)) {
|
324
|
+
longSpread = Math.max(longSpread, lastOracleReservePriceSpreadPct.abs().toNumber() +
|
325
|
+
longVolSpread.toNumber());
|
326
|
+
}
|
327
|
+
spreadTerms.longSpreadwPS = longSpread;
|
328
|
+
spreadTerms.shortSpreadwPS = shortSpread;
|
329
|
+
const maxSpreadBaseline = Math.min(Math.max(lastOracleReservePriceSpreadPct.abs().toNumber(), lastOracleConfPct.muln(2).toNumber(), bn_js_1.default.max(markStd, oracleStd)
|
330
|
+
.mul(constants_1.PERCENTAGE_PRECISION)
|
331
|
+
.div(reservePrice)
|
332
|
+
.toNumber()), constants_1.BID_ASK_SPREAD_PRECISION.toNumber());
|
333
|
+
const maxTargetSpread = Math.floor(Math.max(maxSpread, maxSpreadBaseline));
|
334
|
+
const inventorySpreadScale = calculateInventoryScale(baseAssetAmountWithAmm, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve, baseAssetAmountWithAmm.gt(constants_1.ZERO) ? longSpread : shortSpread, maxTargetSpread);
|
335
|
+
if (baseAssetAmountWithAmm.gt(constants_1.ZERO)) {
|
336
|
+
longSpread *= inventorySpreadScale;
|
337
|
+
}
|
338
|
+
else if (baseAssetAmountWithAmm.lt(constants_1.ZERO)) {
|
339
|
+
shortSpread *= inventorySpreadScale;
|
340
|
+
}
|
341
|
+
spreadTerms.maxTargetSpread = maxTargetSpread;
|
342
|
+
spreadTerms.inventorySpreadScale = inventorySpreadScale;
|
343
|
+
spreadTerms.longSpreadwInvScale = longSpread;
|
344
|
+
spreadTerms.shortSpreadwInvScale = shortSpread;
|
345
|
+
const MAX_SPREAD_SCALE = 10;
|
346
|
+
if (totalFeeMinusDistributions.gt(constants_1.ZERO)) {
|
347
|
+
const effectiveLeverage = calculateEffectiveLeverage(baseSpread, quoteAssetReserve, terminalQuoteAssetReserve, pegMultiplier, baseAssetAmountWithAmm, reservePrice, totalFeeMinusDistributions);
|
348
|
+
spreadTerms.effectiveLeverage = effectiveLeverage;
|
349
|
+
const spreadScale = Math.min(MAX_SPREAD_SCALE, 1 + effectiveLeverage);
|
350
|
+
spreadTerms.effectiveLeverageCapped = spreadScale;
|
351
|
+
if (baseAssetAmountWithAmm.gt(constants_1.ZERO)) {
|
352
|
+
longSpread *= spreadScale;
|
353
|
+
longSpread = Math.floor(longSpread);
|
354
|
+
}
|
355
|
+
else {
|
356
|
+
shortSpread *= spreadScale;
|
357
|
+
shortSpread = Math.floor(shortSpread);
|
358
|
+
}
|
359
|
+
}
|
360
|
+
else {
|
361
|
+
longSpread *= MAX_SPREAD_SCALE;
|
362
|
+
shortSpread *= MAX_SPREAD_SCALE;
|
363
|
+
}
|
364
|
+
spreadTerms.longSpreadwEL = longSpread;
|
365
|
+
spreadTerms.shortSpreadwEL = shortSpread;
|
366
|
+
if (netRevenueSinceLastFunding.lt(constants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT)) {
|
367
|
+
const maxRetreat = maxTargetSpread / 10;
|
368
|
+
let revenueRetreatAmount = maxRetreat;
|
369
|
+
if (netRevenueSinceLastFunding.gte(constants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT.mul(new bn_js_1.default(1000)))) {
|
370
|
+
revenueRetreatAmount = Math.min(maxRetreat, Math.floor((baseSpread * netRevenueSinceLastFunding.abs().toNumber()) /
|
371
|
+
constants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT.abs().toNumber()));
|
372
|
+
}
|
373
|
+
const halfRevenueRetreatAmount = Math.floor(revenueRetreatAmount / 2);
|
374
|
+
spreadTerms.revenueRetreatAmount = revenueRetreatAmount;
|
375
|
+
spreadTerms.halfRevenueRetreatAmount = halfRevenueRetreatAmount;
|
376
|
+
if (baseAssetAmountWithAmm.gt(constants_1.ZERO)) {
|
377
|
+
longSpread += revenueRetreatAmount;
|
378
|
+
shortSpread += halfRevenueRetreatAmount;
|
379
|
+
}
|
380
|
+
else if (baseAssetAmountWithAmm.lt(constants_1.ZERO)) {
|
381
|
+
longSpread += halfRevenueRetreatAmount;
|
382
|
+
shortSpread += revenueRetreatAmount;
|
383
|
+
}
|
384
|
+
else {
|
385
|
+
longSpread += halfRevenueRetreatAmount;
|
386
|
+
shortSpread += halfRevenueRetreatAmount;
|
387
|
+
}
|
388
|
+
}
|
389
|
+
spreadTerms.longSpreadwRevRetreat = longSpread;
|
390
|
+
spreadTerms.shortSpreadwRevRetreat = shortSpread;
|
391
|
+
const totalSpread = longSpread + shortSpread;
|
392
|
+
if (totalSpread > maxTargetSpread) {
|
393
|
+
if (longSpread > shortSpread) {
|
394
|
+
longSpread = Math.ceil((longSpread * maxTargetSpread) / totalSpread);
|
395
|
+
shortSpread = Math.floor(maxTargetSpread - longSpread);
|
396
|
+
}
|
397
|
+
else {
|
398
|
+
shortSpread = Math.ceil((shortSpread * maxTargetSpread) / totalSpread);
|
399
|
+
longSpread = Math.floor(maxTargetSpread - shortSpread);
|
400
|
+
}
|
401
|
+
}
|
402
|
+
spreadTerms.totalSpread = totalSpread;
|
403
|
+
spreadTerms.longSpread = longSpread;
|
404
|
+
spreadTerms.shortSpread = shortSpread;
|
405
|
+
if (returnTerms) {
|
406
|
+
return spreadTerms;
|
407
|
+
}
|
408
|
+
return [longSpread, shortSpread];
|
409
|
+
}
|
410
|
+
exports.calculateSpreadBN = calculateSpreadBN;
|
411
|
+
function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
412
|
+
if (amm.baseSpread === 0 || amm.curveUpdateIntensity === 0) {
|
413
|
+
return [amm.baseSpread / 2, amm.baseSpread / 2];
|
414
|
+
}
|
415
|
+
if (!reservePrice) {
|
416
|
+
reservePrice = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
417
|
+
}
|
418
|
+
const targetPrice = (oraclePriceData === null || oraclePriceData === void 0 ? void 0 : oraclePriceData.price) || reservePrice;
|
419
|
+
const targetMarkSpreadPct = reservePrice
|
420
|
+
.sub(targetPrice)
|
421
|
+
.mul(constants_1.BID_ASK_SPREAD_PRECISION)
|
422
|
+
.div(reservePrice);
|
423
|
+
now = now || new bn_js_1.default(new Date().getTime() / 1000); // todo
|
424
|
+
const liveOracleStd = (0, oracle_1.calculateLiveOracleStd)(amm, oraclePriceData, now);
|
425
|
+
const confIntervalPct = (0, oracle_1.getNewOracleConfPct)(amm, oraclePriceData, reservePrice, now);
|
426
|
+
const spreads = calculateSpreadBN(amm.baseSpread, targetMarkSpreadPct, confIntervalPct, amm.maxSpread, amm.quoteAssetReserve, amm.terminalQuoteAssetReserve, amm.pegMultiplier, amm.baseAssetAmountWithAmm, reservePrice, amm.totalFeeMinusDistributions, amm.netRevenueSinceLastFunding, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve, amm.markStd, liveOracleStd, amm.longIntensityVolume, amm.shortIntensityVolume, amm.volume24H);
|
427
|
+
if (!Array.isArray(spreads))
|
428
|
+
return [0, 0];
|
429
|
+
const longSpread = spreads[0];
|
430
|
+
const shortSpread = spreads[1];
|
431
|
+
return [longSpread, shortSpread];
|
432
|
+
}
|
433
|
+
exports.calculateSpread = calculateSpread;
|
434
|
+
function calculateVolSpreadBN(lastOracleConfPct, reservePrice, markStd, oracleStd, longIntensity, shortIntensity, volume24H) {
|
435
|
+
const marketAvgStdPct = markStd
|
436
|
+
.add(oracleStd)
|
437
|
+
.mul(constants_1.PERCENTAGE_PRECISION)
|
438
|
+
.div(reservePrice)
|
439
|
+
.div(new bn_js_1.default(2));
|
440
|
+
const volSpread = bn_js_1.default.max(lastOracleConfPct, marketAvgStdPct.div(new bn_js_1.default(2)));
|
441
|
+
const clampMin = constants_1.PERCENTAGE_PRECISION.div(new bn_js_1.default(100));
|
442
|
+
const clampMax = constants_1.PERCENTAGE_PRECISION.mul(new bn_js_1.default(16)).div(new bn_js_1.default(10));
|
443
|
+
const longVolSpreadFactor = (0, math_1.clampBN)(longIntensity.mul(constants_1.PERCENTAGE_PRECISION).div(bn_js_1.default.max(constants_1.ONE, volume24H)), clampMin, clampMax);
|
444
|
+
const shortVolSpreadFactor = (0, math_1.clampBN)(shortIntensity.mul(constants_1.PERCENTAGE_PRECISION).div(bn_js_1.default.max(constants_1.ONE, volume24H)), clampMin, clampMax);
|
445
|
+
// only consider confidence interval at full value when above 25 bps
|
446
|
+
let confComponent = lastOracleConfPct;
|
447
|
+
if (lastOracleConfPct.lte(constants_1.PRICE_PRECISION.div(new bn_js_1.default(400)))) {
|
448
|
+
confComponent = lastOracleConfPct.div(new bn_js_1.default(10));
|
449
|
+
}
|
450
|
+
const longVolSpread = bn_js_1.default.max(confComponent, volSpread.mul(longVolSpreadFactor).div(constants_1.PERCENTAGE_PRECISION));
|
451
|
+
const shortVolSpread = bn_js_1.default.max(confComponent, volSpread.mul(shortVolSpreadFactor).div(constants_1.PERCENTAGE_PRECISION));
|
452
|
+
return [longVolSpread, shortVolSpread];
|
453
|
+
}
|
454
|
+
exports.calculateVolSpreadBN = calculateVolSpreadBN;
|
455
|
+
function calculatePrice(baseAssetReserves, quoteAssetReserves, pegMultiplier) {
|
456
|
+
if (baseAssetReserves.abs().lte(constants_1.ZERO)) {
|
457
|
+
return new bn_js_1.default(0);
|
458
|
+
}
|
459
|
+
return quoteAssetReserves
|
460
|
+
.mul(constants_1.PRICE_PRECISION)
|
461
|
+
.mul(pegMultiplier)
|
462
|
+
.div(constants_1.PEG_PRECISION)
|
463
|
+
.div(baseAssetReserves);
|
464
|
+
}
|
465
|
+
exports.calculatePrice = calculatePrice;
|
466
|
+
function calculateEffectiveLeverage(baseSpread, quoteAssetReserve, terminalQuoteAssetReserve, pegMultiplier, netBaseAssetAmount, reservePrice, totalFeeMinusDistributions) {
|
467
|
+
// vAMM skew
|
468
|
+
const netBaseAssetValue = quoteAssetReserve
|
469
|
+
.sub(terminalQuoteAssetReserve)
|
470
|
+
.mul(pegMultiplier)
|
471
|
+
.div(constants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO);
|
472
|
+
const localBaseAssetValue = netBaseAssetAmount
|
473
|
+
.mul(reservePrice)
|
474
|
+
.div(constants_1.AMM_TO_QUOTE_PRECISION_RATIO.mul(constants_1.PRICE_PRECISION));
|
475
|
+
const effectiveGap = Math.max(0, localBaseAssetValue.sub(netBaseAssetValue).toNumber());
|
476
|
+
const effectiveLeverage = effectiveGap / (Math.max(0, totalFeeMinusDistributions.toNumber()) + 1) +
|
477
|
+
1 / constants_1.QUOTE_PRECISION.toNumber();
|
478
|
+
return effectiveLeverage;
|
479
|
+
}
|
480
|
+
exports.calculateEffectiveLeverage = calculateEffectiveLeverage;
|
481
|
+
function calculateInventoryScale(baseAssetAmountWithAmm, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve, directionalSpread, maxSpread) {
|
482
|
+
if (baseAssetAmountWithAmm.eq(constants_1.ZERO)) {
|
483
|
+
return 1;
|
484
|
+
}
|
485
|
+
const MAX_BID_ASK_INVENTORY_SKEW_FACTOR = constants_1.BID_ASK_SPREAD_PRECISION.mul(new bn_js_1.default(10));
|
486
|
+
const inventoryScaleBN = calculateInventoryLiquidityRatio(baseAssetAmountWithAmm, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve);
|
487
|
+
const inventoryScaleMaxBN = bn_js_1.default.max(MAX_BID_ASK_INVENTORY_SKEW_FACTOR, new bn_js_1.default(maxSpread)
|
488
|
+
.mul(constants_1.BID_ASK_SPREAD_PRECISION)
|
489
|
+
.div(new bn_js_1.default(Math.max(directionalSpread, 1))));
|
490
|
+
const inventoryScaleCapped = bn_js_1.default.min(inventoryScaleMaxBN, constants_1.BID_ASK_SPREAD_PRECISION.add(inventoryScaleMaxBN.mul(inventoryScaleBN).div(constants_1.PERCENTAGE_PRECISION))).toNumber() / constants_1.BID_ASK_SPREAD_PRECISION.toNumber();
|
491
|
+
return inventoryScaleCapped;
|
492
|
+
}
|
493
|
+
exports.calculateInventoryScale = calculateInventoryScale;
|
494
|
+
function calculateInventoryLiquidityRatio(baseAssetAmountWithAmm, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve) {
|
495
|
+
// inventory skew
|
496
|
+
const [openBids, openAsks] = calculateMarketOpenBidAsk(baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve);
|
497
|
+
const minSideLiquidity = bn_js_1.default.min(openBids.abs(), openAsks.abs());
|
498
|
+
const inventoryScaleBN = bn_js_1.default.min(baseAssetAmountWithAmm
|
499
|
+
.mul(constants_1.PERCENTAGE_PRECISION)
|
500
|
+
.div(bn_js_1.default.max(minSideLiquidity, constants_1.ONE))
|
501
|
+
.abs(), constants_1.PERCENTAGE_PRECISION);
|
502
|
+
return inventoryScaleBN;
|
503
|
+
}
|
504
|
+
exports.calculateInventoryLiquidityRatio = calculateInventoryLiquidityRatio;
|
505
|
+
function calculateMarketOpenBidAsk(baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve, stepSize) {
|
506
|
+
// open orders
|
507
|
+
let openAsks;
|
508
|
+
if (minBaseAssetReserve.lt(baseAssetReserve)) {
|
509
|
+
openAsks = baseAssetReserve.sub(minBaseAssetReserve).mul(new bn_js_1.default(-1));
|
510
|
+
if (stepSize && openAsks.abs().div(constants_1.TWO).lt(stepSize)) {
|
511
|
+
openAsks = constants_1.ZERO;
|
512
|
+
}
|
513
|
+
}
|
514
|
+
else {
|
515
|
+
openAsks = constants_1.ZERO;
|
516
|
+
}
|
517
|
+
let openBids;
|
518
|
+
if (maxBaseAssetReserve.gt(baseAssetReserve)) {
|
519
|
+
openBids = maxBaseAssetReserve.sub(baseAssetReserve);
|
520
|
+
if (stepSize && openBids.div(constants_1.TWO).lt(stepSize)) {
|
521
|
+
openBids = constants_1.ZERO;
|
522
|
+
}
|
523
|
+
}
|
524
|
+
else {
|
525
|
+
openBids = constants_1.ZERO;
|
526
|
+
}
|
527
|
+
return [openBids, openAsks];
|
528
|
+
}
|
529
|
+
exports.calculateMarketOpenBidAsk = calculateMarketOpenBidAsk;
|
530
|
+
function calculateReferencePriceOffset(reservePrice, last24hAvgFundingRate, liquidityFraction, oracleTwapFast, markTwapFast, oracleTwapSlow, markTwapSlow, maxOffsetPct) {
|
531
|
+
if (last24hAvgFundingRate.eq(constants_1.ZERO)) {
|
532
|
+
return constants_1.ZERO;
|
533
|
+
}
|
534
|
+
const maxOffsetInPrice = new bn_js_1.default(maxOffsetPct)
|
535
|
+
.mul(reservePrice)
|
536
|
+
.div(constants_1.PERCENTAGE_PRECISION);
|
537
|
+
// Calculate quote denominated market premium
|
538
|
+
const markPremiumMinute = (0, math_1.clampBN)(markTwapFast.sub(oracleTwapFast), maxOffsetInPrice.mul(new bn_js_1.default(-1)), maxOffsetInPrice);
|
539
|
+
const markPremiumHour = (0, math_1.clampBN)(markTwapSlow.sub(oracleTwapSlow), maxOffsetInPrice.mul(new bn_js_1.default(-1)), maxOffsetInPrice);
|
540
|
+
// Convert last24hAvgFundingRate to quote denominated premium
|
541
|
+
const markPremiumDay = (0, math_1.clampBN)(last24hAvgFundingRate.div(constants_1.FUNDING_RATE_BUFFER_PRECISION).mul(new bn_js_1.default(24)), maxOffsetInPrice.mul(new bn_js_1.default(-1)), maxOffsetInPrice);
|
542
|
+
// Take average clamped premium as the price-based offset
|
543
|
+
const markPremiumAvg = markPremiumMinute
|
544
|
+
.add(markPremiumHour)
|
545
|
+
.add(markPremiumDay)
|
546
|
+
.div(new bn_js_1.default(3));
|
547
|
+
const markPremiumAvgPct = markPremiumAvg
|
548
|
+
.mul(constants_1.PRICE_PRECISION)
|
549
|
+
.div(reservePrice);
|
550
|
+
const inventoryPct = (0, math_1.clampBN)(liquidityFraction.mul(new bn_js_1.default(maxOffsetPct)).div(constants_1.PERCENTAGE_PRECISION), maxOffsetInPrice.mul(new bn_js_1.default(-1)), maxOffsetInPrice);
|
551
|
+
// Only apply when inventory is consistent with recent and 24h market premium
|
552
|
+
let offsetPct = markPremiumAvgPct.add(inventoryPct);
|
553
|
+
if (!(0, math_1.sigNum)(inventoryPct).eq((0, math_1.sigNum)(markPremiumAvgPct))) {
|
554
|
+
offsetPct = constants_1.ZERO;
|
555
|
+
}
|
556
|
+
const clampedOffsetPct = (0, math_1.clampBN)(offsetPct, new bn_js_1.default(-maxOffsetPct), new bn_js_1.default(maxOffsetPct));
|
557
|
+
return clampedOffsetPct;
|
558
|
+
}
|
559
|
+
exports.calculateReferencePriceOffset = calculateReferencePriceOffset;
|
560
|
+
function calculatePegFromTargetPrice(targetPrice, baseAssetReserve, quoteAssetReserve) {
|
561
|
+
return bn_js_1.default.max(targetPrice
|
562
|
+
.mul(baseAssetReserve)
|
563
|
+
.div(quoteAssetReserve)
|
564
|
+
.add(constants_1.PRICE_DIV_PEG.div(new bn_js_1.default(2)))
|
565
|
+
.div(constants_1.PRICE_DIV_PEG), constants_1.ONE);
|
566
|
+
}
|
567
|
+
//# sourceMappingURL=amm.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"amm.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/drift/perpHelpers/amm.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAsC;AACtC,yDAAyD;AACzD,kDAAuB;AAEvB,mCAMiB;AACjB,2CAcqB;AACrB,qCAAsD;AACtD,iCAAuD;AACvD,qCAAkC;AAClC,qCAAuE;AACvE,mCAIiB;AAEjB,SAAgB,iCAAiC,CAC/C,GAAQ,EACR,SAA4B,EAC5B,eAAgC;IAEhC,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACzD,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,GAAG,uBAAuB,CAC3D,MAAM,EACN,eAAe,CAChB,CAAC;IAEF,MAAM,WAAW,GAAG,IAAA,iBAAS,EAAC,SAAS,EAAE,MAAM,CAAC;QAC9C,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,aAAa,CAAC;IAElB,MAAM,MAAM,GAAG;QACb,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;QAC9C,iBAAiB,EAAE,WAAW,CAAC,iBAAiB;QAChD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,aAAa;KAC7B,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAvBD,8EAuBC;AAED,SAAgB,mBAAmB,CACjC,GAAQ,EACR,eAAgC;IAEhC,IAAI,GAAG,CAAC,oBAAoB,KAAK,CAAC,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QACpE,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,MAAM,qBAAQ,GAAG,CAAE,CAAC;IAC1B,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,eAAe,CAC5D,GAAG,EACH,eAAe,CAChB,CAAC;IAEF,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CA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AC,GAAG,CAAC,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAChC,gBAAgB,CACjB,CAAC;IAEF,6EAA6E;IAC7E,IAAI,SAAS,GAAG,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAEpD,IAAI,CAAC,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,EAAE,CAAC,IAAA,aAAM,EAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC;QACxD,SAAS,GAAG,gBAAI,CAAC;IACnB,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAA,cAAO,EAC9B,SAAS,EACT,IAAI,eAAE,CAAC,CAAC,YAAY,CAAC,EACrB,IAAI,eAAE,CAAC,YAAY,CAAC,CACrB,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AApED,sEAoEC;AAED,SAAS,2BAA2B,CAClC,WAAe,EACf,gBAAoB,EACpB,iBAAqB;IAErB,OAAO,eAAE,CAAC,GAAG,CACX,WAAW;SACR,GAAG,CAAC,gBAAgB,CAAC;SACrB,GAAG,CAAC,iBAAiB,CAAC;SACtB,GAAG,CAAC,yBAAa,CAAC,GAAG,CAAC,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACjC,GAAG,CAAC,yBAAa,CAAC,EACrB,eAAG,CACJ,CAAC;AACJ,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function assert(condition: boolean, error?: string): void;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.assert = void 0;
|
4
|
+
function assert(condition, error) {
|
5
|
+
if (!condition) {
|
6
|
+
throw new Error(error || 'Unspecified AssertionError');
|
7
|
+
}
|
8
|
+
}
|
9
|
+
exports.assert = assert;
|
10
|
+
//# sourceMappingURL=assert.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/drift/perpHelpers/assert.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAC,SAAkB,EAAE,KAAc;IACvD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,4BAA4B,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAJD,wBAIC"}
|