@gmx-io/sdk 2.9.1 → 2.9.3
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/build/cjs/src/clients/v2/index.js +61 -41
- package/build/cjs/src/clients/v2/solana.spec.js +188 -0
- package/build/cjs/src/configs/api.js +4 -0
- package/build/cjs/src/utils/fees/index.js +7 -1
- package/build/cjs/src/utils/fees/priceImpact.js +118 -18
- package/build/cjs/src/utils/gmsol/__tests__/fixtures/nativeMath.json +3171 -0
- package/build/cjs/src/utils/gmsol/__tests__/nativeMath.spec.js +213 -0
- package/build/cjs/src/utils/gmsol/constants.js +12 -0
- package/build/cjs/src/utils/gmsol/fees.js +19 -0
- package/build/cjs/src/utils/gmsol/index.js +66 -0
- package/build/cjs/src/utils/gmsol/markets.js +206 -0
- package/build/cjs/src/utils/gmsol/numbers.js +230 -0
- package/build/cjs/src/utils/gmsol/positions.js +152 -0
- package/build/cjs/src/utils/gmsol/types.js +2 -0
- package/build/cjs/src/utils/http/http.js +3 -4
- package/build/cjs/src/utils/http/httpFallback.js +11 -1
- package/build/cjs/src/utils/http/solana.js +17 -0
- package/build/cjs/src/utils/http/validation.js +21 -1
- package/build/cjs/src/utils/http/validation.spec.js +45 -0
- package/build/cjs/src/utils/markets/__tests__/api.spec.js +53 -0
- package/build/cjs/src/utils/markets/api.js +5 -0
- package/build/cjs/src/utils/markets/utils.js +25 -9
- package/build/cjs/src/utils/orders/api.js +3 -0
- package/build/cjs/src/utils/positions/__tests__/liquidationPrice.spec.js +64 -0
- package/build/cjs/src/utils/positions/api.js +3 -0
- package/build/cjs/src/utils/positions/utils.js +88 -19
- package/build/cjs/src/utils/prices/utils.js +69 -14
- package/build/cjs/src/utils/referrals/api.js +41 -0
- package/build/cjs/src/utils/swap/swapRouting.js +4 -0
- package/build/cjs/src/utils/swap/swapStats.js +6 -1
- package/build/cjs/src/utils/trade/__tests__/gmsolTradeMath.spec.js +1012 -0
- package/build/cjs/src/utils/trade/decrease.js +266 -56
- package/build/cjs/src/utils/trade/decreaseMarginCheck.js +23 -4
- package/build/cjs/src/utils/trade/increase.js +86 -28
- package/build/cjs/src/utils/trade/increaseMarginCheck.js +51 -9
- package/build/cjs/src/utils/trade/twapIncreaseMarginCheck.js +8 -3
- package/build/esm/src/clients/v2/index.js +39 -19
- package/build/esm/src/clients/v2/solana.spec.js +160 -0
- package/build/esm/src/configs/api.js +5 -1
- package/build/esm/src/utils/fees/index.js +7 -1
- package/build/esm/src/utils/fees/priceImpact.js +111 -12
- package/build/esm/src/utils/gmsol/__tests__/fixtures/nativeMath.json +3171 -0
- package/build/esm/src/utils/gmsol/__tests__/nativeMath.spec.js +208 -0
- package/build/esm/src/utils/gmsol/constants.js +9 -0
- package/build/esm/src/utils/gmsol/fees.js +15 -0
- package/build/esm/src/utils/gmsol/index.js +46 -0
- package/build/esm/src/utils/gmsol/markets.js +193 -0
- package/build/esm/src/utils/gmsol/numbers.js +226 -0
- package/build/esm/src/utils/gmsol/positions.js +148 -0
- package/build/esm/src/utils/gmsol/types.js +1 -0
- package/build/esm/src/utils/http/http.js +3 -4
- package/build/esm/src/utils/http/httpFallback.js +11 -1
- package/build/esm/src/utils/http/solana.js +12 -0
- package/build/esm/src/utils/http/validation.js +18 -0
- package/build/esm/src/utils/http/validation.spec.js +43 -0
- package/build/esm/src/utils/markets/__tests__/api.spec.js +53 -0
- package/build/esm/src/utils/markets/api.js +6 -1
- package/build/esm/src/utils/markets/utils.js +23 -8
- package/build/esm/src/utils/orders/api.js +3 -0
- package/build/esm/src/utils/positions/__tests__/liquidationPrice.spec.js +62 -0
- package/build/esm/src/utils/positions/api.js +3 -0
- package/build/esm/src/utils/positions/utils.js +89 -20
- package/build/esm/src/utils/prices/utils.js +70 -15
- package/build/esm/src/utils/referrals/api.js +36 -0
- package/build/esm/src/utils/swap/swapRouting.js +4 -0
- package/build/esm/src/utils/swap/swapStats.js +7 -2
- package/build/esm/src/utils/trade/__tests__/gmsolTradeMath.spec.js +1010 -0
- package/build/esm/src/utils/trade/decrease.js +266 -56
- package/build/esm/src/utils/trade/decreaseMarginCheck.js +23 -4
- package/build/esm/src/utils/trade/increase.js +86 -28
- package/build/esm/src/utils/trade/increaseMarginCheck.js +53 -11
- package/build/esm/src/utils/trade/twapIncreaseMarginCheck.js +8 -3
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/clients/v2/index.d.ts +21 -12
- package/build/types/src/clients/v2/solana.spec.d.ts +1 -0
- package/build/types/src/utils/fees/index.d.ts +1 -1
- package/build/types/src/utils/fees/priceImpact.d.ts +7 -0
- package/build/types/src/utils/gmsol/__tests__/nativeMath.spec.d.ts +1 -0
- package/build/types/src/utils/gmsol/constants.d.ts +9 -0
- package/build/types/src/utils/gmsol/fees.d.ts +6 -0
- package/build/types/src/utils/gmsol/index.d.ts +38 -0
- package/build/types/src/utils/gmsol/markets.d.ts +49 -0
- package/build/types/src/utils/gmsol/numbers.d.ts +11 -0
- package/build/types/src/utils/gmsol/positions.d.ts +7 -0
- package/build/types/src/utils/gmsol/types.d.ts +105 -0
- package/build/types/src/utils/http/http.d.ts +2 -5
- package/build/types/src/utils/http/httpFallback.d.ts +2 -5
- package/build/types/src/utils/http/solana.d.ts +4 -0
- package/build/types/src/utils/http/types.d.ts +17 -4
- package/build/types/src/utils/http/validation.d.ts +8 -0
- package/build/types/src/utils/http/validation.spec.d.ts +1 -0
- package/build/types/src/utils/markets/hashKeys.d.ts +1 -1
- package/build/types/src/utils/markets/types.d.ts +3 -2
- package/build/types/src/utils/markets/utils.d.ts +6 -2
- package/build/types/src/utils/orders/api.d.ts +2 -2
- package/build/types/src/utils/positions/__tests__/liquidationPrice.spec.d.ts +1 -0
- package/build/types/src/utils/positions/api.d.ts +2 -2
- package/build/types/src/utils/positions/types.d.ts +1 -0
- package/build/types/src/utils/positions/utils.d.ts +6 -1
- package/build/types/src/utils/prices/types.d.ts +16 -0
- package/build/types/src/utils/prices/utils.d.ts +3 -11
- package/build/types/src/utils/referrals/api.d.ts +8 -0
- package/build/types/src/utils/referrals/types.d.ts +5 -0
- package/build/types/src/utils/rpc/createViemRpc.d.ts +25 -3
- package/build/types/src/utils/trade/__tests__/gmsolTradeMath.spec.d.ts +1 -0
- package/build/types/src/utils/trade/decrease.d.ts +5 -0
- package/build/types/src/utils/trade/decreaseMarginCheck.d.ts +2 -0
- package/build/types/src/utils/trade/increase.d.ts +2 -0
- package/build/types/src/utils/trade/increaseMarginCheck.d.ts +2 -0
- package/build/types/src/utils/trade/twapIncreaseMarginCheck.d.ts +1 -0
- package/build/types/src/utils/trade/types.d.ts +6 -0
- package/package.json +10 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MarketInfo } from "../markets/types";
|
|
2
1
|
import { OrderType } from "../orders/types";
|
|
3
2
|
import { TokenPrices } from "../tokens/types";
|
|
4
3
|
import { TriggerThresholdType } from "../trade/types";
|
|
4
|
+
import type { AcceptablePriceParams } from "./types";
|
|
5
5
|
export declare function getMarkPrice(p: {
|
|
6
6
|
prices: TokenPrices;
|
|
7
7
|
isIncrease: boolean;
|
|
@@ -19,16 +19,7 @@ export declare function getIncreaseEvaluationIndexPrice(p: {
|
|
|
19
19
|
orderType: OrderType | undefined;
|
|
20
20
|
triggerPrice: bigint | undefined;
|
|
21
21
|
}): bigint | undefined;
|
|
22
|
-
export declare function getAcceptablePriceInfo(p: {
|
|
23
|
-
marketInfo: MarketInfo;
|
|
24
|
-
isIncrease: boolean;
|
|
25
|
-
isLimit: boolean;
|
|
26
|
-
isLong: boolean;
|
|
27
|
-
indexPrice: bigint;
|
|
28
|
-
sizeDeltaUsd: bigint;
|
|
29
|
-
maxNegativePriceImpactBps?: bigint;
|
|
30
|
-
sizeDeltaInTokens?: bigint;
|
|
31
|
-
}): {
|
|
22
|
+
export declare function getAcceptablePriceInfo(p: AcceptablePriceParams): {
|
|
32
23
|
acceptablePrice: bigint;
|
|
33
24
|
acceptablePriceDeltaBps: bigint;
|
|
34
25
|
priceImpactDeltaAmount: bigint;
|
|
@@ -54,4 +45,5 @@ export declare function getDefaultAcceptablePriceImpactBps(p: {
|
|
|
54
45
|
sizeDeltaUsd: bigint;
|
|
55
46
|
priceImpactDeltaUsd: bigint;
|
|
56
47
|
acceptablePriceImpactBuffer?: number;
|
|
48
|
+
executionPrice?: bigint;
|
|
57
49
|
}): bigint;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IHttp } from "../http/types";
|
|
2
|
+
import type { FeeDiscount } from "./types";
|
|
3
|
+
export declare function parseFeeDiscount(raw: unknown): FeeDiscount;
|
|
4
|
+
export declare function fetchApiFeeDiscount(ctx: {
|
|
5
|
+
api: IHttp;
|
|
6
|
+
}, params: {
|
|
7
|
+
address: string;
|
|
8
|
+
}): Promise<FeeDiscount>;
|
|
@@ -11,6 +11,11 @@ export type UserReferralInfo = {
|
|
|
11
11
|
discountFactor: bigint;
|
|
12
12
|
error?: Error;
|
|
13
13
|
};
|
|
14
|
+
export type FeeDiscount = {
|
|
15
|
+
userReferralInfo: UserReferralInfo;
|
|
16
|
+
orderFeeDiscountFactor: bigint;
|
|
17
|
+
updatedAt: number | undefined;
|
|
18
|
+
};
|
|
14
19
|
export declare enum RebateDistributionType {
|
|
15
20
|
Rebate = "1",
|
|
16
21
|
Claim = "1000",
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { IRpc, StateOverrideEntry } from "./index";
|
|
2
|
+
type ViemRpcRequest = {
|
|
3
|
+
account: `0x${string}` | undefined;
|
|
4
|
+
to: `0x${string}`;
|
|
5
|
+
data: `0x${string}`;
|
|
6
|
+
value: bigint;
|
|
7
|
+
stateOverride: ReturnType<typeof mapStateOverride>;
|
|
8
|
+
};
|
|
9
|
+
declare function mapStateOverride(entries?: StateOverrideEntry[]): {
|
|
10
|
+
address: `0x${string}`;
|
|
11
|
+
stateDiff: {
|
|
12
|
+
slot: `0x${string}`;
|
|
13
|
+
value: `0x${string}`;
|
|
14
|
+
}[] | undefined;
|
|
15
|
+
balance: bigint | undefined;
|
|
16
|
+
nonce: number | undefined;
|
|
17
|
+
code: `0x${string}` | undefined;
|
|
18
|
+
}[] | undefined;
|
|
19
|
+
export declare function createViemRpc(client: {
|
|
20
|
+
estimateGas(params: ViemRpcRequest): Promise<bigint>;
|
|
21
|
+
call(params: ViemRpcRequest): Promise<{
|
|
22
|
+
data?: string;
|
|
23
|
+
}>;
|
|
24
|
+
}): IRpc;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -22,6 +22,7 @@ export declare function getDecreasePositionAmounts(p: {
|
|
|
22
22
|
acceptablePriceImpactBuffer?: number;
|
|
23
23
|
userReferralInfo: UserReferralInfo | undefined;
|
|
24
24
|
proDiscountFactor?: bigint;
|
|
25
|
+
feeDiscountFactor?: bigint;
|
|
25
26
|
minCollateralUsd: bigint;
|
|
26
27
|
minPositionSizeUsd: bigint;
|
|
27
28
|
uiFeeFactor: bigint;
|
|
@@ -43,6 +44,7 @@ export declare function getIsFullClose(p: {
|
|
|
43
44
|
}): boolean;
|
|
44
45
|
export declare function getMinCollateralUsdForLeverage(position: PositionInfoLoaded, openInterestDelta: bigint): bigint;
|
|
45
46
|
export declare function getMinRequiredCollateralUsdForPosition(p: {
|
|
47
|
+
feeDiscountFactor?: bigint;
|
|
46
48
|
position: PositionInfoLoaded;
|
|
47
49
|
minCollateralUsd: bigint | undefined;
|
|
48
50
|
userReferralInfo: UserReferralInfo | undefined;
|
|
@@ -54,6 +56,7 @@ export declare function getMaxWithdrawAmount(p: {
|
|
|
54
56
|
collateralDecimals: number | undefined;
|
|
55
57
|
userReferralInfo: UserReferralInfo | undefined;
|
|
56
58
|
proDiscountFactor?: bigint;
|
|
59
|
+
feeDiscountFactor?: bigint;
|
|
57
60
|
}): bigint;
|
|
58
61
|
export declare function getIsProfitKeptInPnlToken(p: {
|
|
59
62
|
pnlToken: TokenData;
|
|
@@ -110,6 +113,7 @@ export declare function getNextPositionValuesForDecreaseTrade(p: {
|
|
|
110
113
|
isLong: boolean;
|
|
111
114
|
minCollateralUsd: bigint;
|
|
112
115
|
userReferralInfo: UserReferralInfo | undefined;
|
|
116
|
+
feeDiscountFactor?: bigint;
|
|
113
117
|
priceImpactDiffUsd?: bigint;
|
|
114
118
|
}): NextPositionValues;
|
|
115
119
|
export declare function getDecreaseSwapType(pnlToken: TokenData, collateralToken: TokenData, receiveToken: TokenData): DecreasePositionSwapType;
|
|
@@ -136,6 +140,7 @@ export declare function getOptimalDecreaseAndSwapAmounts(p: {
|
|
|
136
140
|
acceptablePriceImpactBuffer?: number;
|
|
137
141
|
userReferralInfo: UserReferralInfo | undefined;
|
|
138
142
|
proDiscountFactor?: bigint;
|
|
143
|
+
feeDiscountFactor?: bigint;
|
|
139
144
|
minCollateralUsd: bigint;
|
|
140
145
|
minPositionSizeUsd: bigint;
|
|
141
146
|
uiFeeFactor: bigint;
|
|
@@ -25,6 +25,7 @@ export type DecreaseResultingPositionMarginStateParams = {
|
|
|
25
25
|
minPositionSizeUsd: bigint;
|
|
26
26
|
userReferralInfo: UserReferralInfo | undefined;
|
|
27
27
|
proDiscountFactor?: bigint;
|
|
28
|
+
feeDiscountFactor?: bigint;
|
|
28
29
|
indexPriceForEvaluation?: bigint;
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
@@ -44,6 +45,7 @@ export type TriggerDecreaseRemainingPositionMarginStateParams = {
|
|
|
44
45
|
minPositionSizeUsd: bigint;
|
|
45
46
|
userReferralInfo: UserReferralInfo | undefined;
|
|
46
47
|
proDiscountFactor?: bigint;
|
|
48
|
+
feeDiscountFactor?: bigint;
|
|
47
49
|
};
|
|
48
50
|
/**
|
|
49
51
|
* The same gates for a Take-Profit or Stop-Loss at its trigger price: `decreaseAmounts` are its amounts at that
|
|
@@ -20,6 +20,7 @@ type IncreasePositionParams = {
|
|
|
20
20
|
acceptablePriceImpactBuffer?: number;
|
|
21
21
|
userReferralInfo: UserReferralInfo | undefined;
|
|
22
22
|
proDiscountFactor?: bigint;
|
|
23
|
+
feeDiscountFactor?: bigint;
|
|
23
24
|
strategy: "leverageBySize" | "leverageByCollateral" | "independent";
|
|
24
25
|
findSwapPath: FindSwapPath;
|
|
25
26
|
uiFeeFactor: bigint;
|
|
@@ -89,6 +90,7 @@ export declare function getNextPositionValuesForIncreaseTrade(p: {
|
|
|
89
90
|
showPnlInLeverage: boolean;
|
|
90
91
|
minCollateralUsd: bigint;
|
|
91
92
|
userReferralInfo: UserReferralInfo | undefined;
|
|
93
|
+
feeDiscountFactor?: bigint;
|
|
92
94
|
collateralPrice?: bigint;
|
|
93
95
|
}): NextPositionValues;
|
|
94
96
|
export {};
|
|
@@ -28,6 +28,7 @@ export type PositionMarginStateParams = {
|
|
|
28
28
|
isLong: boolean;
|
|
29
29
|
userReferralInfo: UserReferralInfo | undefined;
|
|
30
30
|
proDiscountFactor?: bigint;
|
|
31
|
+
feeDiscountFactor?: bigint;
|
|
31
32
|
shouldValidateMinCollateralUsd?: boolean;
|
|
32
33
|
};
|
|
33
34
|
/**
|
|
@@ -54,6 +55,7 @@ export type IncreaseResultingPositionMarginStateParams = {
|
|
|
54
55
|
minCollateralUsd: bigint;
|
|
55
56
|
userReferralInfo: UserReferralInfo | undefined;
|
|
56
57
|
proDiscountFactor?: bigint;
|
|
58
|
+
feeDiscountFactor?: bigint;
|
|
57
59
|
indexPriceForEvaluation?: bigint;
|
|
58
60
|
};
|
|
59
61
|
export declare function getMarketInfoAtIndexPrice(p: {
|
|
@@ -35,6 +35,7 @@ export type TwapIncreaseSequentialMarginStateParams = TwapIncreaseSequenceParams
|
|
|
35
35
|
minCollateralUsd: bigint;
|
|
36
36
|
userReferralInfo: UserReferralInfo | undefined;
|
|
37
37
|
proDiscountFactor?: bigint;
|
|
38
|
+
feeDiscountFactor?: bigint;
|
|
38
39
|
};
|
|
39
40
|
export type TwapIncreaseSequentialMarginState = {
|
|
40
41
|
numberOfParts: number;
|
|
@@ -45,7 +45,12 @@ export type SwapAmounts = {
|
|
|
45
45
|
minOutputAmount: bigint;
|
|
46
46
|
uiFeeUsd?: bigint;
|
|
47
47
|
};
|
|
48
|
+
export type FundingPayout = {
|
|
49
|
+
longTokenAmount: bigint;
|
|
50
|
+
shortTokenAmount: bigint;
|
|
51
|
+
};
|
|
48
52
|
export type IncreasePositionAmounts = {
|
|
53
|
+
fundingPayout?: FundingPayout;
|
|
49
54
|
initialCollateralAmount: bigint;
|
|
50
55
|
initialCollateralUsd: bigint;
|
|
51
56
|
collateralDeltaAmount: bigint;
|
|
@@ -79,6 +84,7 @@ export type DecreasePositionOutput = {
|
|
|
79
84
|
usd: bigint;
|
|
80
85
|
};
|
|
81
86
|
export type DecreasePositionAmounts = {
|
|
87
|
+
fundingPayout?: FundingPayout;
|
|
82
88
|
isFullClose: boolean;
|
|
83
89
|
sizeDeltaUsd: bigint;
|
|
84
90
|
sizeDeltaInTokens: bigint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmx-io/sdk",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -161,6 +161,9 @@
|
|
|
161
161
|
],
|
|
162
162
|
"utils/twap/uiFeeReceiver": [
|
|
163
163
|
"./build/types/src/utils/twap/uiFeeReceiver.d.ts"
|
|
164
|
+
],
|
|
165
|
+
"utils/gmsol": [
|
|
166
|
+
"./build/types/src/utils/gmsol/index.d.ts"
|
|
164
167
|
]
|
|
165
168
|
}
|
|
166
169
|
},
|
|
@@ -506,6 +509,12 @@
|
|
|
506
509
|
"import": "./build/esm/src/utils/twap/uiFeeReceiver.js",
|
|
507
510
|
"require": "./build/cjs/src/utils/twap/uiFeeReceiver.js",
|
|
508
511
|
"default": "./build/cjs/src/utils/twap/uiFeeReceiver.js"
|
|
512
|
+
},
|
|
513
|
+
"./utils/gmsol": {
|
|
514
|
+
"types": "./build/types/src/utils/gmsol/index.d.ts",
|
|
515
|
+
"import": "./build/esm/src/utils/gmsol/index.js",
|
|
516
|
+
"require": "./build/cjs/src/utils/gmsol/index.js",
|
|
517
|
+
"default": "./build/cjs/src/utils/gmsol/index.js"
|
|
509
518
|
}
|
|
510
519
|
},
|
|
511
520
|
"scripts": {
|