@gmx-io/sdk 0.1.0 → 0.1.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 +25 -7
- package/build/scripts/prebuild/index.js +2 -0
- package/build/scripts/prebuild/prebuildKinkModelMarketRatesKeys.d.ts +1 -0
- package/build/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +44 -0
- package/build/src/abis/ExchangeRouter.json +203 -0
- package/build/src/abis/GlvReader.json +0 -10
- package/build/src/abis/GlvRouter.json +96 -2
- package/build/src/abis/RewardRouter.json +323 -68
- package/build/src/abis/SubaccountRouter.json +10 -0
- package/build/src/abis/SyntheticsReader.json +196 -64
- package/build/src/configs/batch.js +1 -13
- package/build/src/configs/chains.d.ts +0 -1
- package/build/src/configs/chains.js +1 -7
- package/build/src/configs/contracts.d.ts +2 -1
- package/build/src/configs/contracts.js +27 -66
- package/build/src/configs/dataStore.d.ts +4 -1
- package/build/src/configs/dataStore.js +5 -2
- package/build/src/configs/factors.d.ts +0 -12
- package/build/src/configs/factors.js +0 -12
- package/build/src/configs/markets.js +147 -0
- package/build/src/configs/tokens.d.ts +5 -2
- package/build/src/configs/tokens.js +297 -221
- package/build/src/modules/markets/index.js +2 -3
- package/build/src/modules/markets/markets.spec.js +0 -6
- package/build/src/modules/markets/types.d.ts +8 -0
- package/build/src/modules/oracle.js +1 -16
- package/build/src/modules/orders/orders.d.ts +2 -1
- package/build/src/modules/orders/orders.js +4 -3
- package/build/src/modules/orders/transactions/cancelOrdersTxn.js +1 -1
- package/build/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
- package/build/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -0
- package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +3 -1
- package/build/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
- package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
- package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +3 -1
- package/build/src/modules/orders/transactions/updateOrderTxn.js +7 -5
- package/build/src/modules/orders/utils.js +1 -1
- package/build/src/modules/positions/positions.d.ts +1 -1
- package/build/src/modules/positions/positions.js +10 -86
- package/build/src/modules/trades/trades.js +1 -2
- package/build/src/modules/utils/utils.js +3 -8
- package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +760 -0
- package/build/src/prebuilt/hashedMarketConfigKeys.json +1050 -0
- package/build/src/prebuilt/hashedMarketValuesKeys.json +315 -0
- package/build/src/prebuilt/index.d.ts +8 -2
- package/build/src/prebuilt/index.js +3 -1
- package/build/src/prebuilt/index.ts +19 -2
- package/build/src/types/amounts.d.ts +1 -1
- package/build/src/types/fees.d.ts +1 -2
- package/build/src/types/orders.d.ts +2 -2
- package/build/src/types/positions.d.ts +2 -2
- package/build/src/types/sdk.d.ts +4 -4
- package/build/src/types/syntheticsEvents.d.ts +3 -3
- package/build/src/types/tokens.d.ts +4 -0
- package/build/src/types/trade.d.ts +1 -1
- package/build/src/utils/fees/executionFee.d.ts +1 -5
- package/build/src/utils/fees/executionFee.js +3 -12
- package/build/src/utils/objects.d.ts +0 -5
- package/build/src/utils/objects.js +0 -17
- package/build/src/utils/orders.js +0 -8
- package/build/src/utils/simulateExecuteOrder.js +8 -21
- package/build/src/utils/testUtil.d.ts +2 -3
- package/build/src/utils/testUtil.js +2 -3
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/build/src/configs/subgraph.d.ts +0 -3
- package/build/src/configs/subgraph.js +0 -3
- package/build/src/utils/slidingWindowFallbackSwitcher.d.ts +0 -24
- package/build/src/utils/slidingWindowFallbackSwitcher.js +0 -40
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { zeroAddress } from "viem";
|
|
2
2
|
import { getContract } from "../../configs/contracts";
|
|
3
|
-
import { getSubgraphUrl } from "../../configs/subgraph";
|
|
4
3
|
import { convertTokenAddress, getToken } from "../../configs/tokens";
|
|
5
4
|
import SyntheticsReader from "../../abis/SyntheticsReader.json";
|
|
6
5
|
import { TIMEZONE_OFFSET_SEC } from "../../utils/common";
|
|
@@ -292,7 +291,7 @@ export class Markets extends Module {
|
|
|
292
291
|
const fullMarketInfo = {
|
|
293
292
|
...marketValues,
|
|
294
293
|
...marketConfig,
|
|
295
|
-
...claimableFundingData,
|
|
294
|
+
...claimableFundingData[marketAddress],
|
|
296
295
|
...market,
|
|
297
296
|
longToken,
|
|
298
297
|
shortToken,
|
|
@@ -308,7 +307,7 @@ export class Markets extends Module {
|
|
|
308
307
|
}
|
|
309
308
|
async getDailyVolumes() {
|
|
310
309
|
const { marketsAddresses } = await this.getMarkets();
|
|
311
|
-
const endpoint =
|
|
310
|
+
const endpoint = this.sdk.config.subsquidUrl;
|
|
312
311
|
if (!marketsAddresses || !endpoint) {
|
|
313
312
|
return;
|
|
314
313
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { GmxSdk } from "../../index";
|
|
2
2
|
import { arbitrumSdk, arbitrumSdkConfig } from "../../utils/testUtil";
|
|
3
3
|
describe("Markets", () => {
|
|
4
|
-
describe("getMarkets", () => {
|
|
5
|
-
it("should be able to get markets", async () => {
|
|
6
|
-
const response = await arbitrumSdk.markets.getMarkets();
|
|
7
|
-
expect(response).toBeDefined();
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
4
|
describe("getMarkets", () => {
|
|
11
5
|
it("should be able to get markets data", async () => {
|
|
12
6
|
const marketsData = await arbitrumSdk.markets.getMarkets();
|
|
@@ -38,3 +38,11 @@ export type MarketConfigMulticallRequestConfig = MulticallRequestConfig<{
|
|
|
38
38
|
}>;
|
|
39
39
|
};
|
|
40
40
|
}>;
|
|
41
|
+
export type KinkModelMarketRateMulticallRequestConfig = MulticallRequestConfig<{
|
|
42
|
+
[key: `${string}-dataStore`]: {
|
|
43
|
+
calls: Record<"optimalUsageFactorLong" | "optimalUsageFactorShort" | "baseBorrowingFactorLong" | "baseBorrowingFactorShort" | "aboveOptimalUsageBorrowingFactorLong" | "aboveOptimalUsageBorrowingFactorShort", {
|
|
44
|
+
methodName: string;
|
|
45
|
+
params: any[];
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
@@ -13,11 +13,6 @@ export class Oracle {
|
|
|
13
13
|
throw new Error("Invalid markets response");
|
|
14
14
|
}
|
|
15
15
|
return res.markets;
|
|
16
|
-
})
|
|
17
|
-
.catch((e) => {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.error(e);
|
|
20
|
-
throw e;
|
|
21
16
|
});
|
|
22
17
|
}
|
|
23
18
|
getTokens() {
|
|
@@ -28,12 +23,7 @@ export class Oracle {
|
|
|
28
23
|
...rest,
|
|
29
24
|
isSynthetic: synthetic,
|
|
30
25
|
};
|
|
31
|
-
}))
|
|
32
|
-
.catch((e) => {
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.error(e);
|
|
35
|
-
throw e;
|
|
36
|
-
});
|
|
26
|
+
}));
|
|
37
27
|
}
|
|
38
28
|
getTickers() {
|
|
39
29
|
return fetch(buildUrl(this.url, "/prices/tickers"))
|
|
@@ -43,11 +33,6 @@ export class Oracle {
|
|
|
43
33
|
throw new Error("Invalid tickers response");
|
|
44
34
|
}
|
|
45
35
|
return res;
|
|
46
|
-
})
|
|
47
|
-
.catch((e) => {
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.error(e);
|
|
50
|
-
throw e;
|
|
51
36
|
});
|
|
52
37
|
}
|
|
53
38
|
}
|
|
@@ -7,7 +7,8 @@ import { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts } from ".
|
|
|
7
7
|
import { Module } from "../base";
|
|
8
8
|
import { WrapOrUnwrapParams } from "./transactions/createWrapOrUnwrapTxn";
|
|
9
9
|
export declare class Orders extends Module {
|
|
10
|
-
getOrders({ marketsInfoData, tokensData, orderTypesFilter, marketsDirectionsFilter, }: {
|
|
10
|
+
getOrders({ account: _account, marketsInfoData, tokensData, orderTypesFilter, marketsDirectionsFilter, }: {
|
|
11
|
+
account?: string;
|
|
11
12
|
marketsInfoData: MarketsInfoData;
|
|
12
13
|
tokensData: TokensData;
|
|
13
14
|
orderTypesFilter?: OrderType[];
|
|
@@ -10,8 +10,9 @@ import { createSwapOrderTxn } from "./transactions/createSwapOrderTxn";
|
|
|
10
10
|
import { createWrapOrUnwrapTxn } from "./transactions/createWrapOrUnwrapTxn";
|
|
11
11
|
import { cancelOrdersTxn } from "./transactions/cancelOrdersTxn";
|
|
12
12
|
export class Orders extends Module {
|
|
13
|
-
async getOrders({ marketsInfoData, tokensData, orderTypesFilter = [], marketsDirectionsFilter = [], }) {
|
|
14
|
-
|
|
13
|
+
async getOrders({ account: _account, marketsInfoData, tokensData, orderTypesFilter = [], marketsDirectionsFilter = [], }) {
|
|
14
|
+
const account = _account || this.account;
|
|
15
|
+
if (!account) {
|
|
15
16
|
return {
|
|
16
17
|
count: 0,
|
|
17
18
|
ordersInfoData: {},
|
|
@@ -34,7 +35,7 @@ export class Orders extends Module {
|
|
|
34
35
|
.map((filter) => filter.marketAddress.toLowerCase());
|
|
35
36
|
const hasSwapRelevantDefinedMarkets = swapRelevantDefinedMarketsLowercased.length > 0;
|
|
36
37
|
const orders = await this.sdk
|
|
37
|
-
.executeMulticall(buildGetOrdersMulticall(this.chainId,
|
|
38
|
+
.executeMulticall(buildGetOrdersMulticall(this.chainId, account))
|
|
38
39
|
.then(parseGetOrdersResponse);
|
|
39
40
|
const filteredOrders = orders.orders.filter((order) => {
|
|
40
41
|
if (!isVisibleOrder(order.orderType)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
1
2
|
import ExchangeRouter from "../../../abis/ExchangeRouter.json";
|
|
2
3
|
import { getContract } from "../../../configs/contracts";
|
|
3
|
-
import { encodeFunctionData } from "viem";
|
|
4
4
|
export async function cancelOrdersTxn(sdk, p) {
|
|
5
5
|
const multicall = createCancelEncodedPayload(p.orderKeys);
|
|
6
6
|
const exchangeRouter = getContract(sdk.chainId, "ExchangeRouter");
|
|
@@ -73,6 +73,7 @@ export function createDecreaseEncodedPayload({ sdk, orderVaultAddress, ps, }) {
|
|
|
73
73
|
executionFee: p.executionFee,
|
|
74
74
|
callbackGasLimit: 0n,
|
|
75
75
|
minOutputAmount,
|
|
76
|
+
validFromTime: 0n,
|
|
76
77
|
},
|
|
77
78
|
orderType: p.orderType,
|
|
78
79
|
decreasePositionSwapType: p.decreasePositionSwapType,
|
|
@@ -52,6 +52,7 @@ export type SecondaryUpdateOrderParams = SecondaryOrderCommonParams & {
|
|
|
52
52
|
executionFee: bigint;
|
|
53
53
|
indexToken: TokenData;
|
|
54
54
|
minOutputAmount: bigint;
|
|
55
|
+
autoCancel: boolean;
|
|
55
56
|
};
|
|
56
57
|
export declare function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p, createDecreaseOrderParams, cancelOrderParams, updateOrderParams, }: {
|
|
57
58
|
sdk: GmxSdk;
|
|
@@ -48,7 +48,7 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
|
|
|
48
48
|
ps: createDecreaseOrderParams || [],
|
|
49
49
|
});
|
|
50
50
|
const cancelEncodedPayload = createCancelEncodedPayload(cancelOrderParams?.map(({ orderKey }) => orderKey) || []);
|
|
51
|
-
const updateEncodedPayload = updateOrderParams?.reduce((acc, { orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount }) => {
|
|
51
|
+
const updateEncodedPayload = updateOrderParams?.reduce((acc, { orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount, autoCancel }) => {
|
|
52
52
|
return [
|
|
53
53
|
...acc,
|
|
54
54
|
...createUpdateEncodedPayload({
|
|
@@ -60,6 +60,7 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
|
|
|
60
60
|
acceptablePrice,
|
|
61
61
|
triggerPrice,
|
|
62
62
|
minOutputAmount,
|
|
63
|
+
autoCancel,
|
|
63
64
|
}),
|
|
64
65
|
];
|
|
65
66
|
}, []) ?? [];
|
|
@@ -125,6 +126,7 @@ function createOrderParams({ p, acceptablePrice, initialCollateralTokenAddress,
|
|
|
125
126
|
executionFee: p.executionFee,
|
|
126
127
|
callbackGasLimit: 0n,
|
|
127
128
|
minOutputAmount: 0n,
|
|
129
|
+
validFromTime: 0n,
|
|
128
130
|
},
|
|
129
131
|
orderType: p.orderType,
|
|
130
132
|
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
@@ -9,9 +9,10 @@ export type UpdateOrderParams = {
|
|
|
9
9
|
acceptablePrice: bigint;
|
|
10
10
|
minOutputAmount: bigint;
|
|
11
11
|
executionFee?: bigint;
|
|
12
|
+
autoCancel: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare function updateOrderTxn(sdk: GmxSdk, p: UpdateOrderParams): Promise<Address>;
|
|
14
|
-
export declare function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount, }: {
|
|
15
|
+
export declare function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, autoCancel, minOutputAmount, }: {
|
|
15
16
|
sdk: GmxSdk;
|
|
16
17
|
orderKey: string;
|
|
17
18
|
sizeDeltaUsd: bigint;
|
|
@@ -20,4 +21,5 @@ export declare function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd
|
|
|
20
21
|
acceptablePrice: bigint;
|
|
21
22
|
triggerPrice: bigint;
|
|
22
23
|
minOutputAmount: bigint;
|
|
24
|
+
autoCancel: boolean;
|
|
23
25
|
}): `0x${string}`[];
|
|
@@ -3,7 +3,7 @@ import { getContract } from "../../../configs/contracts";
|
|
|
3
3
|
import { convertToContractPrice } from "../../../utils/tokens";
|
|
4
4
|
import { encodeFunctionData } from "viem";
|
|
5
5
|
export function updateOrderTxn(sdk, p) {
|
|
6
|
-
const { orderKey, sizeDeltaUsd, triggerPrice, acceptablePrice, minOutputAmount, executionFee, indexToken } = p;
|
|
6
|
+
const { orderKey, sizeDeltaUsd, triggerPrice, acceptablePrice, minOutputAmount, executionFee, indexToken, autoCancel, } = p;
|
|
7
7
|
const router = getContract(sdk.chainId, "ExchangeRouter");
|
|
8
8
|
const encodedPayload = createUpdateEncodedPayload({
|
|
9
9
|
sdk,
|
|
@@ -14,12 +14,13 @@ export function updateOrderTxn(sdk, p) {
|
|
|
14
14
|
acceptablePrice,
|
|
15
15
|
triggerPrice,
|
|
16
16
|
minOutputAmount,
|
|
17
|
+
autoCancel,
|
|
17
18
|
});
|
|
18
19
|
return sdk.callContract(router, ExchangeRouter.abi, "multicall", [encodedPayload], {
|
|
19
20
|
value: executionFee != undefined && executionFee > 0 ? executionFee : undefined,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
export function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount, }) {
|
|
23
|
+
export function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, autoCancel, minOutputAmount, }) {
|
|
23
24
|
const orderVaultAddress = getContract(sdk.chainId, "OrderVault");
|
|
24
25
|
const multicall = [];
|
|
25
26
|
if (executionFee != undefined && executionFee > 0) {
|
|
@@ -30,10 +31,11 @@ export function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, execut
|
|
|
30
31
|
params: [
|
|
31
32
|
orderKey,
|
|
32
33
|
sizeDeltaUsd,
|
|
33
|
-
convertToContractPrice(acceptablePrice, indexToken?.decimals || 0),
|
|
34
|
-
convertToContractPrice(triggerPrice, indexToken?.decimals || 0),
|
|
34
|
+
acceptablePrice !== undefined ? convertToContractPrice(acceptablePrice, indexToken?.decimals || 0) : 0n,
|
|
35
|
+
triggerPrice !== undefined ? convertToContractPrice(triggerPrice, indexToken?.decimals || 0) : 0n,
|
|
35
36
|
minOutputAmount,
|
|
36
|
-
|
|
37
|
+
0n,
|
|
38
|
+
autoCancel,
|
|
37
39
|
],
|
|
38
40
|
});
|
|
39
41
|
return multicall.filter(Boolean).map((call) => encodeFunctionData({
|
|
@@ -136,7 +136,7 @@ export function parseGetOrdersResponse(res) {
|
|
|
136
136
|
executionFee: BigInt(order.numbers.executionFee),
|
|
137
137
|
callbackGasLimit: BigInt(order.numbers.callbackGasLimit),
|
|
138
138
|
minOutputAmount: BigInt(order.numbers.minOutputAmount),
|
|
139
|
-
|
|
139
|
+
updatedAtTime: BigInt(order.numbers.updatedAtTime),
|
|
140
140
|
isLong: order.flags.isLong,
|
|
141
141
|
shouldUnwrapNativeToken: order.flags.shouldUnwrapNativeToken,
|
|
142
142
|
isFrozen: order.flags.isFrozen,
|
|
@@ -16,7 +16,7 @@ type PositionsConstantsResult = {
|
|
|
16
16
|
export declare class Positions extends Module {
|
|
17
17
|
static MAX_PENDING_UPDATE_AGE: number;
|
|
18
18
|
private getKeysAndPricesParams;
|
|
19
|
-
private
|
|
19
|
+
private getPositionsData;
|
|
20
20
|
getPositions(p: {
|
|
21
21
|
marketsInfoData: MarketsData | undefined;
|
|
22
22
|
tokensData: TokensData | undefined;
|
|
@@ -6,7 +6,7 @@ import { getContract } from "../../configs/contracts";
|
|
|
6
6
|
import { hashedPositionKey, MAX_AUTO_CANCEL_ORDERS_KEY, MIN_COLLATERAL_USD_KEY, MIN_POSITION_SIZE_USD_KEY, uiFeeFactorKey, } from "../../configs/dataStore";
|
|
7
7
|
import { getContractMarketPrices, getMaxAllowedLeverageByMinCollateralFactor } from "../../utils/markets";
|
|
8
8
|
import { getByKey } from "../../utils/objects";
|
|
9
|
-
import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionKey, getPositionNetValue, getPositionPnlUsd,
|
|
9
|
+
import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionKey, getPositionNetValue, getPositionPnlUsd, } from "../../utils/positions";
|
|
10
10
|
import { Module } from "../base";
|
|
11
11
|
import { getPositionFee, getPriceImpactForPosition } from "../../utils/fees";
|
|
12
12
|
import { basisPointsToFloat, getBasisPoints } from "../../utils/numbers";
|
|
@@ -50,51 +50,19 @@ export class Positions extends Module {
|
|
|
50
50
|
}
|
|
51
51
|
return values;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
const { positionsData, allPositionsKeys
|
|
53
|
+
getPositionsData(p) {
|
|
54
|
+
const { positionsData, allPositionsKeys } = p;
|
|
55
55
|
if (!allPositionsKeys) {
|
|
56
56
|
return undefined;
|
|
57
57
|
}
|
|
58
|
-
if (!positionDecreaseEvents && !positionIncreaseEvents && !pendingPositionsUpdates) {
|
|
59
|
-
return positionsData;
|
|
60
|
-
}
|
|
61
58
|
return allPositionsKeys.reduce((acc, key) => {
|
|
62
|
-
const now = Date.now();
|
|
63
|
-
const lastIncreaseEvent = positionIncreaseEvents
|
|
64
|
-
? positionIncreaseEvents.filter((e) => e.positionKey === key).pop()
|
|
65
|
-
: undefined;
|
|
66
|
-
const lastDecreaseEvent = positionDecreaseEvents
|
|
67
|
-
? positionDecreaseEvents.filter((e) => e.positionKey === key).pop()
|
|
68
|
-
: undefined;
|
|
69
|
-
const pendingUpdate = pendingPositionsUpdates?.[key] &&
|
|
70
|
-
(pendingPositionsUpdates[key]?.updatedAt ?? 0) + Positions.MAX_PENDING_UPDATE_AGE > now
|
|
71
|
-
? pendingPositionsUpdates[key]
|
|
72
|
-
: undefined;
|
|
73
59
|
let position;
|
|
74
60
|
if (getByKey(positionsData, key)) {
|
|
75
61
|
position = { ...getByKey(positionsData, key) };
|
|
76
62
|
}
|
|
77
|
-
else if (pendingUpdate && pendingUpdate.isIncrease) {
|
|
78
|
-
position = getPendingMockPosition(pendingUpdate);
|
|
79
|
-
}
|
|
80
63
|
else {
|
|
81
64
|
return acc;
|
|
82
65
|
}
|
|
83
|
-
if (lastIncreaseEvent &&
|
|
84
|
-
lastIncreaseEvent.increasedAtBlock > position.increasedAtBlock &&
|
|
85
|
-
lastIncreaseEvent.increasedAtBlock > (lastDecreaseEvent?.decreasedAtBlock || 0)) {
|
|
86
|
-
position = applyEventChanges(position, lastIncreaseEvent);
|
|
87
|
-
}
|
|
88
|
-
else if (lastDecreaseEvent &&
|
|
89
|
-
lastDecreaseEvent.decreasedAtBlock > position.decreasedAtBlock &&
|
|
90
|
-
lastDecreaseEvent.decreasedAtBlock > (lastIncreaseEvent?.increasedAtBlock || 0)) {
|
|
91
|
-
position = applyEventChanges(position, lastDecreaseEvent);
|
|
92
|
-
}
|
|
93
|
-
if (pendingUpdate &&
|
|
94
|
-
((pendingUpdate.isIncrease && pendingUpdate.updatedAtBlock > position.increasedAtBlock) ||
|
|
95
|
-
(!pendingUpdate.isIncrease && pendingUpdate.updatedAtBlock > position.decreasedAtBlock))) {
|
|
96
|
-
position.pendingUpdate = pendingUpdate;
|
|
97
|
-
}
|
|
98
66
|
if (position.sizeInUsd > 0) {
|
|
99
67
|
acc[key] = position;
|
|
100
68
|
}
|
|
@@ -126,14 +94,14 @@ export class Positions extends Module {
|
|
|
126
94
|
},
|
|
127
95
|
},
|
|
128
96
|
};
|
|
129
|
-
const
|
|
97
|
+
const positions = await this.sdk.executeMulticall(request).then((res) => {
|
|
130
98
|
const positions = res.data.reader.positions.returnValues;
|
|
131
99
|
return positions.reduce((positionsMap, positionInfo) => {
|
|
132
100
|
const { position, fees } = positionInfo;
|
|
133
101
|
const { addresses, numbers, flags, data } = position;
|
|
134
102
|
const { account, market: marketAddress, collateralToken: collateralTokenAddress } = addresses;
|
|
135
103
|
// Empty position
|
|
136
|
-
if (BigInt(numbers.
|
|
104
|
+
if (BigInt(numbers.increasedAtTime) == 0n) {
|
|
137
105
|
return positionsMap;
|
|
138
106
|
}
|
|
139
107
|
const positionKey = getPositionKey(account, marketAddress, collateralTokenAddress, flags.isLong);
|
|
@@ -147,8 +115,8 @@ export class Positions extends Module {
|
|
|
147
115
|
sizeInUsd: numbers.sizeInUsd,
|
|
148
116
|
sizeInTokens: numbers.sizeInTokens,
|
|
149
117
|
collateralAmount: numbers.collateralAmount,
|
|
150
|
-
|
|
151
|
-
|
|
118
|
+
increasedAtTime: numbers.increasedAtTime,
|
|
119
|
+
decreasedAtTime: numbers.decreasedAtTime,
|
|
152
120
|
isLong: flags.isLong,
|
|
153
121
|
pendingBorrowingFeesUsd: fees.borrowing.borrowingFeeUsd,
|
|
154
122
|
fundingFeeAmount: fees.funding.fundingFeeAmount,
|
|
@@ -159,12 +127,12 @@ export class Positions extends Module {
|
|
|
159
127
|
return positionsMap;
|
|
160
128
|
}, {});
|
|
161
129
|
});
|
|
162
|
-
const
|
|
163
|
-
positionsData:
|
|
130
|
+
const positionsData = this.getPositionsData({
|
|
131
|
+
positionsData: positions,
|
|
164
132
|
allPositionsKeys: keysAndPrices?.allPositionsKeys,
|
|
165
133
|
});
|
|
166
134
|
return {
|
|
167
|
-
positionsData
|
|
135
|
+
positionsData,
|
|
168
136
|
};
|
|
169
137
|
}
|
|
170
138
|
getUiFeeFactorRequest() {
|
|
@@ -517,47 +485,3 @@ export class Positions extends Module {
|
|
|
517
485
|
}
|
|
518
486
|
}
|
|
519
487
|
Positions.MAX_PENDING_UPDATE_AGE = 600 * 1000; // 10 minutes
|
|
520
|
-
function getPendingMockPosition(pendingUpdate) {
|
|
521
|
-
const { account, marketAddress, collateralAddress, isLong } = parsePositionKey(pendingUpdate.positionKey);
|
|
522
|
-
return {
|
|
523
|
-
key: pendingUpdate.positionKey,
|
|
524
|
-
contractKey: hashedPositionKey(account, marketAddress, collateralAddress, isLong),
|
|
525
|
-
account,
|
|
526
|
-
marketAddress,
|
|
527
|
-
collateralTokenAddress: collateralAddress,
|
|
528
|
-
isLong,
|
|
529
|
-
sizeInUsd: pendingUpdate.sizeDeltaUsd ?? 0n,
|
|
530
|
-
collateralAmount: pendingUpdate.collateralDeltaAmount ?? 0n,
|
|
531
|
-
sizeInTokens: pendingUpdate.sizeDeltaInTokens ?? 0n,
|
|
532
|
-
increasedAtBlock: pendingUpdate.updatedAtBlock,
|
|
533
|
-
decreasedAtBlock: 0n,
|
|
534
|
-
pendingBorrowingFeesUsd: 0n,
|
|
535
|
-
fundingFeeAmount: 0n,
|
|
536
|
-
claimableLongTokenAmount: 0n,
|
|
537
|
-
claimableShortTokenAmount: 0n,
|
|
538
|
-
data: "0x",
|
|
539
|
-
isOpening: true,
|
|
540
|
-
pendingUpdate: pendingUpdate,
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
function applyEventChanges(position, event) {
|
|
544
|
-
const nextPosition = { ...position };
|
|
545
|
-
nextPosition.sizeInUsd = event.sizeInUsd;
|
|
546
|
-
nextPosition.sizeInTokens = event.sizeInTokens;
|
|
547
|
-
nextPosition.collateralAmount = event.collateralAmount;
|
|
548
|
-
nextPosition.pendingBorrowingFeesUsd = 0n;
|
|
549
|
-
nextPosition.fundingFeeAmount = 0n;
|
|
550
|
-
nextPosition.claimableLongTokenAmount = 0n;
|
|
551
|
-
nextPosition.claimableShortTokenAmount = 0n;
|
|
552
|
-
nextPosition.pendingUpdate = undefined;
|
|
553
|
-
nextPosition.isOpening = false;
|
|
554
|
-
// eslint-disable-next-line local-rules/no-logical-bigint
|
|
555
|
-
if (event.increasedAtBlock) {
|
|
556
|
-
nextPosition.increasedAtBlock = event.increasedAtBlock;
|
|
557
|
-
}
|
|
558
|
-
// eslint-disable-next-line local-rules/no-logical-bigint
|
|
559
|
-
if (event.decreasedAtBlock) {
|
|
560
|
-
nextPosition.decreasedAtBlock = event.decreasedAtBlock;
|
|
561
|
-
}
|
|
562
|
-
return nextPosition;
|
|
563
|
-
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getSubgraphUrl } from "../../configs/subgraph";
|
|
2
1
|
import { getWrappedToken } from "../../configs/tokens";
|
|
3
2
|
import merge from "lodash/merge";
|
|
4
3
|
import { OrderType } from "../../types/orders";
|
|
@@ -32,7 +31,7 @@ export class Trades extends Module {
|
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirectionsFilter = [], forAllAccounts, account, fromTxTimestamp, toTxTimestamp, orderEventCombinations, marketsInfoData, tokensData, }) {
|
|
35
|
-
const endpoint =
|
|
34
|
+
const endpoint = sdk.config.subgraphUrl;
|
|
36
35
|
const chainId = sdk.chainId;
|
|
37
36
|
if (!endpoint) {
|
|
38
37
|
return [];
|
|
@@ -23,13 +23,9 @@ export class Utils extends Module {
|
|
|
23
23
|
contractAddress: getContract(this.chainId, "DataStore"),
|
|
24
24
|
abi: DataStore.abi,
|
|
25
25
|
calls: {
|
|
26
|
-
|
|
26
|
+
depositToken: {
|
|
27
27
|
methodName: "getUint",
|
|
28
|
-
params: [depositGasLimitKey(
|
|
29
|
-
},
|
|
30
|
-
depositMultiToken: {
|
|
31
|
-
methodName: "getUint",
|
|
32
|
-
params: [depositGasLimitKey(false)],
|
|
28
|
+
params: [depositGasLimitKey()],
|
|
33
29
|
},
|
|
34
30
|
withdrawalMultiToken: {
|
|
35
31
|
methodName: "getUint",
|
|
@@ -88,8 +84,7 @@ export class Utils extends Module {
|
|
|
88
84
|
return BigInt(results[key].returnValues[0]);
|
|
89
85
|
}
|
|
90
86
|
return {
|
|
91
|
-
|
|
92
|
-
depositMultiToken: getBigInt("depositMultiToken"),
|
|
87
|
+
depositToken: getBigInt("depositToken"),
|
|
93
88
|
withdrawalMultiToken: getBigInt("withdrawalMultiToken"),
|
|
94
89
|
shift: getBigInt("shift"),
|
|
95
90
|
singleSwap: getBigInt("singleSwap"),
|