@gmx-io/sdk 1.8.0 → 1.9.1
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/README.md +1 -1
- package/build/cjs/scripts/subsquid-codegen.js +1 -1
- package/build/cjs/src/abis/ArbSys.js +11 -0
- package/build/cjs/src/abis/index.js +2 -0
- package/build/cjs/src/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/index.js +8 -1
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -88
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +136 -748
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -165
- package/build/cjs/src/configs/__tests__/markets.spec.js +1 -16
- package/build/cjs/src/configs/api.js +10 -1
- package/build/cjs/src/configs/contracts.js +2 -0
- package/build/cjs/src/configs/dataStore.js +13 -3
- package/build/cjs/src/configs/express.js +1 -0
- package/build/cjs/src/configs/markets.js +14 -77
- package/build/cjs/src/configs/tokens.js +22 -90
- package/build/cjs/src/test/fixtures/arbitrumMarkets.json +0 -72
- package/build/cjs/src/test/mock.js +12 -1
- package/build/cjs/src/utils/__tests__/fees.spec.js +36 -0
- package/build/cjs/src/utils/__tests__/markets.spec.js +233 -0
- package/build/cjs/src/utils/__tests__/positionPnlCap.spec.js +30 -3
- package/build/cjs/src/utils/__tests__/positions.spec.js +5 -5
- package/build/cjs/src/utils/__tests__/prices.spec.js +97 -0
- package/build/cjs/src/utils/express/utils/gelatoRelayUtils.js +2 -0
- package/build/cjs/src/utils/express/utils/gmxRelayUtils.js +145 -0
- package/build/cjs/src/utils/express/utils/gmxRelayUtils.spec.js +163 -0
- package/build/cjs/src/utils/express/utils/index.js +1 -0
- package/build/cjs/src/utils/fees/index.js +8 -5
- package/build/cjs/src/utils/fees/priceImpact.js +4 -9
- package/build/cjs/src/utils/markets/utils.js +57 -1
- package/build/cjs/src/utils/numbers/index.js +1 -0
- package/build/cjs/src/utils/numbers/prbMath.js +154 -0
- package/build/cjs/src/utils/positions/utils.js +66 -43
- package/build/cjs/src/utils/prices/utils.js +28 -1
- package/build/cjs/src/utils/stats/__tests__/api.spec.js +100 -0
- package/build/cjs/src/utils/stats/api.js +32 -0
- package/build/cjs/src/utils/stats/types.js +4 -0
- package/build/cjs/src/utils/trade/__tests__/increase.spec.js +580 -0
- package/build/cjs/src/utils/trade/__tests__/increaseInvariants.spec.js +258 -0
- package/build/cjs/src/utils/trade/__tests__/increaseMarginCheck.spec.js +837 -0
- package/build/cjs/src/utils/trade/increase.js +255 -32
- package/build/cjs/src/utils/trade/increaseMarginCheck.js +179 -0
- package/build/cjs/src/utils/trade/index.js +1 -0
- package/build/cjs/src/utils/trade/trade.js +11 -1
- package/build/cjs/src/utils/tradeHistory/utils.js +3 -0
- package/build/cjs/src/utils/yield/api.js +9 -1
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/abis/ArbSys.js +9 -0
- package/build/esm/src/abis/index.js +2 -0
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/index.js +5 -1
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -88
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +136 -748
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -165
- package/build/esm/src/configs/__tests__/markets.spec.js +2 -17
- package/build/esm/src/configs/api.js +8 -0
- package/build/esm/src/configs/contracts.js +2 -0
- package/build/esm/src/configs/dataStore.js +8 -0
- package/build/esm/src/configs/express.js +1 -0
- package/build/esm/src/configs/markets.js +14 -77
- package/build/esm/src/configs/tokens.js +22 -90
- package/build/esm/src/test/fixtures/arbitrumMarkets.json +0 -72
- package/build/esm/src/test/mock.js +10 -0
- package/build/esm/src/utils/__tests__/fees.spec.js +37 -1
- package/build/esm/src/utils/__tests__/markets.spec.js +234 -1
- package/build/esm/src/utils/__tests__/positionPnlCap.spec.js +30 -3
- package/build/esm/src/utils/__tests__/positions.spec.js +5 -5
- package/build/esm/src/utils/__tests__/prices.spec.js +98 -1
- package/build/esm/src/utils/express/utils/gelatoRelayUtils.js +2 -0
- package/build/esm/src/utils/express/utils/gmxRelayUtils.js +137 -0
- package/build/esm/src/utils/express/utils/gmxRelayUtils.spec.js +161 -0
- package/build/esm/src/utils/express/utils/index.js +1 -0
- package/build/esm/src/utils/fees/index.js +8 -5
- package/build/esm/src/utils/fees/priceImpact.js +5 -10
- package/build/esm/src/utils/markets/utils.js +57 -2
- package/build/esm/src/utils/numbers/index.js +1 -0
- package/build/esm/src/utils/numbers/prbMath.js +149 -0
- package/build/esm/src/utils/positions/utils.js +63 -42
- package/build/esm/src/utils/prices/utils.js +25 -0
- package/build/esm/src/utils/stats/__tests__/api.spec.js +98 -0
- package/build/esm/src/utils/stats/api.js +26 -0
- package/build/esm/src/utils/stats/types.js +1 -0
- package/build/esm/src/utils/trade/__tests__/increase.spec.js +578 -0
- package/build/esm/src/utils/trade/__tests__/increaseInvariants.spec.js +256 -0
- package/build/esm/src/utils/trade/__tests__/increaseMarginCheck.spec.js +835 -0
- package/build/esm/src/utils/trade/increase.js +243 -20
- package/build/esm/src/utils/trade/increaseMarginCheck.js +173 -0
- package/build/esm/src/utils/trade/index.js +1 -0
- package/build/esm/src/utils/trade/trade.js +10 -1
- package/build/esm/src/utils/tradeHistory/utils.js +3 -0
- package/build/esm/src/utils/yield/api.js +7 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/abis/ArbSys.d.ts +12 -0
- package/build/types/src/abis/index.d.ts +11 -0
- package/build/types/src/clients/v2/index.d.ts +6 -3
- package/build/types/src/codegen/prebuilt/index.d.ts +170 -989
- package/build/types/src/configs/api.d.ts +1 -0
- package/build/types/src/configs/contracts.d.ts +2 -0
- package/build/types/src/configs/dataStore.d.ts +4 -0
- package/build/types/src/configs/express.d.ts +1 -0
- package/build/types/src/test/mock.d.ts +2 -0
- package/build/types/src/utils/buildUrl/utils.d.ts +1 -1
- package/build/types/src/utils/buyback/types.d.ts +7 -0
- package/build/types/src/utils/express/utils/gelatoRelayUtils.d.ts +2 -0
- package/build/types/src/utils/express/utils/gmxRelayUtils.d.ts +61 -0
- package/build/types/src/utils/express/utils/gmxRelayUtils.spec.d.ts +1 -0
- package/build/types/src/utils/express/utils/index.d.ts +1 -0
- package/build/types/src/utils/fees/index.d.ts +1 -1
- package/build/types/src/utils/markets/utils.d.ts +7 -0
- package/build/types/src/utils/numbers/index.d.ts +1 -0
- package/build/types/src/utils/numbers/prbMath.d.ts +7 -0
- package/build/types/src/utils/positions/utils.d.ts +9 -0
- package/build/types/src/utils/prices/utils.d.ts +10 -0
- package/build/types/src/utils/stats/__tests__/api.spec.d.ts +1 -0
- package/build/types/src/utils/stats/api.d.ts +11 -0
- package/build/types/src/utils/stats/types.d.ts +106 -0
- package/build/types/src/utils/trade/__tests__/increase.spec.d.ts +1 -0
- package/build/types/src/utils/trade/__tests__/increaseInvariants.spec.d.ts +1 -0
- package/build/types/src/utils/trade/__tests__/increaseMarginCheck.spec.d.ts +1 -0
- package/build/types/src/utils/trade/increase.d.ts +3 -0
- package/build/types/src/utils/trade/increaseMarginCheck.d.ts +61 -0
- package/build/types/src/utils/trade/index.d.ts +1 -0
- package/build/types/src/utils/trade/trade.d.ts +2 -0
- package/build/types/src/utils/tradeHistory/types.d.ts +2 -1
- package/build/types/src/utils/yield/api.d.ts +4 -1
- package/build/types/src/utils/yield/types.d.ts +18 -0
- package/package.json +3 -3
|
@@ -2,3 +2,4 @@ export type ApiEnvironment = "production" | "test";
|
|
|
2
2
|
export declare function getApiUrl(chainId: number, environment?: ApiEnvironment): any;
|
|
3
3
|
export declare function getApiFallbackUrls(chainId: number, environment?: ApiEnvironment): string[];
|
|
4
4
|
export declare function isApiSupported(chainId: number, environment?: ApiEnvironment): boolean;
|
|
5
|
+
export declare function getStatsApiUrl(environment?: ApiEnvironment): string | undefined;
|
|
@@ -61,6 +61,7 @@ export declare const CONTRACTS: {
|
|
|
61
61
|
KyberSwapRouter: string;
|
|
62
62
|
Multicall: string;
|
|
63
63
|
ArbitrumNodeInterface: string;
|
|
64
|
+
ArbSys: string;
|
|
64
65
|
LayerZeroEndpoint: string;
|
|
65
66
|
GelatoRelayAddress: string;
|
|
66
67
|
};
|
|
@@ -285,6 +286,7 @@ export declare const CONTRACTS: {
|
|
|
285
286
|
NATIVE_TOKEN: string;
|
|
286
287
|
LayerZeroEndpoint: string;
|
|
287
288
|
ArbitrumNodeInterface: string;
|
|
289
|
+
ArbSys: string;
|
|
288
290
|
GelatoRelayAddress: string;
|
|
289
291
|
ExternalHandler: "0x0000000000000000000000000000000000000000";
|
|
290
292
|
GLP: "0x0000000000000000000000000000000000000000";
|
|
@@ -52,6 +52,8 @@ export declare const MIN_POSITION_IMPACT_POOL_AMOUNT_KEY: string;
|
|
|
52
52
|
export declare const POSITION_IMPACT_POOL_DISTRIBUTION_RATE_KEY: string;
|
|
53
53
|
export declare const SWAP_IMPACT_POOL_AMOUNT_KEY: string;
|
|
54
54
|
export declare const MIN_COLLATERAL_USD_KEY: string;
|
|
55
|
+
export declare const PRO_TRADER_TIER_KEY: string;
|
|
56
|
+
export declare const PRO_DISCOUNT_FACTOR_KEY: string;
|
|
55
57
|
export declare const MIN_COLLATERAL_FACTOR_KEY: string;
|
|
56
58
|
export declare const MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY: string;
|
|
57
59
|
export declare const MIN_POSITION_SIZE_USD_KEY: string;
|
|
@@ -161,6 +163,8 @@ export declare function decreaseOrderGasLimitKey(): string;
|
|
|
161
163
|
export declare function swapOrderGasLimitKey(): string;
|
|
162
164
|
export declare function accountOrderListKey(account: string): string;
|
|
163
165
|
export declare function minCollateralFactorKey(market: string): string;
|
|
166
|
+
export declare function proTraderTierKey(account: string): string;
|
|
167
|
+
export declare function proDiscountFactorKey(proTier: bigint): string;
|
|
164
168
|
export declare function minCollateralFactorForLiquidationKey(market: string): string;
|
|
165
169
|
export declare function minCollateralFactorForOpenInterest(market: string, isLong: boolean): string;
|
|
166
170
|
export declare function hashedPositionKey(account: string, market: string, collateralToken: string, isLong: boolean): string;
|
|
@@ -7,6 +7,7 @@ export declare const DEFAULT_SUBACCOUNT_MAX_ALLOWED_COUNT = 90;
|
|
|
7
7
|
export declare const DEFAULT_PERMIT_DEADLINE_DURATION: number;
|
|
8
8
|
export declare const DEFAULT_EXPRESS_ORDER_DEADLINE_DURATION: number;
|
|
9
9
|
export declare const MIN_RELAYER_FEE_USD: bigint;
|
|
10
|
+
/** @deprecated Gelato shuts its relay services down on 2026-09-01; use GMX Relay (`sendToGmxRelay`). */
|
|
10
11
|
export declare const GELATO_API_KEYS: Partial<Record<ContractsChainId, string>>;
|
|
11
12
|
export declare const EXPRESS_EXTRA_EXECUTION_FEE_BUFFER_BPS = 1000;
|
|
12
13
|
export declare function getGasPaymentTokens(chainId: number): string[];
|
|
@@ -23,3 +23,5 @@ data, to, receiver, }: {
|
|
|
23
23
|
to?: string;
|
|
24
24
|
receiver?: string;
|
|
25
25
|
}): ExternalSwapQuote;
|
|
26
|
+
/** Deterministic PRNG for property-style specs: a fixed seed keeps a failing case reproducible from the run alone. */
|
|
27
|
+
export declare function createSeededRandom(seed: number): () => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function buildUrl(baseUrl: string, path: string, query?: Record<string, string | number | boolean | undefined>): string;
|
|
1
|
+
export declare function buildUrl(baseUrl: string, path: string, query?: Record<string, string | number | boolean | readonly string[] | undefined>): string;
|
|
@@ -4,6 +4,12 @@ export type BuybackWeekData = {
|
|
|
4
4
|
weeklyAccrued: string;
|
|
5
5
|
cumulativeAccrued: string;
|
|
6
6
|
};
|
|
7
|
+
export type BuybackMonthData = {
|
|
8
|
+
monthStart: number;
|
|
9
|
+
monthEnd: number;
|
|
10
|
+
monthlyAccrued: string;
|
|
11
|
+
cumulativeAccrued: string;
|
|
12
|
+
};
|
|
7
13
|
export type BuybackSummary = {
|
|
8
14
|
totalAccrued: string;
|
|
9
15
|
latestWeekAccrued: string;
|
|
@@ -12,4 +18,5 @@ export type BuybackSummary = {
|
|
|
12
18
|
export type BuybackWeeklyStatsResponse = {
|
|
13
19
|
summary: BuybackSummary;
|
|
14
20
|
weeks: BuybackWeekData[];
|
|
21
|
+
months: BuybackMonthData[];
|
|
15
22
|
};
|
|
@@ -9,10 +9,12 @@ export type GelatoRelayResult = {
|
|
|
9
9
|
taskId: string;
|
|
10
10
|
relayerClient: GelatoEvmRelayerClient;
|
|
11
11
|
};
|
|
12
|
+
/** @deprecated Gelato shuts its relay services down on 2026-09-01; use `sendToGmxRelay`. */
|
|
12
13
|
export declare function sendToGelatoRelay({ chainId, txnData, }: {
|
|
13
14
|
chainId: ContractsChainId;
|
|
14
15
|
txnData: ExpressTxnData;
|
|
15
16
|
}): Promise<GelatoRelayResult>;
|
|
17
|
+
/** @deprecated Gelato shuts its relay services down on 2026-09-01; use `waitForGmxRelayTask`. */
|
|
16
18
|
export declare function waitForGelatoTask(relayerClient: GelatoEvmRelayerClient, taskId: string, options?: {
|
|
17
19
|
timeout?: number;
|
|
18
20
|
pollingInterval?: number;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ContractsChainId } from "../../../configs/chains";
|
|
2
|
+
import { HttpError } from "../../http/http";
|
|
3
|
+
import type { ExpressTxnData } from "../types";
|
|
4
|
+
export type GmxRelayStatus = "pending" | "executed" | "reverted" | "failed" | "unknown";
|
|
5
|
+
export type GmxRelayResult = {
|
|
6
|
+
taskId: string;
|
|
7
|
+
status: GmxRelayStatus;
|
|
8
|
+
};
|
|
9
|
+
export type GmxRelayDebugView = {
|
|
10
|
+
chainId?: number;
|
|
11
|
+
from?: string | null;
|
|
12
|
+
to?: string;
|
|
13
|
+
operationType?: string;
|
|
14
|
+
account?: string;
|
|
15
|
+
blockNumber?: number | null;
|
|
16
|
+
errorCode?: string | null;
|
|
17
|
+
errorData?: string | null;
|
|
18
|
+
calldata?: string;
|
|
19
|
+
tenderlyUrl?: string;
|
|
20
|
+
};
|
|
21
|
+
export type GmxRelayStatusView = {
|
|
22
|
+
taskId: string;
|
|
23
|
+
status: GmxRelayStatus;
|
|
24
|
+
txHash?: string;
|
|
25
|
+
reason?: string;
|
|
26
|
+
revertData?: string;
|
|
27
|
+
debug?: GmxRelayDebugView | null;
|
|
28
|
+
};
|
|
29
|
+
export type GmxRelayTaskResult = {
|
|
30
|
+
transactionHash?: string;
|
|
31
|
+
status: "success" | "failed" | "pending";
|
|
32
|
+
relayStatus: GmxRelayStatus;
|
|
33
|
+
message?: string;
|
|
34
|
+
revertData?: string;
|
|
35
|
+
};
|
|
36
|
+
export declare class GmxRelayError extends HttpError {
|
|
37
|
+
readonly cause?: unknown;
|
|
38
|
+
data?: {
|
|
39
|
+
traceId: string;
|
|
40
|
+
};
|
|
41
|
+
constructor(message: string, httpStatus?: number, cause?: unknown);
|
|
42
|
+
get isPermanent(): boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function isPermanentRelayError(error: unknown): boolean;
|
|
45
|
+
export declare function sendToGmxRelay({ chainId, txnData, apiUrl, }: {
|
|
46
|
+
chainId: ContractsChainId;
|
|
47
|
+
txnData: ExpressTxnData;
|
|
48
|
+
apiUrl?: string;
|
|
49
|
+
}): Promise<GmxRelayResult>;
|
|
50
|
+
export declare function getGmxRelayTaskStatus({ chainId, taskId, apiUrl, }: {
|
|
51
|
+
chainId: ContractsChainId;
|
|
52
|
+
taskId: string;
|
|
53
|
+
apiUrl?: string;
|
|
54
|
+
}): Promise<GmxRelayStatusView>;
|
|
55
|
+
export declare function waitForGmxRelayTask({ chainId, taskId, apiUrl, timeout, pollingInterval, }: {
|
|
56
|
+
chainId: ContractsChainId;
|
|
57
|
+
taskId: string;
|
|
58
|
+
apiUrl?: string;
|
|
59
|
+
timeout?: number;
|
|
60
|
+
pollingInterval?: number;
|
|
61
|
+
}): Promise<GmxRelayTaskResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,6 +3,7 @@ export * from "./oracleParamsUtils";
|
|
|
3
3
|
export * from "./relayParamsUtils";
|
|
4
4
|
export * from "./batchOrderUtils";
|
|
5
5
|
export * from "./gelatoRelayUtils";
|
|
6
|
+
export * from "./gmxRelayUtils";
|
|
6
7
|
export * from "./globalExpressParams";
|
|
7
8
|
export * from "./expressParamsUtils";
|
|
8
9
|
export * from "./estimateExpressParams";
|
|
@@ -11,7 +11,7 @@ export declare function getSwapFee(marketInfo: MarketInfo, swapAmount: bigint, b
|
|
|
11
11
|
export declare function getPositionFee(marketInfo: MarketInfo, sizeDeltaUsd: bigint, balanceWasImproved: boolean, referralInfo: {
|
|
12
12
|
totalRebateFactor: bigint;
|
|
13
13
|
discountFactor: bigint;
|
|
14
|
-
} | undefined, uiFeeFactor?: bigint): {
|
|
14
|
+
} | undefined, uiFeeFactor?: bigint, proDiscountFactor?: bigint): {
|
|
15
15
|
positionFeeUsd: bigint;
|
|
16
16
|
discountUsd: bigint;
|
|
17
17
|
totalRebateUsd: bigint;
|
|
@@ -77,6 +77,13 @@ export declare function getMarketPnl(marketInfo: MarketInfo, isLong: boolean, fo
|
|
|
77
77
|
export declare function getPositiveMarketPnl(marketInfo: MarketInfo, isLong: boolean, forMaxPoolValue: boolean): bigint;
|
|
78
78
|
export declare function getOpenInterestUsd(marketInfo: MarketInfo, isLong: boolean): bigint;
|
|
79
79
|
export declare function getOpenInterestInTokens(marketInfo: MarketInfo, isLong: boolean): bigint;
|
|
80
|
+
export declare function getMarketInfoWithOpenInterestDelta({ marketInfo, collateralToken, isLong, sizeDeltaUsd, sizeDeltaInTokens, }: {
|
|
81
|
+
marketInfo: MarketInfo;
|
|
82
|
+
collateralToken: Token;
|
|
83
|
+
isLong: boolean;
|
|
84
|
+
sizeDeltaUsd: bigint;
|
|
85
|
+
sizeDeltaInTokens: bigint;
|
|
86
|
+
}): MarketInfo;
|
|
80
87
|
export declare function getOpenInterestForBalance(marketInfo: MarketInfo, isLong: boolean): bigint;
|
|
81
88
|
export declare function getPriceForPnl(prices: TokenPrices, isLong: boolean, maximize: boolean): bigint;
|
|
82
89
|
export declare function getIsMarketAvailableForExpressSwaps(marketInfo: MarketInfo): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact bigint port of the fixed-point math the GMX contracts use for exponentiation:
|
|
3
|
+
* `prb-math@2.4.3` (`PRBMathUD60x18.pow` = `exp2(mulDivFixedPoint(log2(x), y))`) plus the
|
|
4
|
+
* `Precision.applyExponentFactor` wrapper from gmx-synthetics (release-v2.2c).
|
|
5
|
+
*/
|
|
6
|
+
export declare function prbPow(x: bigint, y: bigint): bigint;
|
|
7
|
+
export declare function applyExponentFactor(floatValue: bigint, exponentFactor: bigint): bigint;
|
|
@@ -63,6 +63,14 @@ export declare function getLeverage(p: {
|
|
|
63
63
|
pendingFundingFeesUsd: bigint;
|
|
64
64
|
pendingBorrowingFeesUsd: bigint;
|
|
65
65
|
}): bigint | undefined;
|
|
66
|
+
export declare function getLiquidationPriceImpactDeltaUsd(p: {
|
|
67
|
+
marketInfo: MarketInfo;
|
|
68
|
+
sizeInUsd: bigint;
|
|
69
|
+
sizeInTokens: bigint;
|
|
70
|
+
pendingImpactAmount: bigint;
|
|
71
|
+
isLong: boolean;
|
|
72
|
+
useMaxPriceImpact?: boolean;
|
|
73
|
+
}): bigint;
|
|
66
74
|
export declare function getLiquidationPrice(p: {
|
|
67
75
|
sizeInUsd: bigint;
|
|
68
76
|
sizeInTokens: bigint;
|
|
@@ -88,6 +96,7 @@ export declare function getMinCollateralUsdForLiquidationPrice(p: {
|
|
|
88
96
|
isLong: boolean;
|
|
89
97
|
userReferralInfo: UserReferralInfo | undefined;
|
|
90
98
|
}): bigint;
|
|
99
|
+
export declare function getIsPositionBelowMinCollateralForLeverage(position: PositionInfoLoaded, collateralDeltaAmount?: bigint): boolean;
|
|
91
100
|
export declare function getNetPriceImpactDeltaUsdForDecrease({ marketInfo, sizeInUsd, pendingImpactAmount, priceImpactDeltaUsd, sizeDeltaUsd, }: {
|
|
92
101
|
marketInfo: MarketInfo;
|
|
93
102
|
sizeInUsd: bigint;
|
|
@@ -9,6 +9,16 @@ export declare function getMarkPrice(p: {
|
|
|
9
9
|
}): bigint;
|
|
10
10
|
export declare function getShouldUseMaxPrice(isIncrease: boolean, isLong: boolean): boolean;
|
|
11
11
|
export declare function getOrderThresholdType(orderType: OrderType, isLong: boolean): TriggerThresholdType | undefined;
|
|
12
|
+
export declare function getIsIncreaseOrderExecutableNow(p: {
|
|
13
|
+
orderType: OrderType | undefined;
|
|
14
|
+
isLong: boolean;
|
|
15
|
+
triggerPrice: bigint | undefined;
|
|
16
|
+
indexTokenPrices: TokenPrices;
|
|
17
|
+
}): boolean;
|
|
18
|
+
export declare function getIncreaseEvaluationIndexPrice(p: {
|
|
19
|
+
orderType: OrderType | undefined;
|
|
20
|
+
triggerPrice: bigint | undefined;
|
|
21
|
+
}): bigint | undefined;
|
|
12
22
|
export declare function getAcceptablePriceInfo(p: {
|
|
13
23
|
marketInfo: MarketInfo;
|
|
14
24
|
isIncrease: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IHttp } from "../http/types";
|
|
2
|
+
import type { ProtocolStatsFilterParams, ProtocolStatsSourceStatus, ProtocolStatsSummaryResponse, ProtocolStatsTimeseriesParams, ProtocolStatsTimeseriesResponse } from "./types";
|
|
3
|
+
export declare function fetchApiProtocolStatsSummary(ctx: {
|
|
4
|
+
api: IHttp;
|
|
5
|
+
}, params?: ProtocolStatsFilterParams): Promise<ProtocolStatsSummaryResponse>;
|
|
6
|
+
export declare function fetchApiProtocolStatsTimeseries(ctx: {
|
|
7
|
+
api: IHttp;
|
|
8
|
+
}, params: ProtocolStatsTimeseriesParams): Promise<ProtocolStatsTimeseriesResponse>;
|
|
9
|
+
export declare function fetchApiProtocolStatsSources(ctx: {
|
|
10
|
+
api: IHttp;
|
|
11
|
+
}): Promise<ProtocolStatsSourceStatus[]>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export declare const PROTOCOL_STATS_NETWORKS: readonly ["arbitrum", "avalanche", "megaeth", "solana"];
|
|
2
|
+
export type ProtocolStatsNetwork = (typeof PROTOCOL_STATS_NETWORKS)[number];
|
|
3
|
+
export type ProtocolStatsVersion = "v1" | "v2";
|
|
4
|
+
export type ProtocolStatsUsd = string;
|
|
5
|
+
export type ProtocolStatsVolume = {
|
|
6
|
+
perps: ProtocolStatsUsd | null;
|
|
7
|
+
swaps: ProtocolStatsUsd | null;
|
|
8
|
+
total: ProtocolStatsUsd;
|
|
9
|
+
lpFlows: ProtocolStatsUsd | null;
|
|
10
|
+
};
|
|
11
|
+
export type ProtocolStatsOpenInterest = {
|
|
12
|
+
long: ProtocolStatsUsd;
|
|
13
|
+
short: ProtocolStatsUsd;
|
|
14
|
+
total: ProtocolStatsUsd;
|
|
15
|
+
};
|
|
16
|
+
export type ProtocolStatsFees = {
|
|
17
|
+
trading: ProtocolStatsUsd | null;
|
|
18
|
+
swap: ProtocolStatsUsd | null;
|
|
19
|
+
total: ProtocolStatsUsd;
|
|
20
|
+
};
|
|
21
|
+
export type ProtocolStatsRevenue = {
|
|
22
|
+
lp: ProtocolStatsUsd;
|
|
23
|
+
buyback: ProtocolStatsUsd | null;
|
|
24
|
+
protocol: ProtocolStatsUsd;
|
|
25
|
+
treasury: ProtocolStatsUsd | null;
|
|
26
|
+
};
|
|
27
|
+
export type ProtocolStatsTvl = {
|
|
28
|
+
pools: ProtocolStatsUsd;
|
|
29
|
+
glv: ProtocolStatsUsd;
|
|
30
|
+
store: ProtocolStatsUsd | null;
|
|
31
|
+
total: ProtocolStatsUsd;
|
|
32
|
+
};
|
|
33
|
+
export type ProtocolStatsUsers = {
|
|
34
|
+
traders: number | null;
|
|
35
|
+
lps: number | null;
|
|
36
|
+
all: number | null;
|
|
37
|
+
distinctness: "source";
|
|
38
|
+
};
|
|
39
|
+
export type ProtocolStatsTrades = {
|
|
40
|
+
perps: number | null;
|
|
41
|
+
swaps: number | null;
|
|
42
|
+
total: number | null;
|
|
43
|
+
};
|
|
44
|
+
export type ProtocolStatsMetricSet = {
|
|
45
|
+
volume: ProtocolStatsVolume;
|
|
46
|
+
volume24h: ProtocolStatsVolume | null;
|
|
47
|
+
openInterest: ProtocolStatsOpenInterest | null;
|
|
48
|
+
fees: ProtocolStatsFees;
|
|
49
|
+
fees24h: ProtocolStatsFees | null;
|
|
50
|
+
revenue: ProtocolStatsRevenue | null;
|
|
51
|
+
tvl: ProtocolStatsTvl | null;
|
|
52
|
+
users: ProtocolStatsUsers;
|
|
53
|
+
trades: ProtocolStatsTrades;
|
|
54
|
+
};
|
|
55
|
+
export type ProtocolStatsSourceHealth = "fresh" | "stale" | "missing";
|
|
56
|
+
export type ProtocolStatsSourceStatus = {
|
|
57
|
+
id: string;
|
|
58
|
+
network: ProtocolStatsNetwork;
|
|
59
|
+
version: ProtocolStatsVersion;
|
|
60
|
+
asOf: number | null;
|
|
61
|
+
fetchedAt: number | null;
|
|
62
|
+
health: ProtocolStatsSourceHealth;
|
|
63
|
+
lagSeconds: number | null;
|
|
64
|
+
lastError: string | null;
|
|
65
|
+
};
|
|
66
|
+
export type ProtocolStatsCompleteness = "complete" | "partial";
|
|
67
|
+
export type ProtocolStatsMeta = {
|
|
68
|
+
asOf: number;
|
|
69
|
+
completeness: ProtocolStatsCompleteness;
|
|
70
|
+
sources: ProtocolStatsSourceStatus[];
|
|
71
|
+
schemaVersion: string;
|
|
72
|
+
};
|
|
73
|
+
export type ProtocolStatsFilterParams = {
|
|
74
|
+
networks?: ProtocolStatsNetwork[];
|
|
75
|
+
versions?: ProtocolStatsVersion[];
|
|
76
|
+
};
|
|
77
|
+
export type ProtocolStatsSummaryResponse = {
|
|
78
|
+
meta: ProtocolStatsMeta;
|
|
79
|
+
totals: ProtocolStatsMetricSet;
|
|
80
|
+
byNetwork: Partial<Record<ProtocolStatsNetwork, ProtocolStatsMetricSet>>;
|
|
81
|
+
byVersion: Partial<Record<ProtocolStatsVersion, ProtocolStatsMetricSet>>;
|
|
82
|
+
};
|
|
83
|
+
export type ProtocolStatsTimeseriesMetric = "volume.perps" | "volume.swaps" | "volume.total" | "fees.trading" | "fees.swap" | "fees.total" | "revenue.protocol" | "revenue.lp" | "trades.perps" | "trades.swaps" | "users.active";
|
|
84
|
+
export type ProtocolStatsTimeseriesGroupBy = "network" | "version" | "none";
|
|
85
|
+
export type ProtocolStatsTimeseriesParams = ProtocolStatsFilterParams & {
|
|
86
|
+
metric: ProtocolStatsTimeseriesMetric;
|
|
87
|
+
groupBy?: ProtocolStatsTimeseriesGroupBy;
|
|
88
|
+
from?: number;
|
|
89
|
+
to?: number;
|
|
90
|
+
};
|
|
91
|
+
export type ProtocolStatsTimeseriesPoint = {
|
|
92
|
+
day: number;
|
|
93
|
+
value: string | number | null;
|
|
94
|
+
provisional: boolean;
|
|
95
|
+
};
|
|
96
|
+
export type ProtocolStatsTimeseriesGroup = {
|
|
97
|
+
key: string;
|
|
98
|
+
points: ProtocolStatsTimeseriesPoint[];
|
|
99
|
+
};
|
|
100
|
+
export type ProtocolStatsTimeseriesResponse = {
|
|
101
|
+
meta: ProtocolStatsMeta;
|
|
102
|
+
metric: ProtocolStatsTimeseriesMetric;
|
|
103
|
+
interval: "1d";
|
|
104
|
+
groupBy: ProtocolStatsTimeseriesGroupBy;
|
|
105
|
+
groups: ProtocolStatsTimeseriesGroup[];
|
|
106
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -19,6 +19,7 @@ type IncreasePositionParams = {
|
|
|
19
19
|
fixedAcceptablePriceImpactBps?: bigint;
|
|
20
20
|
acceptablePriceImpactBuffer?: number;
|
|
21
21
|
userReferralInfo: UserReferralInfo | undefined;
|
|
22
|
+
proDiscountFactor?: bigint;
|
|
22
23
|
strategy: "leverageBySize" | "leverageByCollateral" | "independent";
|
|
23
24
|
findSwapPath: FindSwapPath;
|
|
24
25
|
uiFeeFactor: bigint;
|
|
@@ -70,6 +71,7 @@ export declare function getIncreasePositionPrices({ triggerPrice, indexToken, in
|
|
|
70
71
|
indexPrice: bigint;
|
|
71
72
|
initialCollateralPrice: bigint;
|
|
72
73
|
collateralPrice: bigint;
|
|
74
|
+
evaluationPrice: bigint | undefined;
|
|
73
75
|
triggerThresholdType: TriggerThresholdType | undefined;
|
|
74
76
|
triggerPrice: bigint | undefined;
|
|
75
77
|
};
|
|
@@ -87,5 +89,6 @@ export declare function getNextPositionValuesForIncreaseTrade(p: {
|
|
|
87
89
|
showPnlInLeverage: boolean;
|
|
88
90
|
minCollateralUsd: bigint;
|
|
89
91
|
userReferralInfo: UserReferralInfo | undefined;
|
|
92
|
+
collateralPrice?: bigint;
|
|
90
93
|
}): NextPositionValues;
|
|
91
94
|
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MarketInfo } from "../markets/types";
|
|
2
|
+
import { UserReferralInfo } from "../referrals/types";
|
|
3
|
+
import { TokenData } from "../tokens/types";
|
|
4
|
+
export declare enum PositionMarginFailureReason {
|
|
5
|
+
MinCollateral = "min collateral",
|
|
6
|
+
NonPositiveRemainingMargin = "< 0",
|
|
7
|
+
MinCollateralForLeverage = "min collateral for leverage",
|
|
8
|
+
InsufficientCollateralUsd = "insufficient collateral usd"
|
|
9
|
+
}
|
|
10
|
+
export declare function getIsMaxLeverageMarginReason(reason: PositionMarginFailureReason | undefined): boolean;
|
|
11
|
+
export type PositionMarginState = {
|
|
12
|
+
isLiquidatable: boolean;
|
|
13
|
+
reason: PositionMarginFailureReason | undefined;
|
|
14
|
+
remainingCollateralUsd: bigint;
|
|
15
|
+
minCollateralUsd: bigint;
|
|
16
|
+
minCollateralUsdForLeverage: bigint;
|
|
17
|
+
};
|
|
18
|
+
export type PositionMarginStateParams = {
|
|
19
|
+
marketInfo: MarketInfo;
|
|
20
|
+
collateralToken: TokenData;
|
|
21
|
+
sizeInUsd: bigint;
|
|
22
|
+
sizeInTokens: bigint;
|
|
23
|
+
collateralAmount: bigint;
|
|
24
|
+
pendingImpactAmount: bigint;
|
|
25
|
+
minCollateralUsd: bigint;
|
|
26
|
+
isLong: boolean;
|
|
27
|
+
userReferralInfo: UserReferralInfo | undefined;
|
|
28
|
+
proDiscountFactor?: bigint;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Port of `PositionUtils.isPositionLiquidatable` from the gmx-synthetics build deployed on Arbitrum
|
|
32
|
+
* (release_2.2.1 @ 23c9d160: release-v2.2c plus MarketUtils.getPositivePnl in the per-position pnl cap)
|
|
33
|
+
* for a position whose pending fees have just been settled — the state the contract validates right
|
|
34
|
+
* after an increase.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getResultingPositionMarginState(p: PositionMarginStateParams): PositionMarginState;
|
|
37
|
+
export type IncreaseResultingPositionMarginStateParams = {
|
|
38
|
+
marketInfo: MarketInfo;
|
|
39
|
+
collateralToken: TokenData;
|
|
40
|
+
isLong: boolean;
|
|
41
|
+
existingPosition: {
|
|
42
|
+
sizeInUsd: bigint;
|
|
43
|
+
sizeInTokens: bigint;
|
|
44
|
+
collateralAmount: bigint;
|
|
45
|
+
pendingImpactAmount: bigint;
|
|
46
|
+
} | undefined;
|
|
47
|
+
sizeDeltaUsd: bigint;
|
|
48
|
+
sizeDeltaInTokens: bigint;
|
|
49
|
+
collateralDeltaAmount: bigint;
|
|
50
|
+
minCollateralUsd: bigint;
|
|
51
|
+
userReferralInfo: UserReferralInfo | undefined;
|
|
52
|
+
proDiscountFactor?: bigint;
|
|
53
|
+
indexPriceForEvaluation?: bigint;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Mirrors the post-increase gates of `IncreasePositionUtils.increasePosition` from the gmx-synthetics
|
|
57
|
+
* build deployed on Arbitrum (release_2.2.1 @ 23c9d160: release-v2.2c plus MarketUtils.getPositivePnl
|
|
58
|
+
* in the per-position pnl cap): `willPositionCollateralBeSufficient` on the updated open interest,
|
|
59
|
+
* then `validatePosition` on the resulting position.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getIncreaseResultingPositionMarginState(p: IncreaseResultingPositionMarginStateParams): PositionMarginState | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OrderType } from "../orders/types";
|
|
1
2
|
import { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts, TradeFlags, TradeMode, TradeType } from "./types";
|
|
2
3
|
export declare function applySlippageToPrice(allowedSlippage: number, price: bigint, isIncrease: boolean, isLong: boolean): bigint;
|
|
3
4
|
export declare function applySlippageToMinOut(allowedSlippage: number, minOutputAmount: bigint): bigint;
|
|
@@ -9,3 +10,4 @@ export declare function getSwapCount({ isSwap, isIncrease, increaseAmounts, decr
|
|
|
9
10
|
decreaseAmounts?: DecreasePositionAmounts;
|
|
10
11
|
}): number | undefined;
|
|
11
12
|
export declare const createTradeFlags: (tradeType: TradeType, tradeMode: TradeMode) => TradeFlags;
|
|
13
|
+
export declare function getLimitOrderTypeByTradeMode(tradeMode: TradeMode): OrderType.LimitIncrease | OrderType.StopIncrease | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MarketInfo } from "../markets/types";
|
|
2
|
-
import { OrderType } from "../orders/types";
|
|
2
|
+
import { DecreasePositionSwapType, OrderType } from "../orders/types";
|
|
3
3
|
import { TokenData } from "../tokens/types";
|
|
4
4
|
export declare enum TradeActionType {
|
|
5
5
|
OrderCreated = "OrderCreated",
|
|
@@ -49,6 +49,7 @@ export type PositionTradeAction = {
|
|
|
49
49
|
pnlUsd?: bigint;
|
|
50
50
|
basePnlUsd?: bigint;
|
|
51
51
|
orderType: OrderType;
|
|
52
|
+
decreasePositionSwapType?: DecreasePositionSwapType;
|
|
52
53
|
orderKey: string;
|
|
53
54
|
isLong: boolean;
|
|
54
55
|
reason?: string;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IHttp } from "../http/types";
|
|
2
|
-
import { GmPoolsYieldPnlParams, GmPoolsYieldPnlResponse } from "./types";
|
|
2
|
+
import { GmPoolsYieldPnlParams, GmPoolsYieldPnlResponse, GmUserEarningsParams, GmUserEarningsResponse } from "./types";
|
|
3
3
|
export declare function fetchApiGmPoolYieldPnl(ctx: {
|
|
4
4
|
api: IHttp;
|
|
5
5
|
}, params?: GmPoolsYieldPnlParams): Promise<GmPoolsYieldPnlResponse>;
|
|
6
|
+
export declare function fetchApiGmUserEarnings(ctx: {
|
|
7
|
+
api: IHttp;
|
|
8
|
+
}, params: GmUserEarningsParams): Promise<GmUserEarningsResponse>;
|
|
@@ -27,3 +27,21 @@ export type GmPoolsYieldPnlParams = {
|
|
|
27
27
|
period?: ApiParameterPeriod;
|
|
28
28
|
includeComponents?: boolean;
|
|
29
29
|
};
|
|
30
|
+
export type GmUserEarningsWindow = {
|
|
31
|
+
days: number;
|
|
32
|
+
startTimestamp: number;
|
|
33
|
+
endTimestamp: number;
|
|
34
|
+
};
|
|
35
|
+
export type GmUserEarningEntry = {
|
|
36
|
+
marketToken: string;
|
|
37
|
+
lifetimeFeeUsd: string;
|
|
38
|
+
recent7dFeeUsd: string;
|
|
39
|
+
};
|
|
40
|
+
export type GmUserEarningsResponse = {
|
|
41
|
+
account: string;
|
|
42
|
+
window: GmUserEarningsWindow;
|
|
43
|
+
pools: GmUserEarningEntry[];
|
|
44
|
+
};
|
|
45
|
+
export type GmUserEarningsParams = {
|
|
46
|
+
account: string;
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmx-io/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -556,7 +556,7 @@
|
|
|
556
556
|
"tsx": "4.19.0",
|
|
557
557
|
"typescript-transform-paths": "3.5.1",
|
|
558
558
|
"viem": "2.48.11",
|
|
559
|
-
"vitest": "
|
|
559
|
+
"vitest": "4.1.11"
|
|
560
560
|
},
|
|
561
561
|
"files": [
|
|
562
562
|
"build"
|
|
@@ -566,6 +566,6 @@
|
|
|
566
566
|
"ox@0.14.20": "patch:ox@npm:0.14.29#../.yarn/patches/ox-npm-0.14.29-gmx-types",
|
|
567
567
|
"viem@2.48.11": "patch:viem@npm:2.48.11#../.yarn/patches/viem-npm-2.48.11-gmx-hex-types",
|
|
568
568
|
"lodash": "4.18.1",
|
|
569
|
-
"@vitest/pretty-format": "
|
|
569
|
+
"@vitest/pretty-format": "4.1.11"
|
|
570
570
|
}
|
|
571
571
|
}
|