@gmx-io/sdk 1.0.1 → 1.0.2

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 CHANGED
@@ -18,7 +18,7 @@ const sdk = new GmxSdk({
18
18
  rpcUrl: "https://arb1.arbitrum.io/rpc",
19
19
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
20
20
  walletClient: useWallet().walletClient,
21
- subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql",
21
+ subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
22
22
  });
23
23
 
24
24
  const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();
@@ -214,17 +214,19 @@ Helpers are a set of functions that help you create orders without manually calc
214
214
  ```typescript
215
215
  sdk.orders.long({
216
216
  payAmount: 100031302n,
217
- marketAddress: "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
218
- payTokenAddress: market.indexToken.address,
219
- collateralTokenAddress: market.shortToken.address,
217
+ marketAddress: "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", // ETH/USD [WETH-USDC]
218
+ payTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", // WETH
219
+ collateralTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
220
220
  allowedSlippageBps: 125,
221
221
  leverage: 50000n,
222
222
  });
223
223
 
224
224
  sdk.orders.swap({
225
225
  fromAmount: 1000n,
226
- fromTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
227
- toTokenAddress: "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4",
226
+ fromTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548", // ARB
227
+ toTokenAddress: "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4", // LINK
228
228
  allowedSlippageBps: 125,
229
229
  });
230
230
  ```
