@gainsnetwork/sdk 0.2.67-rc8 → 0.2.69
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/contracts/addresses.json +20 -0
- package/lib/{trade/fees/borrowingV2/fetcher.d.ts → contracts/fetch/fees/borrowingFeesV2.d.ts} +3 -2
- package/lib/{trade/fees/borrowingV2/fetcher.js → contracts/fetch/fees/borrowingFeesV2.js} +14 -6
- package/lib/{trade/fees/fundingFees/fetcher.d.ts → contracts/fetch/fees/fundingFees.d.ts} +2 -2
- package/lib/{trade/priceImpact/skew/fetcher.d.ts → contracts/fetch/priceImpact/skew.d.ts} +2 -2
- package/lib/{trade/priceImpact/skew/fetcher.js → contracts/fetch/priceImpact/skew.js} +6 -6
- package/lib/contracts/index.js +3 -1
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +258 -2112
- package/lib/contracts/types/generated/GToken.d.ts +107 -78
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +53 -90
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +421 -4496
- package/lib/contracts/types/generated/factories/GToken__factory.js +142 -65
- package/lib/contracts/types/index.d.ts +2 -1
- package/lib/contracts/types/index.js +1 -0
- package/lib/trade/fees/borrowingV2/converter.d.ts +3 -12
- package/lib/trade/fees/borrowingV2/converter.js +18 -29
- package/lib/trade/fees/borrowingV2/index.d.ts +17 -6
- package/lib/trade/fees/borrowingV2/index.js +37 -10
- package/lib/trade/fees/borrowingV2/types.d.ts +6 -22
- package/lib/trade/fees/fundingFees/index.d.ts +2 -13
- package/lib/trade/fees/fundingFees/index.js +3 -27
- package/lib/trade/fees/trading/index.d.ts +2 -30
- package/lib/trade/fees/trading/index.js +1 -52
- package/lib/trade/fees/trading/types.d.ts +0 -9
- package/lib/trade/priceImpact/index.d.ts +2 -6
- package/lib/trade/priceImpact/index.js +3 -30
- package/lib/trade/priceImpact/skew/index.d.ts +0 -1
- package/lib/trade/priceImpact/skew/index.js +0 -4
- package/package.json +1 -1
- package/lib/backend/globalTrades/index.d.ts +0 -11
- package/lib/backend/globalTrades/index.js +0 -69
- package/lib/backend/index.d.ts +0 -3
- package/lib/backend/index.js +0 -28
- package/lib/backend/tradingVariables/backend.types.d.ts +0 -312
- package/lib/backend/tradingVariables/backend.types.js +0 -2
- package/lib/backend/tradingVariables/converter.d.ts +0 -31
- package/lib/backend/tradingVariables/converter.js +0 -330
- package/lib/backend/tradingVariables/index.d.ts +0 -5
- package/lib/backend/tradingVariables/index.js +0 -95
- package/lib/backend/tradingVariables/types.d.ts +0 -109
- package/lib/backend/tradingVariables/types.js +0 -14
- package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +0 -1911
- package/lib/contracts/types/generated/GFarmTradingStorageV5.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +0 -1067
- package/lib/contracts/types/generated/GNSBorrowingFees.js +0 -2
- package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +0 -533
- package/lib/contracts/types/generated/GNSNftRewardsV6.js +0 -2
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +0 -613
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +0 -2
- package/lib/contracts/types/generated/GNSTrading.d.ts +0 -758
- package/lib/contracts/types/generated/GNSTrading.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +0 -875
- package/lib/contracts/types/generated/GNSTradingCallbacks.js +0 -2
- package/lib/contracts/types/generated/GNSTradingStorage.d.ts +0 -1387
- package/lib/contracts/types/generated/GNSTradingStorage.js +0 -2
- package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +0 -1838
- package/lib/contracts/types/generated/GTokenV6_3_2.js +0 -2
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +0 -83
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +0 -2691
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +0 -124
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +0 -1784
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +0 -100
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +0 -1116
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +0 -100
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +0 -1003
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +0 -113
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +0 -1428
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +0 -96
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +0 -2241
- package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +0 -95
- package/lib/contracts/types/generated/factories/GNSTrading__factory.js +0 -1071
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +0 -110
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +0 -2682
- package/lib/contracts/utils/openLimitOrders.d.ts +0 -8
- package/lib/contracts/utils/openLimitOrders.js +0 -88
- package/lib/markets/collateral/converter.d.ts +0 -5
- package/lib/markets/collateral/converter.js +0 -11
- package/lib/markets/collateral/index.d.ts +0 -1
- package/lib/markets/collateral/index.js +0 -17
- package/lib/markets/collateral/types.d.ts +0 -7
- package/lib/markets/collateral/types.js +0 -2
- package/lib/markets/oi/converter.d.ts +0 -63
- package/lib/markets/oi/converter.js +0 -103
- package/lib/markets/oi/fetcher.d.ts +0 -58
- package/lib/markets/oi/fetcher.js +0 -181
- package/lib/markets/oi/index.d.ts +0 -10
- package/lib/markets/oi/index.js +0 -37
- package/lib/markets/oi/types.d.ts +0 -82
- package/lib/markets/oi/types.js +0 -6
- package/lib/markets/oi/validation.d.ts +0 -80
- package/lib/markets/oi/validation.js +0 -172
- package/lib/trade/fees/borrowing/builder.d.ts +0 -14
- package/lib/trade/fees/borrowing/builder.js +0 -33
- package/lib/trade/fees/borrowingV2/builder.d.ts +0 -6
- package/lib/trade/fees/borrowingV2/builder.js +0 -24
- package/lib/trade/fees/converter.d.ts +0 -48
- package/lib/trade/fees/converter.js +0 -110
- package/lib/trade/fees/fundingFees/builder.d.ts +0 -9
- package/lib/trade/fees/fundingFees/builder.js +0 -35
- package/lib/trade/fees/fundingFees/pairContext.d.ts +0 -33
- package/lib/trade/fees/fundingFees/pairContext.js +0 -17
- package/lib/trade/fees/tiers/converter.d.ts +0 -54
- package/lib/trade/fees/tiers/converter.js +0 -81
- package/lib/trade/fees/trading/builder.d.ts +0 -18
- package/lib/trade/fees/trading/builder.js +0 -20
- package/lib/trade/liquidation/builder.d.ts +0 -25
- package/lib/trade/liquidation/builder.js +0 -59
- package/lib/trade/liquidation/converter.d.ts +0 -23
- package/lib/trade/liquidation/converter.js +0 -46
- package/lib/trade/liquidation/index.d.ts +0 -26
- package/lib/trade/liquidation/index.js +0 -142
- package/lib/trade/liquidation/types.d.ts +0 -59
- package/lib/trade/liquidation/types.js +0 -2
- package/lib/trade/openLimitOrder.d.ts +0 -2
- package/lib/trade/openLimitOrder.js +0 -23
- package/lib/trade/pnl/builder.d.ts +0 -16
- package/lib/trade/pnl/builder.js +0 -44
- package/lib/trade/pnl/converter.d.ts +0 -47
- package/lib/trade/pnl/converter.js +0 -72
- package/lib/trade/pnl/index.d.ts +0 -77
- package/lib/trade/pnl/index.js +0 -270
- package/lib/trade/pnl/types.d.ts +0 -114
- package/lib/trade/pnl/types.js +0 -5
- package/lib/trade/priceImpact/close/index.d.ts +0 -21
- package/lib/trade/priceImpact/close/index.js +0 -131
- package/lib/trade/priceImpact/close/types.d.ts +0 -43
- package/lib/trade/priceImpact/close/types.js +0 -5
- package/lib/trade/priceImpact/cumulVol/converter.d.ts +0 -31
- package/lib/trade/priceImpact/cumulVol/converter.js +0 -59
- package/lib/trade/priceImpact/cumulVol/index.d.ts +0 -107
- package/lib/trade/priceImpact/cumulVol/index.js +0 -228
- package/lib/trade/priceImpact/open/index.d.ts +0 -22
- package/lib/trade/priceImpact/open/index.js +0 -76
- package/lib/trade/priceImpact/open/types.d.ts +0 -41
- package/lib/trade/priceImpact/open/types.js +0 -5
- /package/lib/{trade/fees/fundingFees/fetcher.js → contracts/fetch/fees/fundingFees.js} +0 -0
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @dev Trade opening price impact calculations
|
|
4
|
-
* @dev Mirrors contract's TradingCommonUtils.getTradeOpeningPriceImpact
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getTradeOpeningPriceImpactAtMarket = exports.getTradeOpeningPriceImpact = void 0;
|
|
8
|
-
const cumulVol_1 = require("../cumulVol");
|
|
9
|
-
const skew_1 = require("../skew");
|
|
10
|
-
/**
|
|
11
|
-
* @dev Calculates all price impacts for trade opening
|
|
12
|
-
* @dev Mirrors contract's getTradeOpeningPriceImpact function
|
|
13
|
-
* @param input Trade parameters
|
|
14
|
-
* @param context Combined context for calculations
|
|
15
|
-
* @returns Price impact breakdown and final price
|
|
16
|
-
*/
|
|
17
|
-
const getTradeOpeningPriceImpact = (input, context) => {
|
|
18
|
-
const positionSizeCollateral = input.collateralAmount * input.leverage;
|
|
19
|
-
// Calculate fixed spread
|
|
20
|
-
const spreadP = (0, cumulVol_1.getFixedSpreadP)(input.pairSpreadP, input.long, true // opening
|
|
21
|
-
);
|
|
22
|
-
// Calculate position size in USD
|
|
23
|
-
const positionSizeUsd = positionSizeCollateral * context.collateralPriceUsd;
|
|
24
|
-
// Calculate cumulative volume price impact
|
|
25
|
-
const cumulVolPriceImpactP = (0, cumulVol_1.getTradeCumulVolPriceImpactP)("", // trader - not needed for calculation
|
|
26
|
-
input.pairIndex, input.long, positionSizeUsd, false, // isPnlPositive - not relevant for opening
|
|
27
|
-
true, // open
|
|
28
|
-
0, // lastPosIncreaseBlock - not relevant for opening
|
|
29
|
-
context);
|
|
30
|
-
// Calculate skew price impact (v10+ only)
|
|
31
|
-
const skewPriceImpactP = (0, skew_1.getTradeSkewPriceImpactWithChecks)({
|
|
32
|
-
collateralIndex: input.collateralIndex,
|
|
33
|
-
pairIndex: input.pairIndex,
|
|
34
|
-
long: input.long,
|
|
35
|
-
open: true,
|
|
36
|
-
positionSizeCollateral,
|
|
37
|
-
currentPrice: input.openPrice,
|
|
38
|
-
contractsVersion: input.contractsVersion,
|
|
39
|
-
isCounterTrade: input.isCounterTrade,
|
|
40
|
-
}, context.skewContext);
|
|
41
|
-
// Total price impact (signed - can be positive or negative)
|
|
42
|
-
// Spread is always positive, impacts can be negative
|
|
43
|
-
const totalPriceImpactP = spreadP + cumulVolPriceImpactP + skewPriceImpactP;
|
|
44
|
-
// Calculate final price after impact
|
|
45
|
-
// For longs: price increases with positive impact
|
|
46
|
-
// For shorts: price decreases with positive impact
|
|
47
|
-
const priceImpactFactor = 1 + totalPriceImpactP / 100;
|
|
48
|
-
const priceAfterImpact = input.long
|
|
49
|
-
? input.openPrice * priceImpactFactor
|
|
50
|
-
: input.openPrice / priceImpactFactor;
|
|
51
|
-
// Calculate percent profit from impact
|
|
52
|
-
// Positive when trader benefits, negative when trader loses
|
|
53
|
-
const percentProfitP = input.long
|
|
54
|
-
? -totalPriceImpactP // Long loses when price goes up
|
|
55
|
-
: totalPriceImpactP; // Short gains when price goes up
|
|
56
|
-
return {
|
|
57
|
-
priceAfterImpact,
|
|
58
|
-
priceImpactP: Math.abs(totalPriceImpactP),
|
|
59
|
-
percentProfitP,
|
|
60
|
-
cumulVolPriceImpactP,
|
|
61
|
-
skewPriceImpactP,
|
|
62
|
-
totalPriceImpactP,
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
exports.getTradeOpeningPriceImpact = getTradeOpeningPriceImpact;
|
|
66
|
-
/**
|
|
67
|
-
* @dev Simplified version using current market price
|
|
68
|
-
* @param input Trade parameters
|
|
69
|
-
* @param context Combined context
|
|
70
|
-
* @param currentMarketPrice Current market price to use as open price
|
|
71
|
-
* @returns Price impact breakdown and final price
|
|
72
|
-
*/
|
|
73
|
-
const getTradeOpeningPriceImpactAtMarket = (input, context, currentMarketPrice) => {
|
|
74
|
-
return (0, exports.getTradeOpeningPriceImpact)(Object.assign(Object.assign({}, input), { openPrice: currentMarketPrice }), context);
|
|
75
|
-
};
|
|
76
|
-
exports.getTradeOpeningPriceImpactAtMarket = getTradeOpeningPriceImpactAtMarket;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @dev Types for trade opening price impact calculations
|
|
3
|
-
*/
|
|
4
|
-
import { CumulVolContext } from "../cumulVol";
|
|
5
|
-
import { SkewPriceImpactContext } from "../skew/types";
|
|
6
|
-
import { Fee, PairIndex } from "../../types";
|
|
7
|
-
/**
|
|
8
|
-
* @dev Input parameters for trade opening price impact
|
|
9
|
-
*/
|
|
10
|
-
export type TradeOpeningPriceImpactInput = {
|
|
11
|
-
collateralIndex: number;
|
|
12
|
-
pairIndex: PairIndex;
|
|
13
|
-
long: boolean;
|
|
14
|
-
collateralAmount: number;
|
|
15
|
-
leverage: number;
|
|
16
|
-
openPrice: number;
|
|
17
|
-
pairSpreadP: number;
|
|
18
|
-
fee: Fee;
|
|
19
|
-
contractsVersion: number;
|
|
20
|
-
isCounterTrade?: boolean;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* @dev Context for trade opening price impact calculation
|
|
24
|
-
* Combines contexts from spread, cumul vol, and skew
|
|
25
|
-
*/
|
|
26
|
-
export type TradeOpeningPriceImpactContext = CumulVolContext & {
|
|
27
|
-
skewContext: SkewPriceImpactContext;
|
|
28
|
-
collateralPriceUsd: number;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* @dev Result of trade opening price impact calculation
|
|
32
|
-
* Mirrors contract's PriceImpact struct
|
|
33
|
-
*/
|
|
34
|
-
export type TradeOpeningPriceImpactResult = {
|
|
35
|
-
priceAfterImpact: number;
|
|
36
|
-
priceImpactP: number;
|
|
37
|
-
percentProfitP: number;
|
|
38
|
-
cumulVolPriceImpactP: number;
|
|
39
|
-
skewPriceImpactP: number;
|
|
40
|
-
totalPriceImpactP: number;
|
|
41
|
-
};
|
|
File without changes
|