@gmx-io/sdk 1.5.0-alpha-1 → 1.5.0-alpha-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.
Files changed (156) hide show
  1. package/build/cjs/scripts/generate-platform-tokens.js +200 -0
  2. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  3. package/build/cjs/src/clients/v1/modules/accounts/accounts.js +1 -1
  4. package/build/cjs/src/clients/v1/modules/markets/index.js +1 -1
  5. package/build/cjs/src/clients/v1/modules/markets/markets.spec.js +2 -2
  6. package/build/cjs/src/clients/v1/modules/orders/orders.js +4 -4
  7. package/build/cjs/src/clients/v1/modules/positions/positions.js +9 -151
  8. package/build/cjs/src/clients/v1/modules/tokens/tokens.js +1 -1
  9. package/build/cjs/src/clients/v1/modules/tokens/tokens.spec.js +2 -2
  10. package/build/cjs/src/clients/v1/modules/trades/trades.js +1 -1
  11. package/build/cjs/src/clients/v1/modules/utils/utils.js +1 -1
  12. package/build/cjs/src/clients/v2/index.js +8 -0
  13. package/build/cjs/src/codegen/platformTokens.json +134 -0
  14. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  15. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
  16. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
  17. package/build/cjs/src/codegen/subsquid.js +142 -22
  18. package/build/cjs/src/configs/markets.js +21 -0
  19. package/build/cjs/src/configs/tokens.js +35 -0
  20. package/build/cjs/src/utils/__tests__/fees.spec.js +1 -1
  21. package/build/cjs/src/utils/__tests__/numbers.spec.js +1 -1
  22. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  23. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  24. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  25. package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
  26. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  27. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  28. package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  29. package/build/cjs/src/utils/__tests__/parseError.spec.js +40 -0
  30. package/build/cjs/src/utils/__tests__/positions.spec.js +1 -1
  31. package/build/cjs/src/utils/__tests__/prices.spec.js +1 -1
  32. package/build/cjs/src/utils/__tests__/tokens.spec.js +191 -4
  33. package/build/cjs/src/utils/errors/parseError.js +67 -25
  34. package/build/cjs/src/utils/fees/executionFee.js +1 -1
  35. package/build/cjs/src/utils/fees/priceImpact.js +6 -1
  36. package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +1 -1
  37. package/build/cjs/src/utils/numbers/utils.js +4 -2
  38. package/build/cjs/src/utils/orders/api.js +13 -0
  39. package/build/cjs/src/utils/orders/index.js +1 -0
  40. package/build/cjs/src/utils/orders/utils.js +2 -2
  41. package/build/cjs/src/utils/positions/api.js +14 -0
  42. package/build/cjs/src/utils/positions/index.js +1 -0
  43. package/build/cjs/src/utils/positions/utils.js +213 -1
  44. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
  45. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  46. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  47. package/build/cjs/src/utils/swap/buildSwapStrategy.js +1 -1
  48. package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  49. package/build/cjs/src/utils/swap/swapPath.js +1 -1
  50. package/build/cjs/src/utils/swap/swapValues.js +1 -1
  51. package/build/cjs/src/utils/tokens/utils.js +23 -3
  52. package/build/cjs/src/utils/trade/decrease.js +1 -1
  53. package/build/cjs/src/utils/trade/increase.js +1 -1
  54. package/build/cjs/src/utils/trade/trade.js +1 -1
  55. package/build/esm/scripts/generate-platform-tokens.js +195 -0
  56. package/build/esm/scripts/subsquid-codegen.js +1 -1
  57. package/build/esm/src/clients/v1/modules/accounts/accounts.js +1 -1
  58. package/build/esm/src/clients/v1/modules/markets/index.js +1 -1
  59. package/build/esm/src/clients/v1/modules/markets/markets.spec.js +1 -1
  60. package/build/esm/src/clients/v1/modules/orders/orders.js +4 -4
  61. package/build/esm/src/clients/v1/modules/positions/positions.js +12 -154
  62. package/build/esm/src/clients/v1/modules/tokens/tokens.js +1 -1
  63. package/build/esm/src/clients/v1/modules/tokens/tokens.spec.js +1 -1
  64. package/build/esm/src/clients/v1/modules/trades/trades.js +1 -1
  65. package/build/esm/src/clients/v1/modules/utils/utils.js +1 -1
  66. package/build/esm/src/clients/v2/index.js +8 -0
  67. package/build/esm/src/codegen/platformTokens.json +134 -0
  68. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  69. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
  70. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
  71. package/build/esm/src/codegen/subsquid.js +141 -21
  72. package/build/esm/src/configs/markets.js +21 -0
  73. package/build/esm/src/configs/tokens.js +35 -0
  74. package/build/esm/src/utils/__tests__/fees.spec.js +1 -1
  75. package/build/esm/src/utils/__tests__/numbers.spec.js +1 -1
  76. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  77. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  78. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  79. package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
  80. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  81. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  82. package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  83. package/build/esm/src/utils/__tests__/parseError.spec.js +40 -0
  84. package/build/esm/src/utils/__tests__/positions.spec.js +1 -1
  85. package/build/esm/src/utils/__tests__/prices.spec.js +1 -1
  86. package/build/esm/src/utils/__tests__/tokens.spec.js +192 -5
  87. package/build/esm/src/utils/errors/parseError.js +64 -24
  88. package/build/esm/src/utils/fees/executionFee.js +1 -1
  89. package/build/esm/src/utils/fees/priceImpact.js +5 -1
  90. package/build/esm/src/utils/markets/__tests__/mockMarkets.js +1 -1
  91. package/build/esm/src/utils/numbers/utils.js +2 -0
  92. package/build/esm/src/utils/orders/api.js +9 -0
  93. package/build/esm/src/utils/orders/index.js +1 -0
  94. package/build/esm/src/utils/orders/utils.js +2 -2
  95. package/build/esm/src/utils/positions/api.js +10 -0
  96. package/build/esm/src/utils/positions/index.js +1 -0
  97. package/build/esm/src/utils/positions/utils.js +213 -3
  98. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
  99. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  100. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  101. package/build/esm/src/utils/swap/buildSwapStrategy.js +1 -1
  102. package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  103. package/build/esm/src/utils/swap/swapPath.js +1 -1
  104. package/build/esm/src/utils/swap/swapValues.js +1 -1
  105. package/build/esm/src/utils/tokens/utils.js +23 -3
  106. package/build/esm/src/utils/trade/decrease.js +1 -1
  107. package/build/esm/src/utils/trade/increase.js +1 -1
  108. package/build/esm/src/utils/trade/trade.js +1 -1
  109. package/build/types/scripts/generate-platform-tokens.d.ts +27 -0
  110. package/build/types/src/clients/v1/modules/markets/index.d.ts +1 -1
  111. package/build/types/src/clients/v1/modules/oracle.d.ts +1 -1
  112. package/build/types/src/clients/v1/modules/orders/helpers.d.ts +1 -1
  113. package/build/types/src/clients/v1/modules/orders/orders.d.ts +2 -2
  114. package/build/types/src/clients/v1/modules/orders/transactions/cancelOrdersTxn.d.ts +1 -1
  115. package/build/types/src/clients/v1/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -1
  116. package/build/types/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -1
  117. package/build/types/src/clients/v1/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -1
  118. package/build/types/src/clients/v1/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
  119. package/build/types/src/clients/v1/modules/orders/transactions/updateOrderTxn.d.ts +1 -1
  120. package/build/types/src/clients/v1/modules/orders/utils.d.ts +2 -2
  121. package/build/types/src/clients/v1/modules/positions/positions.d.ts +1 -1
  122. package/build/types/src/clients/v1/modules/tokens/tokens.d.ts +1 -1
  123. package/build/types/src/clients/v1/modules/trades/trades.d.ts +2 -2
  124. package/build/types/src/clients/v1/modules/utils/utils.d.ts +1 -1
  125. package/build/types/src/clients/v2/index.d.ts +7 -0
  126. package/build/types/src/codegen/prebuilt/index.d.ts +240 -0
  127. package/build/types/src/codegen/subsquid.d.ts +492 -60
  128. package/build/types/src/utils/errors/parseError.d.ts +13 -1
  129. package/build/types/src/utils/fees/executionFee.d.ts +1 -1
  130. package/build/types/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +1 -1
  131. package/build/types/src/utils/fees/index.d.ts +1 -1
  132. package/build/types/src/utils/fees/priceImpact.d.ts +1 -0
  133. package/build/types/src/utils/markets/api.d.ts +1 -1
  134. package/build/types/src/utils/markets/multicall.d.ts +1 -1
  135. package/build/types/src/utils/markets/utils.d.ts +1 -1
  136. package/build/types/src/utils/numbers/utils.d.ts +2 -0
  137. package/build/types/src/utils/orders/api.d.ts +7 -0
  138. package/build/types/src/utils/orders/index.d.ts +1 -0
  139. package/build/types/src/utils/orders/types.d.ts +27 -0
  140. package/build/types/src/utils/orders/utils.d.ts +1 -1
  141. package/build/types/src/utils/positions/api.d.ts +8 -0
  142. package/build/types/src/utils/positions/index.d.ts +1 -0
  143. package/build/types/src/utils/positions/types.d.ts +5 -16
  144. package/build/types/src/utils/positions/utils.d.ts +42 -1
  145. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +1 -1
  146. package/build/types/src/utils/swap/findSwapPathsBetweenTokens.d.ts +1 -1
  147. package/build/types/src/utils/swap/preparedSwapData.d.ts +1 -1
  148. package/build/types/src/utils/swap/swapRouting.d.ts +1 -1
  149. package/build/types/src/utils/tokens/types.d.ts +1 -1
  150. package/build/types/src/utils/trade/decrease.d.ts +1 -1
  151. package/build/types/src/utils/trade/increase.d.ts +1 -1
  152. package/build/types/src/utils/trade/trade.d.ts +1 -1
  153. package/build/types/src/utils/tradeHistory/types.d.ts +2 -2
  154. package/build/types/src/utils/tradeHistory/utils.d.ts +1 -1
  155. package/build/types/src/utils/twap/index.d.ts +1 -1
  156. package/package.json +4 -3
