@sonarwatch/portfolio-plugins 0.14.116 → 0.14.117
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/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/plugins/jupiter/exchange/helpersPerps.d.ts +40 -0
- package/src/plugins/jupiter/exchange/helpersPerps.js +156 -0
- package/src/plugins/jupiter/exchange/helpersPerps.js.map +1 -0
- package/src/plugins/jupiter/exchange/perpetualFetcher.js +10 -5
- package/src/plugins/jupiter/exchange/perpetualFetcher.js.map +1 -1
- package/src/plugins/jupiter/exchange/helpers.d.ts +0 -2
- package/src/plugins/jupiter/exchange/helpers.js +0 -29
- package/src/plugins/jupiter/exchange/helpers.js.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
4
4
|
|
5
|
+
## [0.14.117](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.116...plugins-0.14.117) (2025-02-20)
|
6
|
+
|
7
|
+
|
8
|
+
|
5
9
|
## [0.14.116](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.115...plugins-0.14.116) (2025-02-19)
|
6
10
|
|
7
11
|
|
package/package.json
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
import BN from 'bn.js';
|
2
|
+
import { CustodyInfo } from '../types';
|
3
|
+
import { Position } from './structs';
|
4
|
+
export declare const USD_POWER: BN;
|
5
|
+
export type CustodyBn = Omit<CustodyInfo, 'pricing' | 'decreasePositionBps' | 'fundingRateState' | 'jumpRateState' | 'assets'> & {
|
6
|
+
decreasePositionBps: BN;
|
7
|
+
pricing: {
|
8
|
+
tradeImpactFeeScalar: BN;
|
9
|
+
maxLeverage: BN;
|
10
|
+
};
|
11
|
+
fundingRateState: {
|
12
|
+
hourlyFundingBps: BN;
|
13
|
+
lastUpdate: BN;
|
14
|
+
cumulativeInterestRate: BN;
|
15
|
+
};
|
16
|
+
jumpRateState: {
|
17
|
+
minRateBps: BN;
|
18
|
+
maxRateBps: BN;
|
19
|
+
targetRateBps: BN;
|
20
|
+
targetUtilizationRate: BN;
|
21
|
+
};
|
22
|
+
assets: {
|
23
|
+
feesReserves: BN;
|
24
|
+
owned: BN;
|
25
|
+
locked: BN;
|
26
|
+
guaranteedUsd: BN;
|
27
|
+
globalShortSizes: BN;
|
28
|
+
globalShortAveragePrices: BN;
|
29
|
+
};
|
30
|
+
};
|
31
|
+
export type PositionBn = Omit<Position, 'price' | 'collateralUsd' | 'sizeUsd' | 'cumulativeInterestSnapshot'> & {
|
32
|
+
price: BN;
|
33
|
+
collateralUsd: BN;
|
34
|
+
sizeUsd: BN;
|
35
|
+
cumulativeInterestSnapshot: BN;
|
36
|
+
};
|
37
|
+
export declare function custodyToBN(custody: CustodyInfo): CustodyBn;
|
38
|
+
export declare function positionToBn(position: Position): PositionBn;
|
39
|
+
export declare const getFeeAmount: (baseFeeBps: BN, amount: BN, tradeImpactFeeScalar: BN) => BN;
|
40
|
+
export declare const getLiquidationPrice: (position: PositionBn, custody: CustodyBn, collateralCustody: CustodyBn, curtime: BN) => BN;
|
@@ -0,0 +1,156 @@
|
|
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.getLiquidationPrice = exports.getFeeAmount = exports.positionToBn = exports.custodyToBN = exports.USD_POWER = void 0;
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
8
|
+
const structs_1 = require("./structs");
|
9
|
+
exports.USD_POWER = new bn_js_1.default(1000000);
|
10
|
+
const BPS_POWER = new bn_js_1.default(10000);
|
11
|
+
const DBPS_POWER = new bn_js_1.default(100000);
|
12
|
+
const RATE_POWER = new bn_js_1.default(1000000000);
|
13
|
+
const HOURS_IN_A_YEAR = 24 * 365;
|
14
|
+
var BorrowRateMechanism;
|
15
|
+
(function (BorrowRateMechanism) {
|
16
|
+
BorrowRateMechanism[BorrowRateMechanism["Linear"] = 0] = "Linear";
|
17
|
+
BorrowRateMechanism[BorrowRateMechanism["Jump"] = 1] = "Jump";
|
18
|
+
})(BorrowRateMechanism || (BorrowRateMechanism = {}));
|
19
|
+
function custodyToBN(custody) {
|
20
|
+
return Object.assign(Object.assign({}, custody), { decreasePositionBps: new bn_js_1.default(custody.decreasePositionBps), pricing: {
|
21
|
+
tradeImpactFeeScalar: new bn_js_1.default(custody.pricing.tradeSpreadLong),
|
22
|
+
maxLeverage: new bn_js_1.default(custody.pricing.maxLeverage),
|
23
|
+
}, fundingRateState: {
|
24
|
+
hourlyFundingBps: new bn_js_1.default(custody.fundingRateState.hourlyFundingBps.toString()),
|
25
|
+
lastUpdate: new bn_js_1.default(custody.fundingRateState.lastUpdate.toString()),
|
26
|
+
cumulativeInterestRate: new bn_js_1.default(custody.fundingRateState.cumulativeInterestRate.toString()),
|
27
|
+
}, jumpRateState: {
|
28
|
+
maxRateBps: new bn_js_1.default(custody.jumpRateState.maxRateBps.toString()),
|
29
|
+
minRateBps: new bn_js_1.default(custody.jumpRateState.minRateBps.toString()),
|
30
|
+
targetRateBps: new bn_js_1.default(custody.jumpRateState.targetRateBps.toString()),
|
31
|
+
targetUtilizationRate: new bn_js_1.default(custody.jumpRateState.targetUtilizationRate.toString()),
|
32
|
+
}, assets: {
|
33
|
+
feesReserves: new bn_js_1.default(custody.assets.feesReserves),
|
34
|
+
owned: new bn_js_1.default(custody.assets.owned),
|
35
|
+
locked: new bn_js_1.default(custody.assets.locked),
|
36
|
+
guaranteedUsd: new bn_js_1.default(custody.assets.guaranteedUsd),
|
37
|
+
globalShortSizes: new bn_js_1.default(custody.assets.globalShortSizes),
|
38
|
+
globalShortAveragePrices: new bn_js_1.default(custody.assets.globalShortAveragePrices),
|
39
|
+
} });
|
40
|
+
}
|
41
|
+
exports.custodyToBN = custodyToBN;
|
42
|
+
function positionToBn(position) {
|
43
|
+
return Object.assign(Object.assign({}, position), { price: new bn_js_1.default(position.price.toString()), collateralUsd: new bn_js_1.default(position.collateralUsd.toString()), sizeUsd: new bn_js_1.default(position.sizeUsd.toString()), cumulativeInterestSnapshot: new bn_js_1.default(position.cumulativeInterestSnapshot.toString()) });
|
44
|
+
}
|
45
|
+
exports.positionToBn = positionToBn;
|
46
|
+
const divCeil = (a, b) => {
|
47
|
+
const dm = a.divmod(b);
|
48
|
+
// Fast case - exact division
|
49
|
+
if (dm.mod.isZero())
|
50
|
+
return dm.div;
|
51
|
+
// Round up
|
52
|
+
return dm.div.ltn(0) ? dm.div.isubn(1) : dm.div.iaddn(1);
|
53
|
+
};
|
54
|
+
const getImpactFeeBps = (amount, tradeImpactFeeScalar) => tradeImpactFeeScalar.eqn(0)
|
55
|
+
? new bn_js_1.default(0)
|
56
|
+
: divCeil(amount.mul(BPS_POWER), tradeImpactFeeScalar);
|
57
|
+
const getFeeAmount = (baseFeeBps, amount, tradeImpactFeeScalar) => {
|
58
|
+
if (amount.eqn(0)) {
|
59
|
+
return new bn_js_1.default(0);
|
60
|
+
}
|
61
|
+
const impactFeeCoefficientBps = getImpactFeeBps(amount, tradeImpactFeeScalar);
|
62
|
+
const totalFeeBps = impactFeeCoefficientBps.add(baseFeeBps);
|
63
|
+
return amount.mul(totalFeeBps).div(BPS_POWER);
|
64
|
+
};
|
65
|
+
exports.getFeeAmount = getFeeAmount;
|
66
|
+
function getBorrowRateMechanism(custody) {
|
67
|
+
if (!custody.fundingRateState.hourlyFundingBps.eq(new bn_js_1.default(0))) {
|
68
|
+
return BorrowRateMechanism.Linear;
|
69
|
+
}
|
70
|
+
return BorrowRateMechanism.Jump;
|
71
|
+
}
|
72
|
+
const getHourlyBorrowRate = (custody) => {
|
73
|
+
const borrowRateMechanism = getBorrowRateMechanism(custody);
|
74
|
+
if (borrowRateMechanism === BorrowRateMechanism.Linear) {
|
75
|
+
const hourlyFundingRate = custody.fundingRateState.hourlyFundingBps
|
76
|
+
.mul(RATE_POWER)
|
77
|
+
.div(DBPS_POWER);
|
78
|
+
return custody.assets.owned.gtn(0) && custody.assets.locked.gtn(0)
|
79
|
+
? custody.assets.locked.mul(hourlyFundingRate).div(custody.assets.owned)
|
80
|
+
: new bn_js_1.default(0);
|
81
|
+
}
|
82
|
+
const { minRateBps, maxRateBps, targetRateBps, targetUtilizationRate } = custody.jumpRateState;
|
83
|
+
const utilizationRate = custody.assets.owned.gtn(0) && custody.assets.locked.gtn(0)
|
84
|
+
? custody.assets.locked.mul(RATE_POWER).div(custody.assets.owned)
|
85
|
+
: new bn_js_1.default(0);
|
86
|
+
let yearlyRate;
|
87
|
+
if (utilizationRate.lte(targetUtilizationRate)) {
|
88
|
+
yearlyRate = targetRateBps
|
89
|
+
.sub(minRateBps)
|
90
|
+
.mul(utilizationRate)
|
91
|
+
.div(targetUtilizationRate)
|
92
|
+
.add(minRateBps)
|
93
|
+
.mul(RATE_POWER)
|
94
|
+
.div(BPS_POWER);
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
const rateDiff = maxRateBps.sub(targetRateBps);
|
98
|
+
const utilDiff = utilizationRate.sub(targetUtilizationRate);
|
99
|
+
const denom = RATE_POWER.sub(targetUtilizationRate);
|
100
|
+
yearlyRate = rateDiff
|
101
|
+
.mul(utilDiff)
|
102
|
+
.div(denom)
|
103
|
+
.add(targetRateBps)
|
104
|
+
.mul(RATE_POWER)
|
105
|
+
.div(BPS_POWER);
|
106
|
+
}
|
107
|
+
return yearlyRate.divn(HOURS_IN_A_YEAR);
|
108
|
+
};
|
109
|
+
const getCurrentFundingRate = (custody, curtime) => {
|
110
|
+
if (custody.assets.owned.eqn(0))
|
111
|
+
return new bn_js_1.default(0);
|
112
|
+
const interval = curtime.sub(custody.fundingRateState.lastUpdate);
|
113
|
+
const currentFundingRate = getHourlyBorrowRate(custody);
|
114
|
+
return currentFundingRate.mul(interval).div(new bn_js_1.default(3600));
|
115
|
+
};
|
116
|
+
const getCumulativeInterest = (custody, curtime) => {
|
117
|
+
if (curtime.gt(custody.fundingRateState.lastUpdate)) {
|
118
|
+
const fundingRate = getCurrentFundingRate(custody, curtime);
|
119
|
+
return custody.fundingRateState.cumulativeInterestRate.add(fundingRate);
|
120
|
+
}
|
121
|
+
return custody.fundingRateState.cumulativeInterestRate;
|
122
|
+
};
|
123
|
+
const getFundingFee = (custody, position, curtime) => {
|
124
|
+
if (position.sizeUsd.eqn(0))
|
125
|
+
return new bn_js_1.default(0);
|
126
|
+
const cumulativeInterest = getCumulativeInterest(custody, curtime);
|
127
|
+
const positionInterest = cumulativeInterest.sub(position.cumulativeInterestSnapshot);
|
128
|
+
return positionInterest.mul(position.sizeUsd).div(RATE_POWER);
|
129
|
+
};
|
130
|
+
const getLiquidationPrice = (position, custody, collateralCustody, curtime) => {
|
131
|
+
const sizeUsd = new bn_js_1.default(position.sizeUsd.toString());
|
132
|
+
if (sizeUsd.eqn(0))
|
133
|
+
return new bn_js_1.default(0);
|
134
|
+
const closePositionFeeUsd = (0, exports.getFeeAmount)(custody.decreasePositionBps, sizeUsd, custody.pricing.tradeImpactFeeScalar);
|
135
|
+
const fundingFeeUsd = getFundingFee(collateralCustody, position, curtime);
|
136
|
+
const feeUsd = closePositionFeeUsd.add(fundingFeeUsd);
|
137
|
+
const maxLossUsd = sizeUsd
|
138
|
+
.mul(BPS_POWER)
|
139
|
+
.div(custody.pricing.maxLeverage)
|
140
|
+
.add(feeUsd);
|
141
|
+
const marginUsd = position.collateralUsd;
|
142
|
+
let maxPriceDiff = maxLossUsd.sub(marginUsd).abs();
|
143
|
+
maxPriceDiff = maxPriceDiff.mul(position.price).div(sizeUsd);
|
144
|
+
if (position.side === structs_1.Side.Long) {
|
145
|
+
if (maxLossUsd.gt(marginUsd)) {
|
146
|
+
return position.price.add(maxPriceDiff);
|
147
|
+
}
|
148
|
+
return position.price.sub(maxPriceDiff);
|
149
|
+
}
|
150
|
+
if (maxLossUsd.gt(marginUsd)) {
|
151
|
+
return position.price.sub(maxPriceDiff);
|
152
|
+
}
|
153
|
+
return position.price.add(maxPriceDiff);
|
154
|
+
};
|
155
|
+
exports.getLiquidationPrice = getLiquidationPrice;
|
156
|
+
//# sourceMappingURL=helpersPerps.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpersPerps.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/helpersPerps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAuB;AAEvB,uCAA2C;AAE9B,QAAA,SAAS,GAAG,IAAI,eAAE,CAAC,OAAS,CAAC,CAAC;AAC3C,MAAM,SAAS,GAAG,IAAI,eAAE,CAAC,KAAM,CAAC,CAAC;AACjC,MAAM,UAAU,GAAG,IAAI,eAAE,CAAC,MAAO,CAAC,CAAC;AACnC,MAAM,UAAU,GAAG,IAAI,eAAE,CAAC,UAAa,CAAC,CAAC;AACzC,MAAM,eAAe,GAAG,EAAE,GAAG,GAAG,CAAC;AAEjC,IAAK,mBAGJ;AAHD,WAAK,mBAAmB;IACtB,iEAAM,CAAA;IACN,6DAAI,CAAA;AACN,CAAC,EAHI,mBAAmB,KAAnB,mBAAmB,QAGvB;AA8CD,SAAgB,WAAW,CAAC,OAAoB;IAC9C,uCACK,OAAO,KACV,mBAAmB,EAAE,IAAI,eAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,EACxD,OAAO,EAAE;YACP,oBAAoB,EAAE,IAAI,eAAE,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC;YAC7D,WAAW,EAAE,IAAI,eAAE,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;SACjD,EACD,gBAAgB,EAAE;YAChB,gBAAgB,EAAE,IAAI,eAAE,CACtB,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CACrD;YACD,UAAU,EAAE,IAAI,eAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,UAAU,C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,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC,CAAC;AAtCW,QAAA,mBAAmB,uBAsC9B"}
|
@@ -21,7 +21,7 @@ const solana_1 = require("../../../utils/solana");
|
|
21
21
|
const filters_1 = require("../filters");
|
22
22
|
const constants_1 = require("./constants");
|
23
23
|
const structs_1 = require("./structs");
|
24
|
-
const
|
24
|
+
const helpersPerps_1 = require("./helpersPerps");
|
25
25
|
const usdFactor = new bignumber_js_1.default(Math.pow(10, 6));
|
26
26
|
const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
|
27
27
|
const client = (0, clients_1.getClientSolana)();
|
@@ -80,9 +80,14 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
80
80
|
const size = sizeValue.div(entryPrice);
|
81
81
|
const leverage = sizeUsd.dividedBy(collateralUsd);
|
82
82
|
const collateralValue = collateralUsd.dividedBy(usdFactor);
|
83
|
-
const openFee = (0,
|
84
|
-
const closeFee = (0,
|
85
|
-
const
|
83
|
+
const openFee = (0, helpersPerps_1.getFeeAmount)(new bn_js_1.BN(custody.increasePositionBps), new bn_js_1.BN(sizeUsd.toString()), new bn_js_1.BN(custody.pricing.tradeSpreadLong));
|
84
|
+
const closeFee = (0, helpersPerps_1.getFeeAmount)(new bn_js_1.BN(custody.increasePositionBps), new bn_js_1.BN(sizeUsd.toString()), new bn_js_1.BN(custody.pricing.tradeSpreadLong));
|
85
|
+
const curtime = new bn_js_1.BN(Number(new Date()) / 1000);
|
86
|
+
const liquidationPriceBn = (0, helpersPerps_1.getLiquidationPrice)((0, helpersPerps_1.positionToBn)(position), (0, helpersPerps_1.custodyToBN)(custody), (0, helpersPerps_1.custodyToBN)(collateralCustody), curtime);
|
87
|
+
const liquidationPrice = new bignumber_js_1.default(liquidationPriceBn.toString())
|
88
|
+
.div(usdFactor)
|
89
|
+
.toNumber();
|
90
|
+
const openAndCloseFees = openFee.add(closeFee).div(helpersPerps_1.USD_POWER);
|
86
91
|
const borrowFee = sizeUsd
|
87
92
|
.times(new bignumber_js_1.default(collateralCustody.fundingRateState.cumulativeInterestRate).minus(cumulativeInterestSnapshot))
|
88
93
|
.dividedBy(Math.pow(10, 15))
|
@@ -99,7 +104,7 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
99
104
|
address: custody.mint,
|
100
105
|
side: isLong ? portfolio_core_1.LeverageSide.long : portfolio_core_1.LeverageSide.short,
|
101
106
|
leverage: leverage.toNumber(),
|
102
|
-
liquidationPrice
|
107
|
+
liquidationPrice,
|
103
108
|
collateralValue: collateralValue.toNumber(),
|
104
109
|
size: size.toNumber(),
|
105
110
|
sizeValue: sizeValue.toNumber(),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"perpetualFetcher.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/perpetualFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAOoC;AACpC,gEAAqC;AACrC,6CAA4C;AAC5C,iCAA2B;AAG3B,oDAAyD;AACzD,kDAAgF;AAChF,wCAAuD;AAEvD,2CAKqB;AACrB,uCAAiD;AACjD,
|
1
|
+
{"version":3,"file":"perpetualFetcher.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/perpetualFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAOoC;AACpC,gEAAqC;AACrC,6CAA4C;AAC5C,iCAA2B;AAG3B,oDAAyD;AACzD,kDAAgF;AAChF,wCAAuD;AAEvD,2CAKqB;AACrB,uCAAiD;AACjD,iDAMwB;AAExB,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,SAAA,EAAE,EAAI,CAAC,CAAA,CAAC,CAAC;AACzC,MAAM,QAAQ,GAAoB,CAChC,KAAa,EACb,KAAY,EACyB,EAAE;IACvC,MAAM,MAAM,GAAG,IAAA,yBA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I,CAAC,QAAQ,EAAE;YACrB,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE;YAC/B,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE;YAChC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;YACvB,SAAS,EAAE,YAAY;YACvB,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE;SAClC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,IAAA,+BAAc,EAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,OAAO;QACL;YACE,IAAI,EAAE,qCAAoB,CAAC,QAAQ;YACnC,IAAI,EAAE;gBACJ,QAAQ,EAAE;oBACR,SAAS,EAAE,YAAY;oBACvB,KAAK;iBACN;gBACD,KAAK;aACN;YACD,KAAK,EAAE,UAAU;YACjB,SAAS,EAAE,0BAAS,CAAC,MAAM;YAC3B,UAAU,EAAV,sBAAU;YACV,KAAK;SACN;KACF,CAAC;AACJ,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,YAAY;IAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;IAC3B,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
@@ -1,29 +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.getFeeAmount = void 0;
|
7
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
8
|
-
const BPS_POWER = new bn_js_1.default(10000);
|
9
|
-
const divCeil = (a, b) => {
|
10
|
-
const dm = a.divmod(b);
|
11
|
-
// Fast case - exact division
|
12
|
-
if (dm.mod.isZero())
|
13
|
-
return dm.div;
|
14
|
-
// Round up
|
15
|
-
return dm.div.ltn(0) ? dm.div.isubn(1) : dm.div.iaddn(1);
|
16
|
-
};
|
17
|
-
const getImpactFeeBps = (amount, tradeImpactFeeScalar) => tradeImpactFeeScalar.eqn(0)
|
18
|
-
? new bn_js_1.default(0)
|
19
|
-
: divCeil(amount.mul(BPS_POWER), tradeImpactFeeScalar);
|
20
|
-
const getFeeAmount = (baseFeeBps, amount, tradeImpactFeeScalar) => {
|
21
|
-
if (amount.eqn(0)) {
|
22
|
-
return new bn_js_1.default(0);
|
23
|
-
}
|
24
|
-
const impactFeeCoefficientBps = getImpactFeeBps(amount, tradeImpactFeeScalar);
|
25
|
-
const totalFeeBps = impactFeeCoefficientBps.add(baseFeeBps);
|
26
|
-
return amount.mul(totalFeeBps).div(BPS_POWER);
|
27
|
-
};
|
28
|
-
exports.getFeeAmount = getFeeAmount;
|
29
|
-
//# sourceMappingURL=helpers.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAuB;AAEvB,MAAM,SAAS,GAAG,IAAI,eAAE,CAAC,KAAM,CAAC,CAAC;AAEjC,MAAM,OAAO,GAAG,CAAC,CAAK,EAAE,CAAK,EAAE,EAAE;IAC/B,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvB,6BAA6B;IAC7B,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,CAAC,GAAG,CAAC;IACnC,WAAW;IACX,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAA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