231
+
232
+ Pay attention to the `payTokenAddress` and `collateralTokenAddress` fields. They are the addresses of ERC20 tokens that you are paying for and receiving, respectively, some markets may have synthetic tokens in these fields, so you need to pass the correct address. For instance BTC/USD [WETH-USDC] market has synthetic BTC token in `indexTokenAddress` so you need to pass WBTC address instead of BTC.
@@ -52,10 +52,16 @@ async function increaseOrderHelper(sdk, params) {
52
52
  const fromToken = tokensData[params.payTokenAddress];
53
53
  const collateralToken = tokensData[params.collateralTokenAddress];
54
54
  if (!fromToken) {
55
- throw new Error("From token is not available");
55
+ throw new Error("payTokenAddress: token is not available");
56
56
  }
57
57
  if (!collateralToken) {
58
- throw new Error("Collateral token is not available");
58
+ throw new Error("collateralTokenAddress: token is not available");
59
+ }
60
+ if (fromToken.isSynthetic) {
61
+ throw new Error("payTokenAddress: synthetic tokens are not supported");
62
+ }
63
+ if (collateralToken.isSynthetic) {
64
+ throw new Error("collateralTokenAddress: synthetic tokens are not supported");
59
65
  }
60
66
  const marketInfo = (0, objects_1.getByKey)(marketsInfoData, params.marketAddress);
61
67
  if (!marketInfo) {
@@ -66,7 +66,30 @@ const tradeAmounts = __importStar(require("../../utils/trade/amounts"));
66
66
  const e = await testUtil_1.arbitrumSdk.orders
67
67
  .long({
68
68
  ...mockParams,
69
- collateralTokenAddress: "0x47904963fc8b2340414262125aF798B9655E58Cd",
69
+ marketAddress: "0x47c031236e19d024b42f8AE6780E44A573170703",
70
+ collateralTokenAddress: "0xC4da4c24fd591125c3F47b340b6f4f76111883d8",
71
+ })
72
+ .catch((error) => {
73
+ return error.message;
74
+ });
75
+ await (0, vitest_1.expect)(e).toBe("collateralTokenAddress: synthetic tokens are not supported");
76
+ });
77
+ (0, vitest_1.it)("should throw an error if wrong collateral token selected", async () => {
78
+ const e = await testUtil_1.arbitrumSdk.orders
79
+ .long({
80
+ ...mockParams,
81
+ collateralTokenAddress: "0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A",
82
+ })
83
+ .catch((error) => {
84
+ return error.message;
85
+ });
86
+ await (0, vitest_1.expect)(e).toBe("collateralTokenAddress: token is not available");
87
+ });
88
+ (0, vitest_1.it)("should throw an error if wrong collateral token selected", async () => {
89
+ const e = await testUtil_1.arbitrumSdk.orders
90
+ .long({
91
+ ...mockParams,
92
+ collateralTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
70
93
  })
71
94
  .catch((error) => {
72
95
  return error.message;
@@ -112,8 +112,8 @@ class Orders extends base_1.Module {
112
112
  account,
113
113
  collateralAddress: collateralToken.address,
114
114
  }));
115
- if (collateralToken.address !== marketInfo.longToken.address &&
116
- collateralToken.address !== marketInfo.shortToken.address) {
115
+ if (collateralToken.address !== marketInfo.longTokenAddress &&
116
+ collateralToken.address !== marketInfo.shortTokenAddress) {
117
117
  const availableTokens = marketInfo.isSameCollaterals
118
118
  ? `long ${marketInfo.longToken.symbol}`
119
119
  : `long ${marketInfo.longToken.symbol} and short ${marketInfo.shortToken.symbol}`;
@@ -17,6 +17,6 @@ exports.arbitrumSdkConfig = {
17
17
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
18
18
  rpcUrl: "https://arb1.arbitrum.io/rpc",
19
19
  walletClient: client,
20
- subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum@e27d93/api/graphql",
20
+ subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
21
21
  };
22
22
  exports.arbitrumSdk = new index_1.GmxSdk(exports.arbitrumSdkConfig);
@@ -49,10 +49,16 @@ export async function increaseOrderHelper(sdk, params) {
49
49
  const fromToken = tokensData[params.payTokenAddress];
50
50
  const collateralToken = tokensData[params.collateralTokenAddress];
51
51
  if (!fromToken) {
52
- throw new Error("From token is not available");
52
+ throw new Error("payTokenAddress: token is not available");
53
53
  }
54
54
  if (!collateralToken) {
55
- throw new Error("Collateral token is not available");
55
+ throw new Error("collateralTokenAddress: token is not available");
56
+ }
57
+ if (fromToken.isSynthetic) {
58
+ throw new Error("payTokenAddress: synthetic tokens are not supported");
59
+ }
60
+ if (collateralToken.isSynthetic) {
61
+ throw new Error("collateralTokenAddress: synthetic tokens are not supported");
56
62
  }
57
63
  const marketInfo = getByKey(marketsInfoData, params.marketAddress);
58
64
  if (!marketInfo) {
@@ -41,7 +41,30 @@ describe("increaseOrderHelper", () => {
41
41
  const e = await arbitrumSdk.orders
42
42
  .long({
43
43
  ...mockParams,
44
- collateralTokenAddress: "0x47904963fc8b2340414262125aF798B9655E58Cd",
44
+ marketAddress: "0x47c031236e19d024b42f8AE6780E44A573170703",
45
+ collateralTokenAddress: "0xC4da4c24fd591125c3F47b340b6f4f76111883d8",
46
+ })
47
+ .catch((error) => {
48
+ return error.message;
49
+ });
50
+ await expect(e).toBe("collateralTokenAddress: synthetic tokens are not supported");
51
+ });
52
+ it("should throw an error if wrong collateral token selected", async () => {
53
+ const e = await arbitrumSdk.orders
54
+ .long({
55
+ ...mockParams,
56
+ collateralTokenAddress: "0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A",
57
+ })
58
+ .catch((error) => {
59
+ return error.message;
60
+ });
61
+ await expect(e).toBe("collateralTokenAddress: token is not available");
62
+ });
63
+ it("should throw an error if wrong collateral token selected", async () => {
64
+ const e = await arbitrumSdk.orders
65
+ .long({
66
+ ...mockParams,
67
+ collateralTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
45
68
  })
46
69
  .catch((error) => {
47
70
  return error.message;
@@ -109,8 +109,8 @@ export class Orders extends Module {
109
109
  account,
110
110
  collateralAddress: collateralToken.address,
111
111
  }));
112
- if (collateralToken.address !== marketInfo.longToken.address &&
113
- collateralToken.address !== marketInfo.shortToken.address) {
112
+ if (collateralToken.address !== marketInfo.longTokenAddress &&
113
+ collateralToken.address !== marketInfo.shortTokenAddress) {
114
114
  const availableTokens = marketInfo.isSameCollaterals
115
115
  ? `long ${marketInfo.longToken.symbol}`
116
116
  : `long ${marketInfo.longToken.symbol} and short ${marketInfo.shortToken.symbol}`;
@@ -14,6 +14,6 @@ export const arbitrumSdkConfig = {
14
14
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
15
15
  rpcUrl: "https://arb1.arbitrum.io/rpc",
16
16
  walletClient: client,
17
- subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum@e27d93/api/graphql",
17
+ subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
18
18
  };
19
19
  export const arbitrumSdk = new GmxSdk(arbitrumSdkConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmx-io/sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "./build/cjs/src/index.js",
6
6
  "module": "./build/esm/src/index.js",