@@ -0,0 +1,195 @@
1
+ /* eslint-disable no-console */
2
+ /**
3
+ * Generate platform tokens JSON from gmxLayerZero deployments folder
4
+ *
5
+ * Prerequisites:
6
+ * Cloned https://github.com/gmx-io/layer-zero repository
7
+ *
8
+ * Usage:
9
+ * yarn tsx sdk/scripts/generate-platform-tokens.ts <layer-zero-path>
10
+ *
11
+ * Example:
12
+ * # Relative to monorepo root
13
+ * yarn tsx sdk/scripts/generate-platform-tokens.ts ../layer-zero
14
+ * yarn tsx sdk/scripts/generate-platform-tokens.ts /path/to/layer-zero
15
+ *
16
+ *
17
+ * Expected folder structure:
18
+ * layer-zero/
19
+ * deployments/
20
+ * arbitrum-mainnet/
21
+ * .chainId
22
+ * TokenName.json
23
+ * base-mainnet/
24
+ * .chainId
25
+ * TokenName.json
26
+ * ...
27
+ */
28
+ import fs from "fs";
29
+ import path from "path";
30
+ import { fileURLToPath } from "url";
31
+ import { getAddress } from "viem";
32
+ import { isTestnetChain, SETTLEMENT_CHAIN_IDS_DEV, SOURCE_CHAIN_IDS } from "../src/configs/chains";
33
+ // @ts-ignore
34
+ const __filename = fileURLToPath(import.meta.url);
35
+ const __dirname = path.dirname(__filename);
36
+ function getChainId(chainPath) {
37
+ const chainIdPath = path.join(chainPath, ".chainId");
38
+ if (!fs.existsSync(chainIdPath)) {
39
+ return null;
40
+ }
41
+ try {
42
+ const chainId = parseInt(fs.readFileSync(chainIdPath, "utf8").trim(), 10);
43
+ if (isNaN(chainId)) {
44
+ return null;
45
+ }
46
+ return chainId;
47
+ }
48
+ catch (_error) {
49
+ return null;
50
+ }
51
+ }
52
+ function extractTokenSymbol(filename) {
53
+ const name = filename.replace(/\.json$/i, "");
54
+ if (name.startsWith("GlvToken_")) {
55
+ const suffix = name.replace("GlvToken_", "");
56
+ const parts = suffix.replace(/^(Adapter|OFT)_/, "").split("_");
57
+ if (parts.length < 2) {
58
+ return null;
59
+ }
60
+ return `<GLV-${parts.join("-")}>`;
61
+ }
62
+ if (name.startsWith("MarketToken_")) {
63
+ const suffix = name.replace("MarketToken_", "").replace(/^(Adapter|OFT)_/, "");
64
+ return `<GM-${suffix.replace(/_/g, "-")}>`;
65
+ }
66
+ return null;
67
+ }
68
+ function readTokenDeployment(filePath) {
69
+ try {
70
+ const content = fs.readFileSync(filePath, "utf8");
71
+ const data = JSON.parse(content);
72
+ const filename = path.basename(filePath, ".json");
73
+ const isOFT = filename.includes("_OFT_");
74
+ const isAdapter = filename.includes("_Adapter_");
75
+ if (isOFT) {
76
+ return {
77
+ address: getAddress(data.address),
78
+ stargate: getAddress(data.address),
79
+ };
80
+ }
81
+ if (isAdapter) {
82
+ return {
83
+ address: getAddress(data.args[0]),
84
+ stargate: getAddress(data.address),
85
+ };
86
+ }
87
+ return null;
88
+ }
89
+ catch (error) {
90
+ console.error(`Error reading ${filePath}:`, error);
91
+ return null;
92
+ }
93
+ }
94
+ function generatePlatformTokens(gmxLayerZeroPath) {
95
+ const deploymentsPath = path.join(gmxLayerZeroPath, "deployments");
96
+ if (!fs.existsSync(deploymentsPath)) {
97
+ console.error(`Error: deployments folder not found at ${deploymentsPath}`);
98
+ process.exit(1);
99
+ }
100
+ const allowedChains = [...SETTLEMENT_CHAIN_IDS_DEV, ...SOURCE_CHAIN_IDS];
101
+ const chainFolders = fs
102
+ .readdirSync(deploymentsPath, { withFileTypes: true })
103
+ .filter((dirent) => dirent.isDirectory())
104
+ .map((dirent) => dirent.name)
105
+ .filter((chainFolder) => {
106
+ const chainPath = path.join(deploymentsPath, chainFolder);
107
+ const chainId = getChainId(chainPath);
108
+ return chainId !== null && allowedChains.includes(chainId);
109
+ });
110
+ console.log(`Found ${chainFolders.length} valid chain folders:`, chainFolders.join(", "));
111
+ const baseSymbolMap = {};
112
+ for (const chainFolder of chainFolders) {
113
+ const chainPath = path.join(deploymentsPath, chainFolder);
114
+ const chainId = getChainId(chainPath);
115
+ if (!chainId) {
116
+ continue;
117
+ }
118
+ const files = fs.readdirSync(chainPath).filter((file) => file.endsWith(".json") && file !== ".chainId");
119
+ console.log(`\nProcessing ${chainFolder} (chain ID: ${chainId}):`);
120
+ for (const file of files) {
121
+ const filePath = path.join(chainPath, file);
122
+ const deployment = readTokenDeployment(filePath);
123
+ if (!deployment) {
124
+ continue;
125
+ }
126
+ const baseSymbol = extractTokenSymbol(file);
127
+ if (!baseSymbol) {
128
+ continue;
129
+ }
130
+ if (!baseSymbolMap[baseSymbol]) {
131
+ baseSymbolMap[baseSymbol] = {
132
+ baseSymbol,
133
+ deployments: [],
134
+ };
135
+ }
136
+ baseSymbolMap[baseSymbol].deployments.push({
137
+ chainId,
138
+ deployment,
139
+ filename: file,
140
+ });
141
+ console.log(` ✓ ${baseSymbol}: ${deployment.address}`);
142
+ }
143
+ }
144
+ const result = {
145
+ mainnets: {},
146
+ testnets: {},
147
+ };
148
+ for (const { baseSymbol, deployments } of Object.values(baseSymbolMap)) {
149
+ const settlementDeployment = deployments.find(({ chainId }) => SETTLEMENT_CHAIN_IDS_DEV.includes(chainId));
150
+ if (!settlementDeployment) {
151
+ console.error(`Warning: No settlement chain found for ${baseSymbol}`);
152
+ continue;
153
+ }
154
+ const settlementAddress = settlementDeployment.deployment.address;
155
+ const addressSuffix = settlementAddress.slice(-6);
156
+ const finalSymbol = baseSymbol.replace(">", `-${addressSuffix}>`);
157
+ const isTestnet = isTestnetChain(settlementDeployment.chainId);
158
+ const targetGroup = isTestnet ? result.testnets : result.mainnets;
159
+ targetGroup[finalSymbol] = {};
160
+ for (const { chainId, deployment } of deployments) {
161
+ targetGroup[finalSymbol][chainId] = {
162
+ address: deployment.address,
163
+ stargate: deployment.stargate,
164
+ };
165
+ }
166
+ }
167
+ return result;
168
+ }
169
+ function main() {
170
+ const args = process.argv.slice(2);
171
+ if (args.length === 0) {
172
+ console.error("Usage: tsx scripts/generate-platform-tokens.ts <gmxLayerZero-path>");
173
+ console.error("Example: tsx scripts/generate-platform-tokens.ts ../gmx-layerzero");
174
+ process.exit(1);
175
+ }
176
+ const gmxLayerZeroPath = path.resolve(args[0]);
177
+ if (!fs.existsSync(gmxLayerZeroPath)) {
178
+ console.error(`Error: Path does not exist: ${gmxLayerZeroPath}`);
179
+ process.exit(1);
180
+ }
181
+ console.log(`Scanning deployments in: ${gmxLayerZeroPath}\n`);
182
+ const platformTokens = generatePlatformTokens(gmxLayerZeroPath);
183
+ const outputPath = path.join(__dirname, "..", "src", "codegen", "platformTokens.json");
184
+ fs.writeFileSync(outputPath, JSON.stringify(platformTokens, null, 2) + "\n", "utf8");
185
+ console.log(`\n✓ Generated platform tokens JSON at: ${outputPath}`);
186
+ const totalTokenSymbols = new Set([...Object.keys(platformTokens.mainnets), ...Object.keys(platformTokens.testnets)])
187
+ .size;
188
+ console.log(`✓ Found ${totalTokenSymbols} token symbols`);
189
+ const totalChainEntries = [
190
+ ...Object.values(platformTokens.mainnets),
191
+ ...Object.values(platformTokens.testnets),
192
+ ].reduce((sum, tokenChains) => sum + Object.keys(tokenChains).length, 0);
193
+ console.log(`✓ Total chain entries: ${totalChainEntries}`);
194
+ }
195
+ main();
@@ -1,5 +1,5 @@
1
1
  const config = {
2
- schema: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
2
+ schema: "https://gmx.squids.live/gmx-synthetics-arbitrum@045a75/api/graphql",
3
3
  overwrite: true,
4
4
  debug: true,
5
5
  generates: {
@@ -1,5 +1,5 @@
1
- import { getContract } from "../../../../configs/contracts";
2
1
  import { Module } from "../base";
2
+ import { getContract } from "../../../../configs/contracts";
3
3
  export class Accounts extends Module {
4
4
  get govTokenAddress() {
5
5
  let govTokenAddress;
@@ -1,4 +1,5 @@
1
1
  import { zeroAddress } from "viem";
2
+ import { Module } from "../base";
2
3
  import { getContract } from "../../../../configs/contracts";
3
4
  import { USE_OPEN_INTEREST_IN_TOKENS_FOR_BALANCE } from "../../../../configs/dataStore";
4
5
  import { convertTokenAddress, getToken } from "../../../../configs/tokens";
@@ -6,7 +7,6 @@ import graphqlFetcher from "../../../../utils/graphqlFetcher";
6
7
  import { composeFullMarketsInfoData, composeRawMarketsInfoData, getMarketDivisor, getMarketFullName, } from "../../../../utils/markets";
7
8
  import { buildClaimableFundingDataRequest, buildMarketsConfigsRequest, buildMarketsValuesRequest, parseMarketsConfigsResponse, parseMarketsValuesResponse, } from "../../../../utils/markets/multicall";
8
9
  import { getByKey } from "../../../../utils/objects";
9
- import { Module } from "../base";
10
10
  export class Markets extends Module {
11
11
  async getClaimableFundingData() {
12
12
  const chainId = this.chainId;
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
+ import { GmxSdk } from "../..";
2
3
  import { arbitrumSdk, arbitrumSdkConfig } from "../../testUtil";
3
- import { GmxSdk } from "../../index";
4
4
  describe("Markets", () => {
5
5
  describe("getMarkets", () => {
6
6
  it("should be able to get markets data", { timeout: 90000 }, async () => {
@@ -1,15 +1,15 @@
1
+ import { Module } from "../base";
1
2
  import { getWrappedToken } from "../../../../configs/tokens";
2
3
  import { getByKey } from "../../../../utils/objects";
3
4
  import { getOrderInfo, isOrderForPositionByData, isVisibleOrder } from "../../../../utils/orders";
4
5
  import { OrderType } from "../../../../utils/orders/types";
5
- import { createDecreaseOrderTxn } from "./transactions/createDecreaseOrderTxn";
6
- import { createIncreaseOrderTxn } from "./transactions/createIncreaseOrderTxn";
7
- import { buildGetOrdersMulticall, getExecutionFeeAmountForEntry, matchByMarket, parseGetOrdersResponse } from "./utils";
8
- import { Module } from "../base";
9
6
  import { increaseOrderHelper, swap } from "./helpers";
10
7
  import { cancelOrdersTxn } from "./transactions/cancelOrdersTxn";
8
+ import { createDecreaseOrderTxn } from "./transactions/createDecreaseOrderTxn";
9
+ import { createIncreaseOrderTxn } from "./transactions/createIncreaseOrderTxn";
11
10
  import { createSwapOrderTxn } from "./transactions/createSwapOrderTxn";
12
11
  import { createWrapOrUnwrapTxn } from "./transactions/createWrapOrUnwrapTxn";
12
+ import { buildGetOrdersMulticall, getExecutionFeeAmountForEntry, matchByMarket, parseGetOrdersResponse } from "./utils";
13
13
  export class Orders extends Module {
14
14
  async getOrders({ account: _account, marketsInfoData, tokensData, orderTypesFilter = [], marketsDirectionsFilter = [], }) {
15
15
  const account = _account || this.account;
@@ -1,16 +1,13 @@
1
1
  import { zeroAddress, zeroHash } from "viem";
2
+ import { Module } from "../base";
2
3
  import { BOTANIX } from "../../../../configs/chains";
3
4
  import { getContract } from "../../../../configs/contracts";
4
5
  import { hashedPositionKey, MAX_AUTO_CANCEL_ORDERS_KEY, MIN_COLLATERAL_USD_KEY, MIN_POSITION_SIZE_USD_KEY, uiFeeFactorKey, } from "../../../../configs/dataStore";
5
- import { getPositionFee } from "../../../../utils/fees";
6
- import { getContractMarketPrices, getMarketIndexName, getMarketPoolName, getMaxAllowedLeverageByMinCollateralFactor, } from "../../../../utils/markets";
7
- import { basisPointsToFloat, getBasisPoints } from "../../../../utils/numbers";
6
+ import { getContractMarketPrices } from "../../../../utils/markets";
7
+ import { basisPointsToFloat } from "../../../../utils/numbers";
8
8
  import { getByKey } from "../../../../utils/objects";
9
- import { getEntryPrice, getLeverage, getLiquidationPrice, getNetPriceImpactDeltaUsdForDecrease, getPositionKey, getPositionNetValue, getPositionPendingFeesUsd, getPositionPnlAfterFees, getPositionPnlUsd, } from "../../../../utils/positions";
10
- import { getAcceptablePriceInfo, getMarkPrice } from "../../../../utils/prices";
9
+ import { getPositionInfo, getPositionKey } from "../../../../utils/positions";
11
10
  import { decodeReferralCode } from "../../../../utils/referrals";
12
- import { convertToTokenAmount, convertToUsd } from "../../../../utils/tokens";
13
- import { Module } from "../base";
14
11
  export class Positions extends Module {
15
12
  constructor() {
16
13
  super(...arguments);
@@ -375,10 +372,10 @@ export class Positions extends Module {
375
372
  };
376
373
  }
377
374
  async getPositionsInfo(p) {
378
- const { showPnlInLeverage, marketsInfoData, tokensData } = p;
375
+ const { showPnlInLeverage, marketsInfoData } = p;
379
376
  const { positionsData } = await this.getPositions({
380
377
  marketsData: marketsInfoData,
381
- tokensData,
378
+ tokensData: p.tokensData,
382
379
  });
383
380
  const { minCollateralUsd } = await this.getPositionsConstants();
384
381
  const uiFeeFactor = await this.getUiFeeFactorRequest();
@@ -389,156 +386,17 @@ export class Positions extends Module {
389
386
  const positionsInfoData = Object.keys(positionsData).reduce((acc, positionKey) => {
390
387
  const position = getByKey(positionsData, positionKey);
391
388
  const marketInfo = getByKey(marketsInfoData, position.marketAddress);
392
- const indexToken = marketInfo?.indexToken;
393
- const longToken = getByKey(tokensData, marketInfo?.longTokenAddress);
394
- const shortToken = getByKey(tokensData, marketInfo?.shortTokenAddress);
395
- const pnlToken = position.isLong ? marketInfo?.longToken : marketInfo?.shortToken;
396
- const collateralToken = getByKey(tokensData, position.collateralTokenAddress);
397
- if (!marketInfo || !indexToken || !pnlToken || !collateralToken || !longToken || !shortToken) {
389
+ if (!marketInfo) {
398
390
  return acc;
399
391
  }
400
- const markPrice = getMarkPrice({ prices: indexToken.prices, isLong: position.isLong, isIncrease: false });
401
- const collateralMinPrice = collateralToken.prices.minPrice;
402
- const entryPrice = getEntryPrice({
403
- sizeInTokens: position.sizeInTokens,
404
- sizeInUsd: position.sizeInUsd,
405
- indexToken,
406
- });
407
- const pendingFundingFeesUsd = convertToUsd(position.fundingFeeAmount, collateralToken.decimals, collateralToken.prices.minPrice);
408
- const pendingClaimableFundingFeesLongUsd = convertToUsd(position.claimableLongTokenAmount, marketInfo.longToken.decimals, marketInfo.longToken.prices.minPrice);
409
- const pendingClaimableFundingFeesShortUsd = convertToUsd(position.claimableShortTokenAmount, marketInfo.shortToken.decimals, marketInfo.shortToken.prices.minPrice);
410
- const pendingClaimableFundingFeesUsd = pendingClaimableFundingFeesLongUsd + pendingClaimableFundingFeesShortUsd;
411
- const totalPendingFeesUsd = getPositionPendingFeesUsd({
412
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
413
- pendingFundingFeesUsd,
414
- });
415
- const closeAcceptablePriceInfo = marketInfo
416
- ? getAcceptablePriceInfo({
417
- marketInfo,
418
- isIncrease: false,
419
- isLimit: false,
420
- isLong: position.isLong,
421
- indexPrice: getMarkPrice({ prices: indexToken.prices, isLong: position.isLong, isIncrease: false }),
422
- sizeDeltaUsd: position.sizeInUsd,
423
- })
424
- : undefined;
425
- const positionFeeInfo = getPositionFee(marketInfo, position.sizeInUsd, closeAcceptablePriceInfo?.balanceWasImproved ?? false, userReferralInfo, uiFeeFactor);
426
- const closingFeeUsd = positionFeeInfo.positionFeeUsd;
427
- const uiFeeUsd = positionFeeInfo.uiFeeUsd ?? 0n;
428
- const collateralUsd = convertToUsd(position.collateralAmount, collateralToken.decimals, collateralMinPrice);
429
- const remainingCollateralUsd = collateralUsd - totalPendingFeesUsd;
430
- const remainingCollateralAmount = convertToTokenAmount(remainingCollateralUsd, collateralToken.decimals, collateralMinPrice);
431
- const pnl = getPositionPnlUsd({
432
- marketInfo: marketInfo,
433
- sizeInUsd: position.sizeInUsd,
434
- sizeInTokens: position.sizeInTokens,
435
- markPrice,
436
- isLong: position.isLong,
437
- });
438
- const pnlPercentage = collateralUsd !== undefined && collateralUsd != 0n ? getBasisPoints(pnl, collateralUsd) : 0n;
439
- const netPriceImapctValues = marketInfo && closeAcceptablePriceInfo
440
- ? getNetPriceImpactDeltaUsdForDecrease({
441
- marketInfo,
442
- sizeInUsd: position.sizeInUsd,
443
- pendingImpactAmount: position.pendingImpactAmount,
444
- sizeDeltaUsd: position.sizeInUsd,
445
- priceImpactDeltaUsd: closeAcceptablePriceInfo.priceImpactDeltaUsd,
446
- })
447
- : undefined;
448
- const netValue = getPositionNetValue({
449
- collateralUsd: collateralUsd,
450
- pnl,
451
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
452
- pendingFundingFeesUsd: pendingFundingFeesUsd,
453
- closingFeeUsd,
454
- uiFeeUsd,
455
- totalPendingImpactDeltaUsd: netPriceImapctValues?.totalImpactDeltaUsd ?? 0n,
456
- priceImpactDiffUsd: netPriceImapctValues?.priceImpactDiffUsd ?? 0n,
457
- });
458
- const pnlAfterFees = getPositionPnlAfterFees({
459
- pnl,
460
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
461
- pendingFundingFeesUsd: pendingFundingFeesUsd,
462
- closingFeeUsd,
463
- uiFeeUsd,
464
- totalPendingImpactDeltaUsd: netPriceImapctValues?.totalImpactDeltaUsd ?? 0n,
465
- priceImpactDiffUsd: netPriceImapctValues?.priceImpactDiffUsd ?? 0n,
466
- });
467
- const pnlAfterFeesPercentage = collateralUsd != 0n ? getBasisPoints(pnlAfterFees, collateralUsd + closingFeeUsd) : 0n;
468
- const leverage = getLeverage({
469
- sizeInUsd: position.sizeInUsd,
470
- collateralUsd: collateralUsd,
471
- pnl: showPnlInLeverage ? pnl : undefined,
472
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
473
- pendingFundingFeesUsd: pendingFundingFeesUsd,
474
- });
475
- const leverageWithoutPnl = getLeverage({
476
- sizeInUsd: position.sizeInUsd,
477
- collateralUsd: collateralUsd,
478
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
479
- pendingFundingFeesUsd: pendingFundingFeesUsd,
480
- pnl: undefined,
481
- });
482
- const leverageWithPnl = getLeverage({
483
- sizeInUsd: position.sizeInUsd,
484
- collateralUsd: collateralUsd,
485
- pnl,
486
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
487
- pendingFundingFeesUsd: pendingFundingFeesUsd,
488
- });
489
- const maxAllowedLeverage = getMaxAllowedLeverageByMinCollateralFactor(marketInfo.minCollateralFactor);
490
- const hasLowCollateral = (leverage !== undefined && leverage > maxAllowedLeverage) || false;
491
- const liquidationPrice = getLiquidationPrice({
392
+ acc[positionKey] = getPositionInfo({
393
+ position,
492
394
  marketInfo,
493
- collateralToken,
494
- sizeInUsd: position.sizeInUsd,
495
- sizeInTokens: position.sizeInTokens,
496
- collateralUsd,
497
- collateralAmount: position.collateralAmount,
498
- pendingImpactAmount: position.pendingImpactAmount,
499
- userReferralInfo,
500
395
  minCollateralUsd,
501
- pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
502
- pendingFundingFeesUsd,
503
- isLong: position.isLong,
396
+ userReferralInfo,
397
+ showPnlInLeverage,
398
+ uiFeeFactor,
504
399
  });
505
- const indexName = getMarketIndexName({ indexToken, isSpotOnly: false });
506
- const poolName = getMarketPoolName({ longToken, shortToken });
507
- acc[positionKey] = {
508
- ...position,
509
- market: marketInfo,
510
- marketInfo,
511
- indexName,
512
- poolName,
513
- indexToken,
514
- collateralToken,
515
- pnlToken,
516
- longToken,
517
- shortToken,
518
- markPrice,
519
- entryPrice,
520
- liquidationPrice,
521
- collateralUsd,
522
- remainingCollateralUsd,
523
- remainingCollateralAmount,
524
- hasLowCollateral,
525
- leverage,
526
- leverageWithPnl,
527
- leverageWithoutPnl,
528
- pnl,
529
- pnlPercentage,
530
- pnlAfterFees,
531
- pnlAfterFeesPercentage,
532
- netValue,
533
- netPriceImapctDeltaUsd: netPriceImapctValues?.totalImpactDeltaUsd ?? 0n,
534
- priceImpactDiffUsd: netPriceImapctValues?.priceImpactDiffUsd ?? 0n,
535
- pendingImpactUsd: netPriceImapctValues?.proportionalPendingImpactDeltaUsd ?? 0n,
536
- closePriceImpactDeltaUsd: closeAcceptablePriceInfo?.priceImpactDeltaUsd ?? 0n,
537
- closingFeeUsd,
538
- uiFeeUsd,
539
- pendingFundingFeesUsd,
540
- pendingClaimableFundingFeesUsd,
541
- };
542
400
  return acc;
543
401
  }, {});
544
402
  return positionsInfoData;
@@ -1,7 +1,7 @@
1
+ import { Module } from "../base";
1
2
  import { getContract } from "../../../../configs/contracts";
2
3
  import { NATIVE_TOKEN_ADDRESS, getToken, getTokensMap, getV2Tokens, getWrappedToken } from "../../../../configs/tokens";
3
4
  import { parseContractPrice } from "../../../../utils/tokens";
4
- import { Module } from "../base";
5
5
  export class Tokens extends Module {
6
6
  constructor() {
7
7
  super(...arguments);
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { arbitrumSdk, arbitrumSdkConfig } from "../../testUtil";
3
2
  import { GmxSdk } from "../..";
3
+ import { arbitrumSdk, arbitrumSdkConfig } from "../../testUtil";
4
4
  describe("Tokens", () => {
5
5
  it("should be able to fetch tokens", { timeout: 90000 }, async () => {
6
6
  const response = await arbitrumSdk.oracle.getTokens();
@@ -1,4 +1,5 @@
1
1
  import merge from "lodash/merge";
2
+ import { Module } from "../base";
2
3
  import { getWrappedToken } from "../../../../configs/tokens";
3
4
  import graphqlFetcher from "../../../../utils/graphqlFetcher";
4
5
  import { buildFiltersBody } from "../../../../utils/indexers";
@@ -7,7 +8,6 @@ import { OrderType } from "../../../../utils/orders/types";
7
8
  import { getSwapPathOutputAddresses } from "../../../../utils/swap/swapStats";
8
9
  import { createRawTradeActionTransformer } from "../../../../utils/tradeHistory";
9
10
  import { TradeActionType } from "../../../../utils/tradeHistory/types";
10
- import { Module } from "../base";
11
11
  export class Trades extends Module {
12
12
  async getTradeHistory(p) {
13
13
  const account = this.account;
@@ -1,4 +1,5 @@
1
1
  import { withRetry } from "viem";
2
+ import { Module } from "../base";
2
3
  import { getExecutionFeeConfig, getGasPricePremium, getMaxPriorityFeePerGas, getViemChain, } from "../../../../configs/chains";
3
4
  import { getContract } from "../../../../configs/contracts";
4
5
  import { decreaseOrderGasLimitKey, depositGasLimitKey, ESTIMATED_GAS_FEE_BASE_AMOUNT_V2_1, ESTIMATED_GAS_FEE_MULTIPLIER_FACTOR, ESTIMATED_GAS_FEE_PER_ORACLE_PRICE, GELATO_RELAY_FEE_MULTIPLIER_FACTOR_KEY, GLV_DEPOSIT_GAS_LIMIT, GLV_PER_MARKET_GAS_LIMIT, GLV_WITHDRAWAL_GAS_LIMIT, increaseOrderGasLimitKey, shiftGasLimitKey, singleSwapGasLimitKey, swapOrderGasLimitKey, uiFeeFactorKey, withdrawalGasLimitKey, } from "../../../../configs/dataStore";
@@ -7,7 +8,6 @@ import { bigMath } from "../../../../utils/bigmath";
7
8
  import { estimateOrderOraclePriceCount } from "../../../../utils/fees/estimateOraclePriceCount";
8
9
  import { estimateExecuteDecreaseOrderGasLimit, estimateExecuteIncreaseOrderGasLimit, estimateExecuteSwapOrderGasLimit, getExecutionFee, } from "../../../../utils/fees/executionFee";
9
10
  import { getSwapCount } from "../../../../utils/trade";
10
- import { Module } from "../base";
11
11
  const DEFAULT_UI_FEE_RECEIVER_ACCOUNT = "0xff00000000000000000000000000000000000001";
12
12
  export class Utils extends Module {
13
13
  constructor() {
@@ -1,6 +1,8 @@
1
1
  import { getApiUrl } from "../../configs/api";
2
2
  import { HttpClient } from "../../utils/http/http";
3
3
  import { fetchApiMarketsInfo, fetchApiTokensData } from "../../utils/markets/api";
4
+ import { fetchApiOrders } from "../../utils/orders/api";
5
+ import { fetchApiPositionsInfo } from "../../utils/positions/api";
4
6
  export class GmxApiSdk {
5
7
  constructor({ chainId }) {
6
8
  this.ctx = {
@@ -14,4 +16,10 @@ export class GmxApiSdk {
14
16
  fetchTokensData() {
15
17
  return fetchApiTokensData(this.ctx);
16
18
  }
19
+ fetchPositionsInfo(params) {
20
+ return fetchApiPositionsInfo(this.ctx, params);
21
+ }
22
+ fetchOrders(params) {
23
+ return fetchApiOrders(this.ctx, params);
24
+ }
17
25
  }
@@ -0,0 +1,134 @@
1
+ {
2
+ "mainnets": {
3
+ "<GLV-WBTC-USDC-104b96>": {
4
+ "1": {
5
+ "address": "0x3c21894169D669C5f0767c1289E71Ec8d6132C0F",
6
+ "stargate": "0x3c21894169D669C5f0767c1289E71Ec8d6132C0F"
7
+ },
8
+ "56": {
9
+ "address": "0x3c21894169D669C5f0767c1289E71Ec8d6132C0F",
10
+ "stargate": "0x3c21894169D669C5f0767c1289E71Ec8d6132C0F"
11
+ },
12
+ "8453": {
13
+ "address": "0xbCB170fEDDa90cd7593f016DFdabA032Ca1F222b",
14
+ "stargate": "0xbCB170fEDDa90cd7593f016DFdabA032Ca1F222b"
15
+ },
16
+ "42161": {
17
+ "address": "0xdF03EEd325b82bC1d4Db8b49c30ecc9E05104b96",
18
+ "stargate": "0x27Ef981E6fcB274a6C5C75983725d265Fd3dCdac"
19
+ }
20
+ },
21
+ "<GLV-WETH-USDC-4279F9>": {
22
+ "1": {
23
+ "address": "0x0BC5aB50Fd581b34681A9be180179b1Ef0b238c7",
24
+ "stargate": "0x0BC5aB50Fd581b34681A9be180179b1Ef0b238c7"
25
+ },
26
+ "56": {
27
+ "address": "0x0BC5aB50Fd581b34681A9be180179b1Ef0b238c7",
28
+ "stargate": "0x0BC5aB50Fd581b34681A9be180179b1Ef0b238c7"
29
+ },
30
+ "8453": {
31
+ "address": "0x8c92eaE643040fF0Fb65B423433001c176cB0bb6",
32
+ "stargate": "0x8c92eaE643040fF0Fb65B423433001c176cB0bb6"
33
+ },
34
+ "42161": {
35
+ "address": "0x528A5bac7E746C9A509A1f4F6dF58A03d44279F9",
36
+ "stargate": "0x8c92eaE643040fF0Fb65B423433001c176cB0bb6"
37
+ }
38
+ },
39
+ "<GM-BTC-BTC-6b9A77>": {
40
+ "1": {
41
+ "address": "0x5Ece4d3F43D3BD8cBffc1d2CE851E7605D403D3C",
42
+ "stargate": "0x5Ece4d3F43D3BD8cBffc1d2CE851E7605D403D3C"
43
+ },
44
+ "56": {
45
+ "address": "0x2e6Bf9Bdd2A7872bDae170C13F34d64692f842C1",
46
+ "stargate": "0x2e6Bf9Bdd2A7872bDae170C13F34d64692f842C1"
47
+ },
48
+ "8453": {
49
+ "address": "0x5E922D32c7278f6c5621a016c03055c54C97D27b",
50
+ "stargate": "0x5E922D32c7278f6c5621a016c03055c54C97D27b"
51
+ },
52
+ "42161": {
53
+ "address": "0x7C11F78Ce78768518D743E81Fdfa2F860C6b9A77",
54
+ "stargate": "0x661E1faD17124471a59c37E9c4590BA809599f30"
55
+ }
56
+ },
57
+ "<GM-WBTC-USDC-170703>": {
58
+ "1": {
59
+ "address": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21",
60
+ "stargate": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21"
61
+ },
62
+ "56": {
63
+ "address": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21",
64
+ "stargate": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21"
65
+ },
66
+ "8453": {
67
+ "address": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21",
68
+ "stargate": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21"
69
+ },
70
+ "42161": {
71
+ "address": "0x47c031236e19d024b42f8AE6780E44A573170703",
72
+ "stargate": "0x91dd54AA8BA9Dfde8b956Cfb709a7c418f870e21"
73
+ }
74
+ },
75
+ "<GM-WETH-USDC-ee6336>": {
76
+ "1": {
77
+ "address": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7",
78
+ "stargate": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7"
79
+ },
80
+ "56": {
81
+ "address": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7",
82
+ "stargate": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7"
83
+ },
84
+ "8453": {
85
+ "address": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7",
86
+ "stargate": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7"
87
+ },
88
+ "42161": {
89
+ "address": "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
90
+ "stargate": "0xfcff5015627B8ce9CeAA7F5b38a6679F65fE39a7"
91
+ }
92
+ },
93
+ "<GM-WETH-WETH-2ac541>": {
94
+ "1": {
95
+ "address": "0x0B335e18Ab68Ccd2E8946A6E785D8bE65F413103",
96
+ "stargate": "0x0B335e18Ab68Ccd2E8946A6E785D8bE65F413103"
97
+ },
98
+ "56": {
99
+ "address": "0x5Ece4d3F43D3BD8cBffc1d2CE851E7605D403D3C",
100
+ "stargate": "0x5Ece4d3F43D3BD8cBffc1d2CE851E7605D403D3C"
101
+ },
102
+ "8453": {
103
+ "address": "0x47dFf0cbE239c02479C5944b9F4F3Ade8a212457",
104
+ "stargate": "0x47dFf0cbE239c02479C5944b9F4F3Ade8a212457"
105
+ },
106
+ "42161": {
107
+ "address": "0x450bb6774Dd8a756274E0ab4107953259d2ac541",
108
+ "stargate": "0x0110424A21D5DF818f4a789E5d9d9141a4E29A3C"
109
+ }
110
+ }
111
+ },
112
+ "testnets": {
113
+ "<GLV-WETH-USDC-SG-a9F854>": {
114
+ "421614": {
115
+ "address": "0xAb3567e55c205c62B141967145F37b7695a9F854",
116
+ "stargate": "0xD5BdEa6dC8E4B7429b72675386fC903DEf06599d"
117
+ },
118
+ "11155111": {
119
+ "address": "0xD5BdEa6dC8E4B7429b72675386fC903DEf06599d",
120
+ "stargate": "0xD5BdEa6dC8E4B7429b72675386fC903DEf06599d"
121
+ }
122
+ },
123
+ "<GM-WETH-USDC-SG-Ac0Bcc>": {
124
+ "421614": {
125
+ "address": "0xb6fC4C9eB02C35A134044526C62bb15014Ac0Bcc",
126
+ "stargate": "0xe4EBcAC4a2e6CBEE385eE407f7D5E278Bc07e11e"
127
+ },
128
+ "11155111": {
129
+ "address": "0xe4EBcAC4a2e6CBEE385eE407f7D5E278Bc07e11e",
130
+ "stargate": "0xe4EBcAC4a2e6CBEE385eE407f7D5E278Bc07e11e"
131
+ }
132
+ }
133
+ }
134
+ }