@drift-labs/sdk 0.1.30-master.1 → 0.1.30-master.4
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.js +1 -1
- package/lib/constants/markets.js +11 -8
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +31 -20
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +1 -1
- package/src/constants/markets.ts +11 -8
- package/src/tx/retryTxSender.ts +42 -26
- package/src/assert/assert.js +0 -10
- package/src/assert/assert.js.map +0 -1
- package/src/math/conversion.js +0 -16
- package/src/math/conversion.js.map +0 -1
- package/src/math/funding.js +0 -223
- package/src/math/funding.js.map +0 -1
- package/src/math/insuranceFund.js +0 -23
- package/src/math/insuranceFund.js.map +0 -1
- package/src/math/market.js +0 -30
- package/src/math/market.js.map +0 -1
- package/src/math/orders.js +0 -73
- package/src/math/orders.js.map +0 -1
- package/src/math/position.js +0 -121
- package/src/math/position.js.map +0 -1
- package/src/math/trade.js +0 -182
- package/src/math/trade.js.map +0 -1
- package/src/math/utils.js +0 -27
- package/src/math/utils.js.map +0 -1
- package/src/oracles/switchboardClient.js +0 -60
- package/src/oracles/switchboardClient.js.map +0 -1
- package/src/oracles/types.js +0 -3
- package/src/oracles/types.js.map +0 -1
- package/src/token/index.js +0 -39
- package/src/token/index.js.map +0 -1
- package/src/tx/defaultTxSender.js +0 -13
- package/src/tx/defaultTxSender.js.map +0 -1
- package/src/tx/types.js +0 -3
- package/src/tx/types.js.map +0 -1
- package/src/tx/utils.js +0 -9
- package/src/tx/utils.js.map +0 -1
- package/src/util/computeUnits.js +0 -17
- package/src/util/computeUnits.js.map +0 -1
- package/src/util/tps.js +0 -17
- package/src/util/tps.js.map +0 -1
package/src/math/orders.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
-
function isOrderRiskIncreasing(user, order) {
|
|
7
|
-
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const position = user.getUserPosition(order.marketIndex) ||
|
|
11
|
-
user.getEmptyPosition(order.marketIndex);
|
|
12
|
-
// if no position exists, it's risk increasing
|
|
13
|
-
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
// if position is long and order is long
|
|
17
|
-
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
// if position is short and order is short
|
|
21
|
-
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
22
|
-
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
const baseAssetAmountToFill = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
26
|
-
// if order will flip position
|
|
27
|
-
if (baseAssetAmountToFill.gt(position.baseAssetAmount.abs().mul(numericConstants_1.TWO))) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
|
|
33
|
-
function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
34
|
-
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const position = user.getUserPosition(order.marketIndex) ||
|
|
38
|
-
user.getEmptyPosition(order.marketIndex);
|
|
39
|
-
// if no position exists, it's risk increasing
|
|
40
|
-
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
// if position is long and order is long
|
|
44
|
-
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
// if position is short and order is short
|
|
48
|
-
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
49
|
-
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
|
|
55
|
-
function isOrderReduceOnly(user, order) {
|
|
56
|
-
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
const position = user.getUserPosition(order.marketIndex) ||
|
|
60
|
-
user.getEmptyPosition(order.marketIndex);
|
|
61
|
-
// if position is long and order is long
|
|
62
|
-
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
// if position is short and order is short
|
|
66
|
-
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
67
|
-
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return order.baseAssetAmount.abs().lte(position.baseAssetAmount.abs());
|
|
71
|
-
}
|
|
72
|
-
exports.isOrderReduceOnly = isOrderReduceOnly;
|
|
73
|
-
//# sourceMappingURL=orders.js.map
|
package/src/math/orders.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orders.js","sourceRoot":"","sources":["orders.ts"],"names":[],"mappings":";;;AACA,oCAA4C;AAC5C,oEAA0D;AAE1D,SAAgB,qBAAqB,CACpC,IAAuB,EACvB,KAAY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C,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC;AACxE,CAAC;AA1BD,8CA0BC"}
|
package/src/math/position.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEmptyPosition = exports.positionCurrentDirection = exports.findDirectionToClose = exports.calculateEntryPrice = exports.calculatePositionFundingPNL = exports.calculatePositionPNL = exports.calculateBaseAssetValue = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
const amm_1 = require("./amm");
|
|
8
|
-
/**
|
|
9
|
-
* calculateBaseAssetValue
|
|
10
|
-
* = market value of closing entire position
|
|
11
|
-
* @param market
|
|
12
|
-
* @param userPosition
|
|
13
|
-
* @returns Base Asset Value. : Precision QUOTE_PRECISION
|
|
14
|
-
*/
|
|
15
|
-
function calculateBaseAssetValue(market, userPosition) {
|
|
16
|
-
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
17
|
-
return numericConstants_1.ZERO;
|
|
18
|
-
}
|
|
19
|
-
const directionToClose = findDirectionToClose(userPosition);
|
|
20
|
-
const [newQuoteAssetReserve, _] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'base', userPosition.baseAssetAmount.abs(), (0, amm_1.getSwapDirection)('base', directionToClose));
|
|
21
|
-
switch (directionToClose) {
|
|
22
|
-
case types_1.PositionDirection.SHORT:
|
|
23
|
-
return market.amm.quoteAssetReserve
|
|
24
|
-
.sub(newQuoteAssetReserve)
|
|
25
|
-
.mul(market.amm.pegMultiplier)
|
|
26
|
-
.div(numericConstants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO);
|
|
27
|
-
case types_1.PositionDirection.LONG:
|
|
28
|
-
return newQuoteAssetReserve
|
|
29
|
-
.sub(market.amm.quoteAssetReserve)
|
|
30
|
-
.mul(market.amm.pegMultiplier)
|
|
31
|
-
.div(numericConstants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO)
|
|
32
|
-
.add(numericConstants_1.ONE);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.calculateBaseAssetValue = calculateBaseAssetValue;
|
|
36
|
-
/**
|
|
37
|
-
* calculatePositionPNL
|
|
38
|
-
* = BaseAssetAmount * (Avg Exit Price - Avg Entry Price)
|
|
39
|
-
* @param market
|
|
40
|
-
* @param marketPosition
|
|
41
|
-
* @param withFunding (adds unrealized funding payment pnl to result)
|
|
42
|
-
* @returns BaseAssetAmount : Precision QUOTE_PRECISION
|
|
43
|
-
*/
|
|
44
|
-
function calculatePositionPNL(market, marketPosition, withFunding = false) {
|
|
45
|
-
if (marketPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
46
|
-
return numericConstants_1.ZERO;
|
|
47
|
-
}
|
|
48
|
-
const baseAssetValue = calculateBaseAssetValue(market, marketPosition);
|
|
49
|
-
let pnl;
|
|
50
|
-
if (marketPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
51
|
-
pnl = baseAssetValue.sub(marketPosition.quoteAssetAmount);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
pnl = marketPosition.quoteAssetAmount.sub(baseAssetValue);
|
|
55
|
-
}
|
|
56
|
-
if (withFunding) {
|
|
57
|
-
const fundingRatePnL = calculatePositionFundingPNL(market, marketPosition).div(numericConstants_1.PRICE_TO_QUOTE_PRECISION);
|
|
58
|
-
pnl = pnl.add(fundingRatePnL);
|
|
59
|
-
}
|
|
60
|
-
return pnl;
|
|
61
|
-
}
|
|
62
|
-
exports.calculatePositionPNL = calculatePositionPNL;
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @param market
|
|
66
|
-
* @param marketPosition
|
|
67
|
-
* @returns // TODO-PRECISION
|
|
68
|
-
*/
|
|
69
|
-
function calculatePositionFundingPNL(market, marketPosition) {
|
|
70
|
-
if (marketPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
71
|
-
return numericConstants_1.ZERO;
|
|
72
|
-
}
|
|
73
|
-
let ammCumulativeFundingRate;
|
|
74
|
-
if (marketPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
75
|
-
ammCumulativeFundingRate = market.amm.cumulativeFundingRateLong;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
ammCumulativeFundingRate = market.amm.cumulativeFundingRateShort;
|
|
79
|
-
}
|
|
80
|
-
const perPositionFundingRate = ammCumulativeFundingRate
|
|
81
|
-
.sub(marketPosition.lastCumulativeFundingRate)
|
|
82
|
-
.mul(marketPosition.baseAssetAmount)
|
|
83
|
-
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
84
|
-
.div(numericConstants_1.FUNDING_PAYMENT_PRECISION)
|
|
85
|
-
.mul(new __1.BN(-1));
|
|
86
|
-
return perPositionFundingRate;
|
|
87
|
-
}
|
|
88
|
-
exports.calculatePositionFundingPNL = calculatePositionFundingPNL;
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @param userPosition
|
|
92
|
-
* @returns Precision: MARK_PRICE_PRECISION (10^10)
|
|
93
|
-
*/
|
|
94
|
-
function calculateEntryPrice(userPosition) {
|
|
95
|
-
if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
96
|
-
return numericConstants_1.ZERO;
|
|
97
|
-
}
|
|
98
|
-
return userPosition.quoteAssetAmount
|
|
99
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
100
|
-
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
101
|
-
.div(userPosition.baseAssetAmount)
|
|
102
|
-
.abs();
|
|
103
|
-
}
|
|
104
|
-
exports.calculateEntryPrice = calculateEntryPrice;
|
|
105
|
-
function findDirectionToClose(userPosition) {
|
|
106
|
-
return userPosition.baseAssetAmount.gt(numericConstants_1.ZERO)
|
|
107
|
-
? types_1.PositionDirection.SHORT
|
|
108
|
-
: types_1.PositionDirection.LONG;
|
|
109
|
-
}
|
|
110
|
-
exports.findDirectionToClose = findDirectionToClose;
|
|
111
|
-
function positionCurrentDirection(userPosition) {
|
|
112
|
-
return userPosition.baseAssetAmount.gte(numericConstants_1.ZERO)
|
|
113
|
-
? types_1.PositionDirection.LONG
|
|
114
|
-
: types_1.PositionDirection.SHORT;
|
|
115
|
-
}
|
|
116
|
-
exports.positionCurrentDirection = positionCurrentDirection;
|
|
117
|
-
function isEmptyPosition(userPosition) {
|
|
118
|
-
return (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO) && userPosition.openOrders.eq(numericConstants_1.ZERO));
|
|
119
|
-
}
|
|
120
|
-
exports.isEmptyPosition = isEmptyPosition;
|
|
121
|
-
//# sourceMappingURL=position.js.map
|
package/src/math/position.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position.js","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AACzB,oEASuC;AACvC,oCAAmE;AACnE,+BAAwE;AAExE;;;;;;GAMG;AACH,SAAgB,uBAAuB,CACtC,MAAc,EACd,YAA0B;IAE1B,IAAI,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,uBAAI,CAAC,EAAE;QAC1C,OAAO,uBAAI,CAAC;KACZ;IAED,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAE5D,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC,GAAG,IAAA,mCAA6B,EAC9D,MAAM,CAAC,GAAG,EACV,MAAM,EACN,YAAY,CAAC,eAAe,CAAC,GAAG,EAAE,EAClC,IAAA,sBAAgB,EAAC,MAAM,EAAE,gBAAgB,CAAC,CAC1C,CAAC;IAEF,QAAQ,gBAAgB,EAAE;QACzB,KAAK,yBAAiB,CAAC,KAAK;YAC3B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B,CACvC,YAA0B;IAE1B,OAAO,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,uBAAI,CAAC;QAC5C,CAAC,CAAC,yBAAiB,CAAC,IAAI;QACxB,CAAC,CAAC,yBAAiB,CAAC,KAAK,CAAC;AAC5B,CAAC;AAND,4DAMC;AAED,SAAgB,eAAe,CAAC,YAA0B;IACzD,OAAO,CACN,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,uBAAI,CAAC,IAAI,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC,uBAAI,CAAC,CACzE,CAAC;AACH,CAAC;AAJD,0CAIC"}
|
package/src/math/trade.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateTargetPriceTrade = exports.calculateTradeAcquiredAmounts = exports.calculateTradeSlippage = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const anchor_1 = require("@project-serum/anchor");
|
|
6
|
-
const assert_1 = require("../assert/assert");
|
|
7
|
-
const numericConstants_1 = require("../constants/numericConstants");
|
|
8
|
-
const market_1 = require("./market");
|
|
9
|
-
const amm_1 = require("./amm");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
const MAXPCT = new anchor_1.BN(1000); //percentage units are [0,1000] => [0,1]
|
|
12
|
-
/**
|
|
13
|
-
* Calculates avg/max slippage (price impact) for candidate trade
|
|
14
|
-
* @param direction
|
|
15
|
-
* @param amount
|
|
16
|
-
* @param market
|
|
17
|
-
* @return [pctAvgSlippage, pctMaxSlippage, entryPrice, newPrice]
|
|
18
|
-
*
|
|
19
|
-
* 'pctAvgSlippage' => the percentage change to entryPrice (average est slippage in execution) : Precision MARK_PRICE_PRECISION
|
|
20
|
-
*
|
|
21
|
-
* 'pctMaxSlippage' => the percentage change to maxPrice (highest est slippage in execution) : Precision MARK_PRICE_PRECISION
|
|
22
|
-
*
|
|
23
|
-
* 'entryPrice' => the average price of the trade : Precision MARK_PRICE_PRECISION
|
|
24
|
-
*
|
|
25
|
-
* 'newPrice' => the price of the asset after the trade : Precision MARK_PRICE_PRECISION
|
|
26
|
-
*/
|
|
27
|
-
function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quote') {
|
|
28
|
-
const oldPrice = (0, market_1.calculateMarkPrice)(market);
|
|
29
|
-
if (amount.eq(numericConstants_1.ZERO)) {
|
|
30
|
-
return [numericConstants_1.ZERO, numericConstants_1.ZERO, oldPrice, oldPrice];
|
|
31
|
-
}
|
|
32
|
-
const [acquiredBase, acquiredQuote] = calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType);
|
|
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
|
-
if (direction == types_1.PositionDirection.SHORT) {
|
|
36
|
-
(0, assert_1.assert)(newPrice.lt(oldPrice));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
(0, assert_1.assert)(oldPrice.lt(newPrice));
|
|
40
|
-
}
|
|
41
|
-
const pctMaxSlippage = newPrice
|
|
42
|
-
.sub(oldPrice)
|
|
43
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
44
|
-
.div(oldPrice)
|
|
45
|
-
.abs();
|
|
46
|
-
const pctAvgSlippage = entryPrice
|
|
47
|
-
.sub(oldPrice)
|
|
48
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
49
|
-
.div(oldPrice)
|
|
50
|
-
.abs();
|
|
51
|
-
return [pctAvgSlippage, pctMaxSlippage, entryPrice, newPrice];
|
|
52
|
-
}
|
|
53
|
-
exports.calculateTradeSlippage = calculateTradeSlippage;
|
|
54
|
-
/**
|
|
55
|
-
* Calculates acquired amounts for trade executed
|
|
56
|
-
* @param direction
|
|
57
|
-
* @param amount
|
|
58
|
-
* @param market
|
|
59
|
-
* @return
|
|
60
|
-
* | 'acquiredBase' => positive/negative change in user's base : BN TODO-PRECISION
|
|
61
|
-
* | 'acquiredQuote' => positive/negative change in user's quote : BN TODO-PRECISION
|
|
62
|
-
*/
|
|
63
|
-
function calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType = 'quote') {
|
|
64
|
-
if (amount.eq(numericConstants_1.ZERO)) {
|
|
65
|
-
return [numericConstants_1.ZERO, numericConstants_1.ZERO];
|
|
66
|
-
}
|
|
67
|
-
const swapDirection = (0, amm_1.getSwapDirection)(inputAssetType, direction);
|
|
68
|
-
const [newQuoteAssetReserve, newBaseAssetReserve] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, inputAssetType, amount, swapDirection);
|
|
69
|
-
const acquiredBase = market.amm.baseAssetReserve.sub(newBaseAssetReserve);
|
|
70
|
-
let acquiredQuote = market.amm.quoteAssetReserve.sub(newQuoteAssetReserve);
|
|
71
|
-
if (inputAssetType === 'base' && (0, types_1.isVariant)(swapDirection, 'remove')) {
|
|
72
|
-
acquiredQuote = acquiredQuote.sub(numericConstants_1.ONE);
|
|
73
|
-
}
|
|
74
|
-
return [acquiredBase, acquiredQuote];
|
|
75
|
-
}
|
|
76
|
-
exports.calculateTradeAcquiredAmounts = calculateTradeAcquiredAmounts;
|
|
77
|
-
/**
|
|
78
|
-
* calculateTargetPriceTrade
|
|
79
|
-
* simple function for finding arbitraging trades
|
|
80
|
-
* @param market
|
|
81
|
-
* @param targetPrice
|
|
82
|
-
* @param pct optional default is 100% gap filling, can set smaller.
|
|
83
|
-
* @returns trade direction/size in order to push price to a targetPrice,
|
|
84
|
-
*
|
|
85
|
-
* [
|
|
86
|
-
* direction => direction of trade required, TODO-PRECISION
|
|
87
|
-
* tradeSize => size of trade required, TODO-PRECISION
|
|
88
|
-
* entryPrice => the entry price for the trade, TODO-PRECISION
|
|
89
|
-
* targetPrice => the target price TODO-PRECISION
|
|
90
|
-
* ]
|
|
91
|
-
*/
|
|
92
|
-
function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAssetType = 'quote') {
|
|
93
|
-
(0, assert_1.assert)(market.amm.baseAssetReserve.gt(numericConstants_1.ZERO));
|
|
94
|
-
(0, assert_1.assert)(targetPrice.gt(numericConstants_1.ZERO));
|
|
95
|
-
(0, assert_1.assert)(pct.lte(MAXPCT) && pct.gt(numericConstants_1.ZERO));
|
|
96
|
-
const markPriceBefore = (0, market_1.calculateMarkPrice)(market);
|
|
97
|
-
if (targetPrice.gt(markPriceBefore)) {
|
|
98
|
-
const priceGap = targetPrice.sub(markPriceBefore);
|
|
99
|
-
const priceGapScaled = priceGap.mul(pct).div(MAXPCT);
|
|
100
|
-
targetPrice = markPriceBefore.add(priceGapScaled);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const priceGap = markPriceBefore.sub(targetPrice);
|
|
104
|
-
const priceGapScaled = priceGap.mul(pct).div(MAXPCT);
|
|
105
|
-
targetPrice = markPriceBefore.sub(priceGapScaled);
|
|
106
|
-
}
|
|
107
|
-
let direction;
|
|
108
|
-
let tradeSize;
|
|
109
|
-
let baseSize;
|
|
110
|
-
const baseAssetReserveBefore = market.amm.baseAssetReserve;
|
|
111
|
-
const quoteAssetReserveBefore = market.amm.quoteAssetReserve;
|
|
112
|
-
const peg = market.amm.pegMultiplier;
|
|
113
|
-
const invariant = market.amm.sqrtK.mul(market.amm.sqrtK);
|
|
114
|
-
const k = invariant.mul(numericConstants_1.MARK_PRICE_PRECISION);
|
|
115
|
-
let baseAssetReserveAfter;
|
|
116
|
-
let quoteAssetReserveAfter;
|
|
117
|
-
const biasModifier = new anchor_1.BN(1);
|
|
118
|
-
let markPriceAfter;
|
|
119
|
-
if (markPriceBefore.gt(targetPrice)) {
|
|
120
|
-
// overestimate y2
|
|
121
|
-
baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).sub(biasModifier)).sub(new anchor_1.BN(1));
|
|
122
|
-
quoteAssetReserveAfter = k
|
|
123
|
-
.div(numericConstants_1.MARK_PRICE_PRECISION)
|
|
124
|
-
.div(baseAssetReserveAfter);
|
|
125
|
-
markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
126
|
-
direction = types_1.PositionDirection.SHORT;
|
|
127
|
-
tradeSize = quoteAssetReserveBefore
|
|
128
|
-
.sub(quoteAssetReserveAfter)
|
|
129
|
-
.mul(peg)
|
|
130
|
-
.div(numericConstants_1.PEG_PRECISION)
|
|
131
|
-
.div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
|
|
132
|
-
baseSize = baseAssetReserveAfter.sub(baseAssetReserveBefore);
|
|
133
|
-
}
|
|
134
|
-
else if (markPriceBefore.lt(targetPrice)) {
|
|
135
|
-
// underestimate y2
|
|
136
|
-
baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).add(biasModifier)).add(new anchor_1.BN(1));
|
|
137
|
-
quoteAssetReserveAfter = k
|
|
138
|
-
.div(numericConstants_1.MARK_PRICE_PRECISION)
|
|
139
|
-
.div(baseAssetReserveAfter);
|
|
140
|
-
markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
|
|
141
|
-
direction = types_1.PositionDirection.LONG;
|
|
142
|
-
tradeSize = quoteAssetReserveAfter
|
|
143
|
-
.sub(quoteAssetReserveBefore)
|
|
144
|
-
.mul(peg)
|
|
145
|
-
.div(numericConstants_1.PEG_PRECISION)
|
|
146
|
-
.div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
|
|
147
|
-
baseSize = baseAssetReserveBefore.sub(baseAssetReserveAfter);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
// no trade, market is at target
|
|
151
|
-
direction = types_1.PositionDirection.LONG;
|
|
152
|
-
tradeSize = numericConstants_1.ZERO;
|
|
153
|
-
return [direction, tradeSize, targetPrice, targetPrice];
|
|
154
|
-
}
|
|
155
|
-
let tp1 = targetPrice;
|
|
156
|
-
let tp2 = markPriceAfter;
|
|
157
|
-
let originalDiff = targetPrice.sub(markPriceBefore);
|
|
158
|
-
if (direction == types_1.PositionDirection.SHORT) {
|
|
159
|
-
tp1 = markPriceAfter;
|
|
160
|
-
tp2 = targetPrice;
|
|
161
|
-
originalDiff = markPriceBefore.sub(targetPrice);
|
|
162
|
-
}
|
|
163
|
-
const entryPrice = tradeSize
|
|
164
|
-
.mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
|
|
165
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
166
|
-
.div(baseSize.abs());
|
|
167
|
-
(0, assert_1.assert)(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
|
|
168
|
-
(0, assert_1.assert)(tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000, 'Target Price Calculation incorrect' +
|
|
169
|
-
tp2.toString() +
|
|
170
|
-
'>=' +
|
|
171
|
-
tp1.toString() +
|
|
172
|
-
'err: ' +
|
|
173
|
-
tp2.sub(tp1).abs().toString());
|
|
174
|
-
if (outputAssetType == 'quote') {
|
|
175
|
-
return [direction, tradeSize, entryPrice, targetPrice];
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
return [direction, baseSize, entryPrice, targetPrice];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.calculateTargetPriceTrade = calculateTargetPriceTrade;
|
|
182
|
-
//# sourceMappingURL=trade.js.map
|
package/src/math/trade.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trade.js","sourceRoot":"","sources":["trade.ts"],"names":[],"mappings":";;;AAAA,oCAAgE;AAChE,kDAA2C;AAC3C,6CAA0C;AAC1C,oEAMuC;AACvC,qCAA8C;AAC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,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,oCAAoC,CAAC,CAAC;IAC7E,IAAA,eAAM,EACL,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,EAC3C,oCAAoC;QACnC,GAAG,CAAC,QAAQ,EAAE;QACd,IAAI;QACJ,GAAG,CAAC,QAAQ,EAAE;QACd,OAAO;QACP,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAC9B,CAAC;IACF,IAAI,eAAe,IAAI,OAAO,EAAE;QAC/B,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;KACvD;SAAM;QACN,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;KACtD;AACF,CAAC;AArHD,8DAqHC"}
|
package/src/math/utils.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.squareRootBN = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
const squareRootBN = (n, closeness = new __1.BN(1)) => {
|
|
6
|
-
// Assuming the sqrt of n as n only
|
|
7
|
-
let x = n;
|
|
8
|
-
// The closed guess will be stored in the root
|
|
9
|
-
let root;
|
|
10
|
-
// To count the number of iterations
|
|
11
|
-
let count = 0;
|
|
12
|
-
const TWO = new __1.BN(2);
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
-
while (count < Number.MAX_SAFE_INTEGER) {
|
|
15
|
-
count++;
|
|
16
|
-
// Calculate more closed x
|
|
17
|
-
root = x.add(n.div(x)).div(TWO);
|
|
18
|
-
// Check for closeness
|
|
19
|
-
if (x.sub(root).abs().lte(closeness))
|
|
20
|
-
break;
|
|
21
|
-
// Update root
|
|
22
|
-
x = root;
|
|
23
|
-
}
|
|
24
|
-
return root;
|
|
25
|
-
};
|
|
26
|
-
exports.squareRootBN = squareRootBN;
|
|
27
|
-
//# sourceMappingURL=utils.js.map
|
package/src/math/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAElB,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,MAAE,CAAC,CAAC,CAAC,EAAE,EAAE;IACxD,mCAAmC;IACnC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,8CAA8C;IAC9C,IAAI,IAAI,CAAC;IAET,oCAAoC;IACpC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,GAAG,GAAG,IAAI,MAAE,CAAC,CAAC,CAAC,CAAC;IAEtB,6DAA6D;IAC7D,OAAO,KAAK,GAAG,MAAM,CAAC,gBAAgB,EAAE;QACvC,KAAK,EAAE,CAAC;QAER,0BAA0B;QAC1B,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEhC,sBAAsB;QACtB,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,MAAM;QAE5C,cAAc;QACd,CAAC,GAAG,IAAI,CAAC;KACT;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AA1BW,QAAA,YAAY,gBA0BvB"}
|
|
@@ -1,60 +0,0 @@
|
|
|
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.SwitchboardClient = void 0;
|
|
7
|
-
const switchboard_v2_1 = require("@switchboard-xyz/switchboard-v2");
|
|
8
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
-
const anchor_1 = require("@project-serum/anchor");
|
|
10
|
-
const numericConstants_1 = require("../constants/numericConstants");
|
|
11
|
-
const wallet_1 = require("../wallet");
|
|
12
|
-
const switchboard_v2_json_1 = __importDefault(require("../idl/switchboard_v2.json"));
|
|
13
|
-
// cache switchboard program for every client object since itll always be the same
|
|
14
|
-
const programMap = new Map();
|
|
15
|
-
class SwitchboardClient {
|
|
16
|
-
constructor(connection, env) {
|
|
17
|
-
this.connection = connection;
|
|
18
|
-
this.env = env;
|
|
19
|
-
}
|
|
20
|
-
async getOraclePriceData(pricePublicKey) {
|
|
21
|
-
const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
|
|
22
|
-
return this.getOraclePriceDataFromBuffer(accountInfo.data);
|
|
23
|
-
}
|
|
24
|
-
async getOraclePriceDataFromBuffer(buffer) {
|
|
25
|
-
const program = await this.getProgram();
|
|
26
|
-
const aggregatorAccountData = program.account.aggregatorAccountData.coder.accounts.decode('AggregatorAccountData', buffer);
|
|
27
|
-
const price = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound.result);
|
|
28
|
-
const confidence = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound
|
|
29
|
-
.stdDeviation);
|
|
30
|
-
const slot = aggregatorAccountData.latestConfirmedRound.roundOpenSlot;
|
|
31
|
-
return {
|
|
32
|
-
price,
|
|
33
|
-
slot,
|
|
34
|
-
confidence,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async getProgram() {
|
|
38
|
-
if (programMap.has(this.env)) {
|
|
39
|
-
return programMap.get(this.env);
|
|
40
|
-
}
|
|
41
|
-
const program = await getSwitchboardProgram(this.env, this.connection);
|
|
42
|
-
programMap.set(this.env, program);
|
|
43
|
-
return program;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.SwitchboardClient = SwitchboardClient;
|
|
47
|
-
async function getSwitchboardProgram(env, connection) {
|
|
48
|
-
const DEFAULT_KEYPAIR = web3_js_1.Keypair.fromSeed(new Uint8Array(32).fill(1));
|
|
49
|
-
const programId = (0, switchboard_v2_1.getSwitchboardPid)(env);
|
|
50
|
-
const wallet = new wallet_1.Wallet(DEFAULT_KEYPAIR);
|
|
51
|
-
const provider = new anchor_1.Provider(connection, wallet, {});
|
|
52
|
-
return new anchor_1.Program(switchboard_v2_json_1.default, programId, provider);
|
|
53
|
-
}
|
|
54
|
-
function convertSwitchboardDecimal(switchboardDecimal) {
|
|
55
|
-
const switchboardPrecision = numericConstants_1.TEN.pow(new anchor_1.BN(switchboardDecimal.scale));
|
|
56
|
-
return switchboardDecimal.mantissa
|
|
57
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
58
|
-
.div(switchboardPrecision);
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=switchboardClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"switchboardClient.js","sourceRoot":"","sources":["switchboardClient.ts"],"names":[],"mappings":";;;;;;AAAA,oEAGyC;AACzC,6CAAiE;AAEjE,kDAAmE;AACnE,oEAA0E;AAE1E,sCAAmC;AACnC,qFAA0D;AAE1D,kFAAkF;AAClF,MAAM,UAAU,GAAG,IAAI,GAAG,EAAmB,CAAC;AAE9C,MAAa,iBAAiB;IAI7B,YAAmB,UAAsB,EAAE,GAAa;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC9B,cAAyB;QAEzB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC,4BAA4B,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC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AC;IAC3C,MAAM,QAAQ,GAAG,IAAI,iBAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IAEtD,OAAO,IAAI,gBAAO,CAAC,6BAAuB,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,yBAAyB,CAAC,kBAAsC;IACxE,MAAM,oBAAoB,GAAG,sBAAG,CAAC,GAAG,CAAC,IAAI,WAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO,kBAAkB,CAAC,QAAQ;SAChC,GAAG,CAAC,uCAAoB,CAAC;SACzB,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAC7B,CAAC"}
|
package/src/oracles/types.js
DELETED
package/src/oracles/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
|
package/src/token/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTokenAccount = void 0;
|
|
4
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
function parseTokenAccount(data) {
|
|
7
|
-
const accountInfo = spl_token_1.AccountLayout.decode(data);
|
|
8
|
-
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
|
|
9
|
-
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
|
|
10
|
-
accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
|
|
11
|
-
if (accountInfo.delegateOption === 0) {
|
|
12
|
-
accountInfo.delegate = null;
|
|
13
|
-
// eslint-disable-next-line new-cap
|
|
14
|
-
accountInfo.delegatedAmount = new spl_token_1.u64(0);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
|
|
18
|
-
accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
|
|
19
|
-
}
|
|
20
|
-
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
21
|
-
accountInfo.isFrozen = accountInfo.state === 2;
|
|
22
|
-
if (accountInfo.isNativeOption === 1) {
|
|
23
|
-
accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
|
|
24
|
-
accountInfo.isNative = true;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
accountInfo.rentExemptReserve = null;
|
|
28
|
-
accountInfo.isNative = false;
|
|
29
|
-
}
|
|
30
|
-
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
-
accountInfo.closeAuthority = null;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
|
|
35
|
-
}
|
|
36
|
-
return accountInfo;
|
|
37
|
-
}
|
|
38
|
-
exports.parseTokenAccount = parseTokenAccount;
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
package/src/token/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAoE;AACpE,6CAA4C;AAE5C,SAAgB,iBAAiB,CAAC,IAAY;IAC7C,MAAM,WAAW,GAAG,yBAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/C,WAAW,CAAC,IAAI,GAAG,IAAI,mBAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACnD,WAAW,CAAC,KAAK,GAAG,IAAI,mBAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACrD,WAAW,CAAC,MAAM,GAAG,eAAG,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAExD,IAAI,WAAW,CAAC,cAAc,KAAK,CAAC,EAAE;QACrC,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC5B,mCAAmC;QACnC,WAAW,CAAC,eAAe,GAAG,IAAI,eAAG,CAAC,CAAC,CAAC,CAAC;KACzC;SAAM;QACN,WAAW,CAAC,QAAQ,GAAG,IAAI,mBAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC3D,WAAW,CAAC,eAAe,GAAG,eAAG,CAAC,UAAU,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;KAC1E;IAED,WAAW,CAAC,aAAa,GAAG,WAAW,CAAC,KAAK,KAAK,CAAC,CAAC;IACpD,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,KAAK,KAAK,CAAC,CAAC;IAE/C,IAAI,WAAW,CAAC,cAAc,KAAK,CAAC,EAAE;QACrC,WAAW,CAAC,iBAAiB,GAAG,eAAG,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACrE,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC;KAC5B;SAAM;QACN,WAAW,CAAC,iBAAiB,GAAG,IAAI,CAAC;QACrC,WAAW,CAAC,QAAQ,GAAG,KAAK,CAAC;KAC7B;IAED,IAAI,WAAW,CAAC,oBAAoB,KAAK,CAAC,EAAE;QAC3C,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC;KAClC;SAAM;QACN,WAAW,CAAC,cAAc,GAAG,IAAI,mBAAS,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;KACvE;IAED,OAAO,WAAW,CAAC;AACpB,CAAC;AAjCD,8CAiCC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultTxSender = void 0;
|
|
4
|
-
class DefaultTxSender {
|
|
5
|
-
constructor(provider) {
|
|
6
|
-
this.provider = provider;
|
|
7
|
-
}
|
|
8
|
-
send(tx, additionalSigners, opts) {
|
|
9
|
-
return this.provider.send(tx, additionalSigners, opts);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.DefaultTxSender = DefaultTxSender;
|
|
13
|
-
//# sourceMappingURL=defaultTxSender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultTxSender.js","sourceRoot":"","sources":["defaultTxSender.ts"],"names":[],"mappings":";;;AASA,MAAa,eAAe;IAG3B,YAAmB,QAAkB;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,IAAI,CACH,EAAe,EACf,iBAAiC,EACjC,IAAqB;QAErB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;CACD;AAdD,0CAcC"}
|
package/src/tx/types.js
DELETED
package/src/tx/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
|
package/src/tx/utils.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapInTx = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
function wrapInTx(instruction) {
|
|
6
|
-
return new web3_js_1.Transaction().add(instruction);
|
|
7
|
-
}
|
|
8
|
-
exports.wrapInTx = wrapInTx;
|
|
9
|
-
//# sourceMappingURL=utils.js.map
|
package/src/tx/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAAA,6CAAsE;AAEtE,SAAgB,QAAQ,CAAC,WAAmC;IAC3D,OAAO,IAAI,qBAAW,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC3C,CAAC;AAFD,4BAEC"}
|
package/src/util/computeUnits.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findComputeUnitConsumption = void 0;
|
|
4
|
-
async function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
|
|
5
|
-
const tx = await connection.getTransaction(txSignature, { commitment });
|
|
6
|
-
const computeUnits = [];
|
|
7
|
-
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of 200000 compute units`);
|
|
8
|
-
tx.meta.logMessages.forEach((logMessage) => {
|
|
9
|
-
const match = logMessage.match(regex);
|
|
10
|
-
if (match && match[1]) {
|
|
11
|
-
computeUnits.push(match[1]);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return computeUnits;
|
|
15
|
-
}
|
|
16
|
-
exports.findComputeUnitConsumption = findComputeUnitConsumption;
|
|
17
|
-
//# sourceMappingURL=computeUnits.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"computeUnits.js","sourceRoot":"","sources":["computeUnits.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,0BAA0B,CAC/C,SAAoB,EACpB,UAAsB,EACtB,WAAmB,EACnB,aAAuB,WAAW;IAElC,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,MAAM,CACvB,WAAW,SAAS,CAAC,QAAQ,EAAE,gDAAgD,CAC/E,CAAC;IACF,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;YACtB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5B;IACF,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACrB,CAAC;AAlBD,gEAkBC"}
|
package/src/util/tps.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.estimateTps = void 0;
|
|
4
|
-
async function estimateTps(programId, connection, failed) {
|
|
5
|
-
let signatures = await connection.getSignaturesForAddress(programId, undefined, 'finalized');
|
|
6
|
-
if (failed) {
|
|
7
|
-
signatures = signatures.filter((signature) => signature.err);
|
|
8
|
-
}
|
|
9
|
-
const numberOfSignatures = signatures.length;
|
|
10
|
-
if (numberOfSignatures === 0) {
|
|
11
|
-
return 0;
|
|
12
|
-
}
|
|
13
|
-
return (numberOfSignatures /
|
|
14
|
-
(signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
|
|
15
|
-
}
|
|
16
|
-
exports.estimateTps = estimateTps;
|
|
17
|
-
//# sourceMappingURL=tps.js.map
|
package/src/util/tps.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tps.js","sourceRoot":"","sources":["tps.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,WAAW,CAChC,SAAoB,EACpB,UAAsB,EACtB,MAAe;IAEf,IAAI,UAAU,GAAG,MAAM,UAAU,CAAC,uBAAuB,CACxD,SAAS,EACT,SAAS,EACT,WAAW,CACX,CAAC;IACF,IAAI,MAAM,EAAE;QACX,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC7D;IAED,MAAM,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC;IAE7C,IAAI,kBAAkB,KAAK,CAAC,EAAE;QAC7B,OAAO,CAAC,CAAC;KACT;IAED,OAAO,CACN,kBAAkB;QAClB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,UAAU,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CACxE,CAAC;AACH,CAAC;AAxBD,kCAwBC"}
|