@gmx-io/sdk 0.0.2 → 0.0.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.
Files changed (42) hide show
  1. package/README.md +98 -20
  2. package/build/scripts/prebuild/index.d.ts +1 -0
  3. package/build/scripts/prebuild/index.js +7 -0
  4. package/build/scripts/prebuild/prebuildMarketConfigKeys.d.ts +1 -0
  5. package/build/scripts/prebuild/prebuildMarketConfigKeys.js +18 -0
  6. package/build/scripts/prebuild/prebuildMarketValuesKeys.d.ts +1 -0
  7. package/build/scripts/prebuild/prebuildMarketValuesKeys.js +18 -0
  8. package/build/src/configs/markets.d.ts +1 -2
  9. package/build/src/index.d.ts +2 -0
  10. package/build/src/index.js +7 -4
  11. package/build/src/modules/accounts/accounts.spec.js +1 -1
  12. package/build/src/modules/base.d.ts +3 -4
  13. package/build/src/modules/base.js +1 -1
  14. package/build/src/modules/markets/index.d.ts +4 -19
  15. package/build/src/modules/markets/index.js +72 -76
  16. package/build/src/modules/markets/markets.spec.js +14 -9
  17. package/build/src/modules/markets/query-builders.js +2 -0
  18. package/build/src/modules/markets/types.d.ts +0 -2
  19. package/build/src/modules/oracle.d.ts +2 -9
  20. package/build/src/modules/orders/orders.spec.js +1 -1
  21. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +0 -1
  22. package/build/src/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -1
  23. package/build/src/modules/orders/transactions/createSwapOrderTxn.js +13 -31
  24. package/build/src/modules/positions/positions.spec.js +1 -1
  25. package/build/src/modules/tokens/tokens.d.ts +6 -13
  26. package/build/src/modules/tokens/tokens.js +8 -3
  27. package/build/src/modules/tokens/tokens.spec.js +16 -9
  28. package/build/src/modules/trades/trades.js +0 -3
  29. package/build/src/modules/trades/trades.spec.js +1 -1
  30. package/build/src/types/markets.d.ts +7 -0
  31. package/build/src/types/sdk.d.ts +12 -20
  32. package/build/src/utils/marketKeysAndConfigs.d.ts +3 -3
  33. package/build/src/utils/marketKeysAndConfigs.js +2 -2
  34. package/build/src/utils/markets.d.ts +1 -1
  35. package/build/src/utils/markets.js +2 -2
  36. package/build/src/utils/multicall.js +2 -0
  37. package/build/src/utils/simulateExecuteOrder.js +2 -0
  38. package/build/src/utils/testUtil.d.ts +575 -0
  39. package/build/src/utils/{test.js → testUtil.js} +4 -7
  40. package/build/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +75 -91
  42. package/build/src/utils/test.d.ts +0 -2
package/README.md CHANGED
@@ -1,14 +1,15 @@
1
- # GMX SDK
1
+ # <img src="https://app.gmx.io/favicon/apple-icon-144x144.png" width="28" height="28"> GMX SDK
2
2
 
3
3
  ## Install
4
4
 
5
5
  ```bash
6
- yarn add @gmx/sdk
6
+ yarn add @gmx-io/sdk # or
7
+ npm install --save @gmx-io/sdk
7
8
  ```
8
9
 
9
10
  ## Usage
10
11
 
11
- ```javascript
12
+ ```typescript
12
13
  import { GmxSdk } from "@gmx/sdk";
13
14
  import { useWallet } from "wagmi";
14
15
 
@@ -17,6 +18,9 @@ const sdk = new GmxSdk({
17
18
  rpcUrl: "https://arb1.arbitrum.io/rpc",
18
19
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
19
20
  walletClient: useWallet().walletClient,
21
+ subgraph: {
22
+ subsquid: "https://gmx.squids.live/gmx-synthetics-arbitrum/graphql",
23
+ },
20
24
  });
21
25
 
22
26
  const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();
