@gmx-io/sdk 2.9.2 → 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/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 +4 -1
- package/build/cjs/src/utils/gmsol/fees.js +19 -0
- package/build/cjs/src/utils/gmsol/index.js +14 -1
- package/build/cjs/src/utils/gmsol/markets.js +206 -0
- package/build/cjs/src/utils/gmsol/numbers.js +55 -1
- package/build/cjs/src/utils/gmsol/positions.js +152 -0
- 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 +3 -0
- package/build/esm/src/utils/gmsol/fees.js +15 -0
- package/build/esm/src/utils/gmsol/index.js +5 -2
- package/build/esm/src/utils/gmsol/markets.js +193 -0
- package/build/esm/src/utils/gmsol/numbers.js +55 -1
- package/build/esm/src/utils/gmsol/positions.js +148 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/utils/gmsol/__tests__/nativeMath.spec.d.ts +1 -0
- package/build/types/src/utils/gmsol/constants.d.ts +4 -0
- package/build/types/src/utils/gmsol/fees.d.ts +6 -0
- package/build/types/src/utils/gmsol/index.d.ts +6 -3
- package/build/types/src/utils/gmsol/markets.d.ts +49 -0
- package/build/types/src/utils/gmsol/numbers.d.ts +10 -0
- package/build/types/src/utils/gmsol/positions.d.ts +7 -0
- package/build/types/src/utils/gmsol/types.d.ts +96 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { GmsolSide } from "./types";
|
|
1
2
|
export declare const GMSOL_PRECISION: bigint;
|
|
2
3
|
export declare const GMSOL_PRECISION_SCALE: bigint;
|
|
3
4
|
export declare const GMSOL_MAX_UNSIGNED: bigint;
|
|
4
5
|
export declare const GMSOL_MAX_SIGNED: bigint;
|
|
5
6
|
export declare const GMSOL_MAX_IMPACT_EXPONENT: bigint;
|
|
7
|
+
export declare const GMSOL_LONG: GmsolSide;
|
|
8
|
+
export declare const GMSOL_SHORT: GmsolSide;
|
|
9
|
+
export declare const GMSOL_SIDES: readonly GmsolSide[];
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { TokenData } from "../tokens/types";
|
|
2
|
-
export { GMSOL_PRECISION_SCALE } from "./constants";
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
2
|
+
export { GMSOL_PRECISION, GMSOL_PRECISION_SCALE } from "./constants";
|
|
3
|
+
export { getGmsolOrderFeeDiscountFactor } from "./fees";
|
|
4
|
+
export { getGmsolBorrowingFactorPerSecond, getGmsolMarketStatus, getGmsolNextFunding, getGmsolNextPositionImpactPoolAmount, getGmsolPendingBorrowingFees, getGmsolPoolValue, } from "./markets";
|
|
5
|
+
export { getGmsolFractionalPower, gmsolMath } from "./numbers";
|
|
6
|
+
export { getGmsolPendingPositionFees } from "./positions";
|
|
7
|
+
export type { GmsolFeeDiscountConfig, GmsolFundingParams, GmsolMarketConfig, GmsolMarketPrices, GmsolMarketState, GmsolMarketStatus, GmsolNextFunding, GmsolPendingPositionFees, GmsolPerSide, GmsolPnlFactorKind, GmsolPositionState, GmsolPriceRange, GmsolSide, } from "./types";
|
|
5
8
|
export declare function getGmsolUsdAmount(value: bigint): bigint;
|
|
6
9
|
export declare function getGmsolMidPrice(token: TokenData): bigint;
|
|
7
10
|
/** The impact is settled in the entry size; it never becomes pending collateral. 0 means the order fills no tokens. */
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GmsolMarketPrices, GmsolMarketState, GmsolMarketStatus, GmsolNextFunding, GmsolPnlFactorKind, GmsolPriceRange, GmsolSide } from "./types";
|
|
2
|
+
export declare function getGmsolReservedValue({ market, prices, side, }: {
|
|
3
|
+
market: GmsolMarketState;
|
|
4
|
+
prices: GmsolMarketPrices;
|
|
5
|
+
side: GmsolSide;
|
|
6
|
+
}): bigint;
|
|
7
|
+
export declare function getGmsolPoolValueWithoutPnl({ market, prices, side, maximize, }: {
|
|
8
|
+
market: GmsolMarketState;
|
|
9
|
+
prices: GmsolMarketPrices;
|
|
10
|
+
side: GmsolSide;
|
|
11
|
+
maximize: boolean;
|
|
12
|
+
}): bigint;
|
|
13
|
+
export declare function getGmsolPendingPnl({ market, indexPrice, side, maximize, }: {
|
|
14
|
+
market: GmsolMarketState;
|
|
15
|
+
indexPrice: GmsolPriceRange;
|
|
16
|
+
side: GmsolSide;
|
|
17
|
+
maximize: boolean;
|
|
18
|
+
}): bigint;
|
|
19
|
+
export declare function getGmsolBorrowingFactorPerSecond({ market, prices, side, }: {
|
|
20
|
+
market: GmsolMarketState;
|
|
21
|
+
prices: GmsolMarketPrices;
|
|
22
|
+
side: GmsolSide;
|
|
23
|
+
}): bigint;
|
|
24
|
+
export declare function getGmsolNextCumulativeBorrowingFactor({ market, prices, now, side, }: {
|
|
25
|
+
market: GmsolMarketState;
|
|
26
|
+
prices: GmsolMarketPrices;
|
|
27
|
+
now: number;
|
|
28
|
+
side: GmsolSide;
|
|
29
|
+
}): bigint;
|
|
30
|
+
export declare function getGmsolPendingBorrowingFees({ market, prices, now, side, }: {
|
|
31
|
+
market: GmsolMarketState;
|
|
32
|
+
prices: GmsolMarketPrices;
|
|
33
|
+
now: number;
|
|
34
|
+
side: GmsolSide;
|
|
35
|
+
}): bigint;
|
|
36
|
+
export declare function getGmsolNextPositionImpactPoolAmount(market: GmsolMarketState, now: number): bigint;
|
|
37
|
+
export declare function getGmsolPoolValue({ market, prices, now, pnlFactorKind, maximize, }: {
|
|
38
|
+
market: GmsolMarketState;
|
|
39
|
+
prices: GmsolMarketPrices;
|
|
40
|
+
now: number;
|
|
41
|
+
pnlFactorKind: GmsolPnlFactorKind;
|
|
42
|
+
maximize: boolean;
|
|
43
|
+
}): bigint;
|
|
44
|
+
export declare function getGmsolNextFunding(market: GmsolMarketState, now: number): GmsolNextFunding;
|
|
45
|
+
export declare function getGmsolMarketStatus({ market, prices, now, }: {
|
|
46
|
+
market: GmsolMarketState;
|
|
47
|
+
prices: GmsolMarketPrices;
|
|
48
|
+
now: number;
|
|
49
|
+
}): GmsolMarketStatus;
|
|
@@ -1 +1,11 @@
|
|
|
1
1
|
export declare function getGmsolFractionalPower(base20: bigint, exponent20: bigint): bigint;
|
|
2
|
+
export declare const gmsolMath: {
|
|
3
|
+
toUnsigned(value: bigint, what: string): bigint;
|
|
4
|
+
toSigned(value: bigint, what: string): bigint;
|
|
5
|
+
mulDiv(a: bigint, b: bigint, divisor: bigint, what: string): bigint;
|
|
6
|
+
mulDivCeil(a: bigint, b: bigint, divisor: bigint, what: string): bigint;
|
|
7
|
+
roundUpDiv(value: bigint, divisor: bigint, what: string): bigint;
|
|
8
|
+
applyFactor(value: bigint, factor: bigint, what: string): bigint;
|
|
9
|
+
divToFactor(value: bigint, divisor: bigint, what: string): bigint;
|
|
10
|
+
applyExponentFactor(value: bigint, exponent: bigint, what: string): bigint;
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GmsolMarketPrices, GmsolMarketState, GmsolPendingPositionFees, GmsolPositionState } from "./types";
|
|
2
|
+
export declare function getGmsolPendingPositionFees({ market, prices, now, position, }: {
|
|
3
|
+
market: GmsolMarketState;
|
|
4
|
+
prices: GmsolMarketPrices;
|
|
5
|
+
now: number;
|
|
6
|
+
position: GmsolPositionState;
|
|
7
|
+
}): GmsolPendingPositionFees;
|
|
@@ -7,3 +7,99 @@ export type Decimal = {
|
|
|
7
7
|
coefficient: bigint;
|
|
8
8
|
scale: number;
|
|
9
9
|
};
|
|
10
|
+
export type GmsolSide = 0 | 1;
|
|
11
|
+
export type GmsolPerSide = readonly [long: bigint, short: bigint];
|
|
12
|
+
export type GmsolPriceRange = {
|
|
13
|
+
min: bigint;
|
|
14
|
+
max: bigint;
|
|
15
|
+
};
|
|
16
|
+
export type GmsolMarketPrices = {
|
|
17
|
+
index: GmsolPriceRange;
|
|
18
|
+
long: GmsolPriceRange;
|
|
19
|
+
short: GmsolPriceRange;
|
|
20
|
+
};
|
|
21
|
+
export type GmsolPnlFactorKind = "maxAfterDeposit" | "maxAfterWithdrawal" | "maxForTrader";
|
|
22
|
+
export type GmsolFundingParams = {
|
|
23
|
+
exponent: bigint;
|
|
24
|
+
factor: bigint;
|
|
25
|
+
maxFactorPerSecond: bigint;
|
|
26
|
+
minFactorPerSecond: bigint;
|
|
27
|
+
increaseFactorPerSecond: bigint;
|
|
28
|
+
decreaseFactorPerSecond: bigint;
|
|
29
|
+
thresholdForStableFunding: bigint;
|
|
30
|
+
thresholdForDecreaseFunding: bigint;
|
|
31
|
+
};
|
|
32
|
+
export type GmsolMarketState = {
|
|
33
|
+
name: string;
|
|
34
|
+
marketTokenMint: string;
|
|
35
|
+
longTokenMint: string;
|
|
36
|
+
shortTokenMint: string;
|
|
37
|
+
store: string;
|
|
38
|
+
config: {
|
|
39
|
+
reserveFactor: bigint;
|
|
40
|
+
openInterestReserveFactor: bigint;
|
|
41
|
+
borrowingFeeReceiverFactor: bigint;
|
|
42
|
+
positionImpactDistributeFactor: bigint;
|
|
43
|
+
minPositionImpactPoolAmount: bigint;
|
|
44
|
+
maxPnlFactorForLongDeposit: bigint;
|
|
45
|
+
maxPnlFactorForShortDeposit: bigint;
|
|
46
|
+
maxPnlFactorForLongWithdrawal: bigint;
|
|
47
|
+
maxPnlFactorForShortWithdrawal: bigint;
|
|
48
|
+
maxPnlFactorForLongTrader: bigint;
|
|
49
|
+
maxPnlFactorForShortTrader: bigint;
|
|
50
|
+
};
|
|
51
|
+
skipBorrowingFeeForSmallerSide: boolean;
|
|
52
|
+
ignoreOpenInterestForUsageFactor: boolean;
|
|
53
|
+
borrowingFeeFactor: GmsolPerSide;
|
|
54
|
+
borrowingFeeExponent: GmsolPerSide;
|
|
55
|
+
borrowingFeeOptimalUsageFactor: GmsolPerSide;
|
|
56
|
+
borrowingFeeBaseFactor: GmsolPerSide;
|
|
57
|
+
borrowingFeeAboveOptimalUsageFactor: GmsolPerSide;
|
|
58
|
+
maxOpenInterest: GmsolPerSide;
|
|
59
|
+
funding: GmsolFundingParams;
|
|
60
|
+
primary: GmsolPerSide;
|
|
61
|
+
openInterest: GmsolPerSide;
|
|
62
|
+
openInterestInTokens: GmsolPerSide;
|
|
63
|
+
openInterestByCollateral: readonly [GmsolPerSide, GmsolPerSide];
|
|
64
|
+
positionImpactPoolAmount: bigint;
|
|
65
|
+
borrowingFactor: GmsolPerSide;
|
|
66
|
+
fundingFeeAmountPerSize: readonly [GmsolPerSide, GmsolPerSide];
|
|
67
|
+
claimableFundingAmountPerSize: readonly [GmsolPerSide, GmsolPerSide];
|
|
68
|
+
totalBorrowing: GmsolPerSide;
|
|
69
|
+
priceImpactDistributionClock: number;
|
|
70
|
+
borrowingClock: number;
|
|
71
|
+
fundingClock: number;
|
|
72
|
+
fundingFactorPerSecond: bigint;
|
|
73
|
+
};
|
|
74
|
+
export type GmsolPositionState = {
|
|
75
|
+
store: string;
|
|
76
|
+
marketToken: string;
|
|
77
|
+
collateralToken: string;
|
|
78
|
+
isLong: boolean;
|
|
79
|
+
sizeInUsd: bigint;
|
|
80
|
+
borrowingFactor: bigint;
|
|
81
|
+
fundingFeeAmountPerSize: bigint;
|
|
82
|
+
longTokenClaimableFundingAmountPerSize: bigint;
|
|
83
|
+
shortTokenClaimableFundingAmountPerSize: bigint;
|
|
84
|
+
};
|
|
85
|
+
export type GmsolNextFunding = {
|
|
86
|
+
factor: bigint;
|
|
87
|
+
longsPayShorts: boolean;
|
|
88
|
+
};
|
|
89
|
+
export type GmsolMarketStatus = {
|
|
90
|
+
fundingFactorPerSecond: bigint;
|
|
91
|
+
longsPayShorts: boolean;
|
|
92
|
+
liquidityForLong: bigint;
|
|
93
|
+
liquidityForShort: bigint;
|
|
94
|
+
};
|
|
95
|
+
export type GmsolPendingPositionFees = {
|
|
96
|
+
borrowingFeeValue: bigint;
|
|
97
|
+
fundingFeeAmount: bigint;
|
|
98
|
+
claimableLongTokenAmount: bigint;
|
|
99
|
+
claimableShortTokenAmount: bigint;
|
|
100
|
+
};
|
|
101
|
+
export type GmsolFeeDiscountConfig = {
|
|
102
|
+
maxRank: number;
|
|
103
|
+
byRank: readonly bigint[];
|
|
104
|
+
referredUser: bigint;
|
|
105
|
+
};
|