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