@@ -54,26 +58,100 @@ sdk.positions.getPositions().then((positions) => {
54
58
 
55
59
  - `getTradeHistory(p: Parameters): Promise<TradeAction[]>` - returns a list of trades
56
60
 
57
- #### Parameters:
61
+ ### Write methods
62
+
63
+ ### Orders
64
+
65
+ - `cancelOrders(orderKeys: string[])` - cancels orders by order keys
66
+ - `createIncreaseOrder(p: Parameters)` - creates an increase order (see [examples](#examples))
67
+ - `createDecreaseOrder(p: Parameters)` - creates a decrease order (see [examples](#examples))
68
+ - `createSwapOrder(p: Parameters)` - creates a swap order (see [examples](#examples))
69
+
70
+ ## Configuration
58
71
 
59
72
  ```typescript
60
- forAllAccounts?: boolean;
61
- pageSize: number;
62
- fromTxTimestamp?: number;
63
- toTxTimestamp?: number;
64
- marketsInfoData: MarketsInfoData | undefined;
65
- tokensData: TokensData | undefined;
66
- pageIndex: number;
67
- marketsDirectionsFilter?: MarketFilterLongShortItemData[];
68
- orderEventCombinations?: {
69
- eventName?: TradeActionType;
70
- orderType?: OrderType;
71
- isDepositOrWithdraw?: boolean;
72
- }[];
73
+ interface GmxSdkConfig {
74
+ chainId: number;
75
+ rpcUrl: string;
76
+ oracleUrl: string;
77
+ subgraph: {
78
+ subsquid?: string;
79
+ };
80
+ account?: string;
81
+ publicClient: PublicClient;
82
+ walletClient: WalletClient;
83
+ tokens?: Record<string, Partial<Token>>;
84
+ markets?: Record<
85
+ string,
86
+ {
87
+ isListed: boolean;
88
+ }
89
+ >;
90
+ }
73
91
  ```
74
92
 
75
- ### Write methods
93
+ ### Tokens customization
76
94
 
77
- ### Orders
95
+ If you need to override some field in tokens, just pass extension object in SDK config:
96
+
97
+ ```typescript
98
+ const sdk = new GmxSdk({
99
+ ...arbitrumSdkConfig,
100
+ tokens: {
101
+ "0x912CE59144191C1204E64559FE8253a0e49E6548": {
102
+ name: "My Custom Name for ARB",
103
+ },
104
+ },
105
+ });
106
+ ```
107
+
108
+ Here and further, `name` field in tokens data object will be taken from the extension object.
109
+
110
+ ### Markets customization
78
111
 
79
- - `cancelOrders(orderKeys: string[])` - creates an order
112
+ To enable/disable market in SDK use config field `markets
113
+
114
+ ```typescript
115
+ const sdk = new GmxSdk({
116
+ ...arbitrumSdkConfig,
117
+ markets: {
118
+ "0x47c031236e19d024b42f8AE6780E44A573170703": {
119
+ isListed: false,
120
+ },
121
+ },
122
+ });
123
+ ```
124
+
125
+ ## Examples
126
+
127
+ ### Open long position
128
+
129
+ ```typescript
130
+ import type { IncreasePositionAmounts } from "@gmx-io/sdk/types/orders";
131
+
132
+ const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();
133
+
134
+ if (!marketsInfoData || !tokensData) {
135
+ throw new Error("No markets or tokens info data");
136
+ }
137
+
138
+ const marketInfo = marketsInfo["0x47c031236e19d024b42f8AE6780E44A573170703"];
139
+ const collateralToken = tokensData["0x912CE59144191C1204E64559FE8253a0e49E6548"];
140
+ sdk.orders.createIncreaseOrder({
141
+ marketsInfoData: marketsInfoData!,
142
+ tokensData,
143
+ isLimit: false,
144
+ isLong: true,
145
+ marketAddress: marketInfo.marketTokenAddress,
146
+ allowedSlippage: 50,
147
+ collateralToken,
148
+ collateralTokenAddress: collateralToken.address,
149
+ receiveTokenAddress: collateralToken.address,
150
+ fromToken: tokensData["0x912CE59144191C1204E64559FE8253a0e49E6548"],
151
+ marketInfo,
152
+ indexToken: marketInfo.indexToken,
153
+ increaseAmounts: {
154
+ // amounts for position
155
+ },
156
+ });
157
+ ```
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { resolve } from "path";
2
+ import { prebuildMarketValuesKeys } from "./prebuildMarketValuesKeys";
3
+ import { prebuildMarketConfigKeys } from "./prebuildMarketConfigKeys";
4
+ /* eslint-disable-next-line no-restricted-globals */
5
+ const OUTPUT_DIR = resolve(process.cwd(), "src/prebuilt");
6
+ prebuildMarketValuesKeys(OUTPUT_DIR);
7
+ prebuildMarketConfigKeys(OUTPUT_DIR);
@@ -0,0 +1 @@
1
+ export declare function prebuildMarketConfigKeys(outputDir: string): {};
@@ -0,0 +1,18 @@
1
+ import fs from "fs";
2
+ import { resolve } from "path";
3
+ import entries from "lodash/entries";
4
+ import { MARKETS } from "../../src/configs/markets";
5
+ import { hashMarketConfigKeys } from "../../src/utils/marketKeysAndConfigs";
6
+ export function prebuildMarketConfigKeys(outputDir) {
7
+ const chainMarketKeys = entries(MARKETS).reduce((chainsAcc, [chainId, markets]) => {
8
+ const chainMarkets = entries(markets).reduce((marketsAcc, [marketAddress, market]) => {
9
+ const marketKeys = hashMarketConfigKeys(market);
10
+ marketsAcc[marketAddress] = marketKeys;
11
+ return marketsAcc;
12
+ }, {});
13
+ chainsAcc[chainId] = chainMarkets;
14
+ return chainsAcc;
15
+ }, {});
16
+ fs.writeFileSync(resolve(outputDir, "hashedMarketConfigKeys.json"), JSON.stringify(chainMarketKeys, null, 2));
17
+ return chainMarketKeys;
18
+ }
@@ -0,0 +1 @@
1
+ export declare function prebuildMarketValuesKeys(outputDir: string): {};
@@ -0,0 +1,18 @@
1
+ import fs from "fs";
2
+ import entries from "lodash/entries";
3
+ import { resolve } from "path";
4
+ import { MARKETS } from "../../src/configs/markets";
5
+ import { hashMarketValuesKeys } from "../../src/utils/marketKeysAndConfigs";
6
+ export function prebuildMarketValuesKeys(outputDir) {
7
+ const chainMarketKeys = entries(MARKETS).reduce((chainsAcc, [chainId, markets]) => {
8
+ const chainMarkets = entries(markets).reduce((marketsAcc, [marketAddress, market]) => {
9
+ const marketKeys = hashMarketValuesKeys(market);
10
+ marketsAcc[marketAddress] = marketKeys;
11
+ return marketsAcc;
12
+ }, {});
13
+ chainsAcc[chainId] = chainMarkets;
14
+ return chainsAcc;
15
+ }, {});
16
+ fs.writeFileSync(resolve(outputDir, "hashedMarketValuesKeys.json"), JSON.stringify(chainMarketKeys, null, 2));
17
+ return chainMarketKeys;
18
+ }
@@ -1,8 +1,7 @@
1
- type MarketConfig = {
1
+ export type MarketConfig = {
2
2
  marketTokenAddress: string;
3
3
  indexTokenAddress: string;
4
4
  longTokenAddress: string;
5
5
  shortTokenAddress: string;
6
6
  };
7
7
  export declare const MARKETS: Record<string, Record<string, MarketConfig>>;
8
- export {};
@@ -28,6 +28,8 @@ export declare class GmxSdk {
28
28
  executeMulticall<T = any>(request: MulticallRequestConfig<any>): Promise<T>;
29
29
  callContract(address: Address, abi: Abi, method: string, params: any[], opts?: CallContractOpts): Promise<`0x${string}`>;
30
30
  get chainId(): number;
31
+ get chain(): import("viem").Chain;
32
+ get account(): `0x${string}`;
31
33
  _gasLimits: GasLimitsConfig | null;
32
34
  getGasLimits(): Promise<GasLimitsConfig>;
33
35
  getEstimatedGasFee(tradeFeesType: TradeFeesType, { increaseAmounts, decreaseAmounts, swapAmounts, }: {
@@ -60,10 +60,7 @@ export class GmxSdk {
60
60
  }
61
61
  async executeMulticall(request) {
62
62
  const multicall = await Multicall.getInstance(this);
63
- const promise = multicall?.call(request, MAX_TIMEOUT);
64
- // debug mode
65
- promise.request = request;
66
- return promise;
63
+ return multicall?.call(request, MAX_TIMEOUT);
67
64
  }
68
65
  async callContract(address, abi, method, params, opts) {
69
66
  return callContract(this, address, abi, method, params, opts);
@@ -71,6 +68,12 @@ export class GmxSdk {
71
68
  get chainId() {
72
69
  return this.config.chainId;
73
70
  }
71
+ get chain() {
72
+ return getChain(this.chainId);
73
+ }
74
+ get account() {
75
+ return this.config.account;
76
+ }
74
77
  async getGasLimits() {
75
78
  if (this._gasLimits) {
76
79
  return this._gasLimits;
@@ -1,4 +1,4 @@
1
- import { arbitrumSdk } from "utils/test";
1
+ import { arbitrumSdk } from "utils/testUtil";
2
2
  describe("Accounts", () => {
3
3
  it("should be able to get delegates", async () => {
4
4
  const delegates = await arbitrumSdk.accounts.getGovTokenDelegates();
@@ -1,9 +1,8 @@
1
- import type { GmxSdk } from "index";
2
- import { Oracle } from "./oracle";
1
+ import type { GmxSdk } from "..";
3
2
  export declare class Module {
4
3
  sdk: GmxSdk;
5
4
  constructor(sdk: GmxSdk);
6
- get oracle(): Oracle;
5
+ get oracle(): import("./oracle").Oracle;
7
6
  get chainId(): number;
8
- get account(): string | undefined;
7
+ get account(): `0x${string}`;
9
8
  }
@@ -10,6 +10,6 @@ export class Module {
10
10
  return this.sdk.chainId;
11
11
  }
12
12
  get account() {
13
- return this.sdk.config.account;
13
+ return this.sdk.account;
14
14
  }
15
15
  }
@@ -1,26 +1,11 @@
1
- import { ClaimableFundingData, MarketsData } from "types/markets";
2
- import { TokensData } from "types/tokens";
3
1
  import { Module } from "../base";
4
- import { MarketConfig, MarketsInfoResult, MarketsResult } from "./types";
2
+ import { MarketsInfoResult, MarketsResult } from "./types";
5
3
  export declare class Markets extends Module {
4
+ private getClaimableFundingData;
5
+ private getMarketsValues;
6
+ private getMarketsConfigs;
6
7
  private _marketsData;
7
8
  getMarkets(offset?: bigint, limit?: bigint): Promise<MarketsResult>;
8
- getClaimableFundingData(): Promise<ClaimableFundingData>;
9
- getMarketsValues({ marketsAddresses, marketsData, tokensData, }: {
10
- account: string | undefined;
11
- marketsAddresses: string[] | undefined;
12
- marketsData: MarketsData | undefined;
13
- tokensData: TokensData | undefined;
14
- }): Promise<MarketsResult>;
15
- /**
16
- * Fetch market configs from the blockchain
17
- */
18
- getMarketsConfigs({ marketsAddresses, marketsData, }: {
19
- marketsAddresses: string[] | undefined;
20
- marketsData: MarketsData | undefined;
21
- }): Promise<{
22
- [marketAddress: string]: MarketConfig;
23
- }>;
24
9
  getMarketsInfo(): Promise<MarketsInfoResult>;
25
10
  getDailyVolumes(): Promise<{} | undefined>;
26
11
  }
@@ -10,72 +10,6 @@ import { getByKey } from "utils/objects";
10
10
  import { Module } from "../base";
11
11
  import { buildClaimableFundingDataRequest, buildMarketsConfigsRequest, buildMarketsValuesRequest, } from "./query-builders";
12
12
  export class Markets extends Module {
13
- async getMarkets(offset = 0n, limit = 100n) {
14
- if (this._marketsData) {
15
- return this._marketsData;
16
- }
17
- const readerAddress = getContract(this.chainId, "SyntheticsReader");
18
- const dataStoreAddress = getContract(this.chainId, "DataStore");
19
- const apiMarkets = await this.sdk.oracle.getMarkets();
20
- const marketsMap = apiMarkets.reduce((acc, market) => {
21
- return {
22
- ...acc,
23
- [market.marketToken]: market,
24
- };
25
- }, {});
26
- const markets = await this.sdk
27
- .executeMulticall({
28
- markets: {
29
- contractAddress: readerAddress,
30
- abi: SyntheticsReader.abi,
31
- calls: {
32
- markets: {
33
- methodName: "getMarkets",
34
- params: [dataStoreAddress, offset, offset + limit],
35
- },
36
- },
37
- },
38
- })
39
- .then((res) => {
40
- return res.data.markets.markets.returnValues.map((market) => {
41
- return {
42
- marketTokenAddress: market.marketToken,
43
- indexTokenAddress: market.indexToken,
44
- longTokenAddress: market.longToken,
45
- shortTokenAddress: market.shortToken,
46
- };
47
- });
48
- });
49
- const chainId = this.chainId;
50
- const marketsResult = markets.reduce((acc, market) => {
51
- try {
52
- if (!marketsMap[market.marketTokenAddress]?.isListed) {
53
- return acc;
54
- }
55
- const indexToken = getToken(chainId, convertTokenAddress(chainId, market.indexTokenAddress, "native"));
56
- const longToken = getToken(chainId, market.longTokenAddress);
57
- const shortToken = getToken(chainId, market.shortTokenAddress);
58
- const isSameCollaterals = market.longTokenAddress === market.shortTokenAddress;
59
- const isSpotOnly = market.indexTokenAddress === zeroAddress;
60
- const name = getMarketFullName({ indexToken, longToken, shortToken, isSpotOnly });
61
- acc.marketsAddresses.push(market.marketTokenAddress);
62
- acc.marketsData[market.marketTokenAddress] = {
63
- ...market,
64
- isSameCollaterals,
65
- isSpotOnly,
66
- name,
67
- data: "",
68
- };
69
- }
70
- catch (e) {
71
- // eslint-disable-next-line no-console
72
- console.warn(`Unsupported market ${market.marketTokenAddress}`, e);
73
- }
74
- return acc;
75
- }, { marketsData: {}, marketsAddresses: [] });
76
- this._marketsData = marketsResult;
77
- return marketsResult;
78
- }
79
13
  async getClaimableFundingData() {
80
14
  const chainId = this.chainId;
81
15
  const account = this.account;
@@ -176,9 +110,6 @@ export class Markets extends Module {
176
110
  return result;
177
111
  });
178
112
  }
179
- /**
180
- * Fetch market configs from the blockchain
181
- */
182
113
  async getMarketsConfigs({ marketsAddresses, marketsData, }) {
183
114
  const dataStoreAddress = getContract(this.chainId, "DataStore");
184
115
  const request = await buildMarketsConfigsRequest(this.chainId, {
@@ -251,12 +182,82 @@ export class Markets extends Module {
251
182
  return result;
252
183
  });
253
184
  }
185
+ async getMarkets(offset = 0n, limit = 100n) {
186
+ if (this._marketsData) {
187
+ return this._marketsData;
188
+ }
189
+ const readerAddress = getContract(this.chainId, "SyntheticsReader");
190
+ const dataStoreAddress = getContract(this.chainId, "DataStore");
191
+ const apiMarkets = await this.sdk.oracle.getMarkets();
192
+ const configMarkets = this.sdk.config.markets ?? {};
193
+ const marketsMap = apiMarkets.reduce((acc, market) => {
194
+ if (configMarkets[market.marketToken]?.isListed === false) {
195
+ return acc;
196
+ }
197
+ return {
198
+ ...acc,
199
+ [market.marketToken]: market,
200
+ };
201
+ }, {});
202
+ const markets = await this.sdk
203
+ .executeMulticall({
204
+ markets: {
205
+ contractAddress: readerAddress,
206
+ abi: SyntheticsReader.abi,
207
+ calls: {
208
+ markets: {
209
+ methodName: "getMarkets",
210
+ params: [dataStoreAddress, offset, offset + limit],
211
+ },
212
+ },
213
+ },
214
+ })
215
+ .then((res) => {
216
+ return res.data.markets.markets.returnValues.map((market) => {
217
+ return {
218
+ marketTokenAddress: market.marketToken,
219
+ indexTokenAddress: market.indexToken,
220
+ longTokenAddress: market.longToken,
221
+ shortTokenAddress: market.shortToken,
222
+ };
223
+ });
224
+ });
225
+ const chainId = this.chainId;
226
+ const marketsResult = markets.reduce((acc, market) => {
227
+ try {
228
+ if (!marketsMap[market.marketTokenAddress]?.isListed) {
229
+ return acc;
230
+ }
231
+ const indexToken = getToken(chainId, convertTokenAddress(chainId, market.indexTokenAddress, "native"));
232
+ const longToken = getToken(chainId, market.longTokenAddress);
233
+ const shortToken = getToken(chainId, market.shortTokenAddress);
234
+ const isSameCollaterals = market.longTokenAddress === market.shortTokenAddress;
235
+ const isSpotOnly = market.indexTokenAddress === zeroAddress;
236
+ const name = getMarketFullName({ indexToken, longToken, shortToken, isSpotOnly });
237
+ acc.marketsAddresses.push(market.marketTokenAddress);
238
+ acc.marketsData[market.marketTokenAddress] = {
239
+ ...market,
240
+ isSameCollaterals,
241
+ isSpotOnly,
242
+ name,
243
+ data: "",
244
+ };
245
+ }
246
+ catch (e) {
247
+ // eslint-disable-next-line no-console
248
+ console.warn(`Unsupported market ${market.marketTokenAddress}`, e);
249
+ }
250
+ return acc;
251
+ }, { marketsData: {}, marketsAddresses: [] });
252
+ this._marketsData = marketsResult;
253
+ return marketsResult;
254
+ }
254
255
  async getMarketsInfo() {
255
256
  const { marketsData, marketsAddresses } = await this.getMarkets();
256
- const { tokensData, pricesUpdatedAt, error: tokensDataError, isBalancesLoaded, } = await this.sdk.tokens.getTokensData();
257
+ const { tokensData, pricesUpdatedAt } = await this.sdk.tokens.getTokensData();
257
258
  const [marketsValues, marketsConfigs, claimableFundingData] = await Promise.all([
258
259
  this.getMarketsValues({
259
- account: this.sdk.config.account,
260
+ account: this.account,
260
261
  marketsAddresses,
261
262
  marketsData,
262
263
  tokensData,
@@ -272,8 +273,6 @@ export class Markets extends Module {
272
273
  marketsInfoData: {},
273
274
  tokensData,
274
275
  pricesUpdatedAt,
275
- error: tokensDataError,
276
- isBalancesLoaded,
277
276
  };
278
277
  }
279
278
  // Manual merging to avoid cloning tokens as they are sometimes compared by reference
@@ -301,13 +300,10 @@ export class Markets extends Module {
301
300
  };
302
301
  marketsInfoData[marketAddress] = fullMarketInfo;
303
302
  }
304
- const error = tokensDataError;
305
303
  return {
306
304
  marketsInfoData,
307
305
  tokensData,
308
306
  pricesUpdatedAt,
309
- error,
310
- isBalancesLoaded,
311
307
  };
312
308
  }
313
309
  async getDailyVolumes() {
@@ -1,4 +1,5 @@
1
- import { arbitrumSdk } from "utils/test";
1
+ import { GmxSdk } from "../../index";
2
+ import { arbitrumSdk, arbitrumSdkConfig } from "utils/testUtil";
2
3
  describe("Markets", () => {
3
4
  describe("getMarkets", () => {
4
5
  it("should be able to get markets", async () => {
@@ -12,15 +13,19 @@ describe("Markets", () => {
12
13
  expect(marketsData.marketsAddresses).toBeDefined();
13
14
  expect(marketsData.marketsData).toBeDefined();
14
15
  });
15
- });
16
- describe("getMarketsConfigs", () => {
17
- it("should be able to get markets configs", async () => {
18
- const data = await arbitrumSdk.markets.getMarkets();
19
- const response = await arbitrumSdk.markets.getMarketsConfigs({
20
- marketsAddresses: data.marketsAddresses,
21
- marketsData: data.marketsData,
16
+ it("should respect config filters", async () => {
17
+ const sdk = new GmxSdk({
18
+ ...arbitrumSdkConfig,
19
+ markets: {
20
+ "0x47c031236e19d024b42f8AE6780E44A573170703": {
21
+ isListed: false,
22
+ },
23
+ },
22
24
  });
23
- expect(response).toBeDefined();
25
+ const baseSdkResponse = await arbitrumSdk.markets.getMarkets();
26
+ const sdkResponse = await sdk.markets.getMarkets();
27
+ expect(baseSdkResponse.marketsData?.["0x47c031236e19d024b42f8AE6780E44A573170703"]).toBeDefined();
28
+ expect(sdkResponse.marketsData?.["0x47c031236e19d024b42f8AE6780E44A573170703"]).not.toBeDefined();
24
29
  });
25
30
  });
26
31
  describe("getMarketsInfo", () => {
@@ -95,6 +95,7 @@ export async function buildMarketsValuesRequest(chainId, { marketsAddresses, mar
95
95
  };
96
96
  let prebuiltHashedKeys = HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress];
97
97
  if (!prebuiltHashedKeys) {
98
+ // eslint-disable-next-line no-console
98
99
  console.warn(`No pre-built hashed market keys found for the market ${marketAddress}. Run \`yarn prebuild\` to generate them.`);
99
100
  if (!marketsData?.[marketAddress]) {
100
101
  throw new Error(`No market data found for the market ${marketAddress}`);
@@ -170,6 +171,7 @@ export async function buildMarketsConfigsRequest(chainId, { marketsData, markets
170
171
  for (const marketAddress of marketsAddresses || []) {
171
172
  let prebuiltHashedKeys = HASHED_MARKET_CONFIG_KEYS[chainId]?.[marketAddress];
172
173
  if (!prebuiltHashedKeys) {
174
+ // eslint-disable-next-line no-console
173
175
  console.warn(`No pre-built hashed config keys found for the market ${marketAddress}. Run \`yarn prebuild\` to generate them.`);
174
176
  if (!marketsData?.[marketAddress]) {
175
177
  throw new Error(`No market data found for the market ${marketAddress}`);
@@ -10,8 +10,6 @@ export type MarketsInfoResult = {
10
10
  marketsInfoData?: MarketsInfoData;
11
11
  tokensData?: TokensData;
12
12
  pricesUpdatedAt?: number;
13
- isBalancesLoaded?: boolean;
14
- error?: Error;
15
13
  };
16
14
  export type MarketValues = Pick<MarketInfo, "longInterestUsd" | "shortInterestUsd" | "longInterestInTokens" | "shortInterestInTokens" | "longPoolAmount" | "shortPoolAmount" | "poolValueMin" | "poolValueMax" | "totalBorrowingFees" | "positionImpactPoolAmount" | "swapImpactPoolAmountLong" | "swapImpactPoolAmountShort" | "pnlLongMax" | "pnlLongMin" | "pnlShortMax" | "pnlShortMin" | "netPnlMax" | "netPnlMin" | "borrowingFactorPerSecondForLongs" | "borrowingFactorPerSecondForShorts" | "fundingFactorPerSecond" | "longsPayShorts" | "virtualPoolAmountForLongToken" | "virtualPoolAmountForShortToken" | "virtualInventoryForPositions">;
17
15
  /**
@@ -1,4 +1,5 @@
1
1
  import type { GmxSdk } from "../index";
2
+ import { MarketSdkConfig } from "types/markets";
2
3
  export type TickersResponse = {
3
4
  minPrice: string;
4
5
  maxPrice: string;
@@ -13,19 +14,11 @@ export type TokensResponse = {
13
14
  decimals: number;
14
15
  synthetic: boolean;
15
16
  }[];
16
- export type ApiMarket = {
17
- marketToken: string;
18
- indexToken: string;
19
- longToken: string;
20
- shortToken: string;
21
- isListed: boolean;
22
- };
23
- export type MarketsResponse = ApiMarket[];
24
17
  export declare class Oracle {
25
18
  sdk: GmxSdk;
26
19
  private url;
27
20
  constructor(sdk: GmxSdk);
28
- getMarkets(): Promise<MarketsResponse>;
21
+ getMarkets(): Promise<MarketSdkConfig[]>;
29
22
  getTokens(): Promise<TokensResponse>;
30
23
  getTickers(): Promise<TickersResponse>;
31
24
  }
@@ -1,4 +1,4 @@
1
- import { arbitrumSdk } from "utils/test";
1
+ import { arbitrumSdk } from "utils/testUtil";
2
2
  describe("Positions", () => {
3
3
  describe("read", () => {
4
4
  it("should be able to get orders", async () => {
@@ -33,7 +33,6 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
33
33
  isNativePayment,
34
34
  initialCollateralTokenAddress,
35
35
  });
36
- const orders = concat(createDecreaseOrderParams ?? [], cancelOrderParams ?? [], updateOrderParams ?? []).map((p) => getPendingOrderFromParams(chainId, p.txnType, p)) || [];
37
36
  const simulationEncodedPayload = await createEncodedPayload({
38
37
  routerAbi: ExchangeRouter.abi,
39
38
  orderVaultAddress,
@@ -1,6 +1,6 @@
1
- import type { GmxSdk } from "../../../index";
2
1
  import { OrderType } from "types/orders";
3
2
  import { TokensData } from "types/tokens";
3
+ import type { GmxSdk } from "../../..";
4
4
  export type SwapOrderParams = {
5
5
  fromTokenAddress: string;
6
6
  fromTokenAmount: bigint;