@gmx-io/sdk 0.0.9 → 0.1.1-alpha-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +25 -7
  2. package/build/scripts/prebuild/index.js +2 -0
  3. package/build/scripts/prebuild/prebuildKinkModelMarketRatesKeys.d.ts +1 -0
  4. package/build/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +44 -0
  5. package/build/src/abis/ExchangeRouter.json +203 -0
  6. package/build/src/abis/GlvReader.json +0 -10
  7. package/build/src/abis/GlvRouter.json +96 -2
  8. package/build/src/abis/RewardRouter.json +323 -68
  9. package/build/src/abis/SubaccountRouter.json +10 -0
  10. package/build/src/abis/SyntheticsReader.json +196 -64
  11. package/build/src/configs/batch.js +1 -13
  12. package/build/src/configs/chains.d.ts +0 -1
  13. package/build/src/configs/chains.js +1 -7
  14. package/build/src/configs/contracts.d.ts +2 -1
  15. package/build/src/configs/contracts.js +27 -66
  16. package/build/src/configs/dataStore.d.ts +4 -1
  17. package/build/src/configs/dataStore.js +5 -2
  18. package/build/src/configs/factors.d.ts +0 -12
  19. package/build/src/configs/factors.js +0 -12
  20. package/build/src/configs/markets.js +147 -0
  21. package/build/src/configs/tokens.d.ts +5 -2
  22. package/build/src/configs/tokens.js +297 -221
  23. package/build/src/index.d.ts +3 -17
  24. package/build/src/index.js +5 -182
  25. package/build/src/modules/markets/index.js +2 -3
  26. package/build/src/modules/markets/markets.spec.js +1 -7
  27. package/build/src/modules/markets/types.d.ts +8 -0
  28. package/build/src/modules/oracle.js +1 -16
  29. package/build/src/modules/orders/orders.d.ts +2 -1
  30. package/build/src/modules/orders/orders.js +9 -8
  31. package/build/src/modules/orders/transactions/cancelOrdersTxn.js +1 -1
  32. package/build/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
  33. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -0
  34. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +3 -1
  35. package/build/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
  36. package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
  37. package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +3 -1
  38. package/build/src/modules/orders/transactions/updateOrderTxn.js +7 -5
  39. package/build/src/modules/orders/utils.js +1 -1
  40. package/build/src/modules/positions/positions.d.ts +1 -1
  41. package/build/src/modules/positions/positions.js +10 -86
  42. package/build/src/modules/trades/trades.js +1 -2
  43. package/build/src/modules/utils/utils.d.ts +20 -0
  44. package/build/src/modules/utils/utils.js +183 -0
  45. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +760 -0
  46. package/build/src/prebuilt/hashedMarketConfigKeys.json +1050 -0
  47. package/build/src/prebuilt/hashedMarketValuesKeys.json +315 -0
  48. package/build/src/prebuilt/index.d.ts +8 -2
  49. package/build/src/prebuilt/index.js +3 -1
  50. package/build/src/prebuilt/index.ts +19 -2
  51. package/build/src/types/amounts.d.ts +1 -1
  52. package/build/src/types/fees.d.ts +1 -2
  53. package/build/src/types/orders.d.ts +2 -2
  54. package/build/src/types/positions.d.ts +2 -2
  55. package/build/src/types/sdk.d.ts +4 -4
  56. package/build/src/types/syntheticsEvents.d.ts +3 -3
  57. package/build/src/types/tokens.d.ts +4 -0
  58. package/build/src/types/trade.d.ts +1 -1
  59. package/build/src/utils/fees/executionFee.d.ts +1 -5
  60. package/build/src/utils/fees/executionFee.js +3 -12
  61. package/build/src/utils/objects.d.ts +0 -5
  62. package/build/src/utils/objects.js +0 -17
  63. package/build/src/utils/orders.js +0 -8
  64. package/build/src/utils/simulateExecuteOrder.js +8 -21
  65. package/build/src/utils/testUtil.d.ts +2 -3
  66. package/build/src/utils/testUtil.js +2 -3
  67. package/build/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +3 -2
  69. package/build/src/configs/subgraph.d.ts +0 -3
  70. package/build/src/configs/subgraph.js +0 -3
  71. package/build/src/utils/slidingWindowFallbackSwitcher.d.ts +0 -24
  72. package/build/src/utils/slidingWindowFallbackSwitcher.js +0 -40
package/README.md CHANGED
@@ -18,9 +18,8 @@ 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
- subgraph: {
22
- subsquid: "https://gmx.squids.live/gmx-synthetics-arbitrum/graphql",
23
- },
21
+ subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum/graphql",
22
+ subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api",
24
23
  });
25
24
 
26
25
  const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();
@@ -74,9 +73,7 @@ interface GmxSdkConfig {
74
73
  chainId: number;
75
74
  rpcUrl: string;
76
75
  oracleUrl: string;
77
- subgraph: {
78
- subsquid?: string;
79
- };
76
+ subsquidUrl?: string;
80
77
  account?: string;
81
78
  publicClient: PublicClient;
82
79
  walletClient: WalletClient;
@@ -151,7 +148,28 @@ sdk.orders.createIncreaseOrder({
151
148
  marketInfo,
152
149
  indexToken: marketInfo.indexToken,
153
150
  increaseAmounts: {
154
- // amounts for position
151
+ initialCollateralAmount: 3000000n,
152
+ initialCollateralUsd: 2999578868393486100000000000000n,
153
+ collateralDeltaAmount: 2997003n,
154
+ collateralDeltaUsd: 2996582289103961007386100000000n,
155
+ indexTokenAmount: 1919549334876037n,
156
+ sizeDeltaUsd: 5993158579050185227800000000000n,
157
+ sizeDeltaInTokens: 1919536061202302n,
158
+ estimatedLeverage: 20000n,
159
+ indexPrice: 3122169600000000000000000000000000n,
160
+ initialCollateralPrice: 999859622797828700000000000000n,
161
+ collateralPrice: 999859622797828700000000000000n,
162
+ triggerPrice: 0n,
163
+ acceptablePrice: 3122191190655414690893787784152819n,
164
+ acceptablePriceDeltaBps: 0n,
165
+ positionFeeUsd: 2996579289525092613900000000n,
166
+ swapPathStats: undefined,
167
+ uiFeeUsd: 0n,
168
+ swapUiFeeUsd: 0n,
169
+ feeDiscountUsd: 0n,
170
+ borrowingFeeUsd: 0n,
171
+ fundingFeeUsd: 0n,
172
+ positionPriceImpactDeltaUsd: 41444328240807630917223064n,
155
173
  },
156
174
  });
157
175
  ```
@@ -1,7 +1,9 @@
1
1
  import { resolve } from "path";
2
2
  import { prebuildMarketValuesKeys } from "./prebuildMarketValuesKeys";
3
3
  import { prebuildMarketConfigKeys } from "./prebuildMarketConfigKeys";
4
+ import { prebuildKinkModelMarketRatesKeys } from "./prebuildKinkModelMarketRatesKeys";
4
5
  /* eslint-disable-next-line no-restricted-globals */
5
6
  const OUTPUT_DIR = resolve(process.cwd(), "src/prebuilt");
6
7
  prebuildMarketValuesKeys(OUTPUT_DIR);
7
8
  prebuildMarketConfigKeys(OUTPUT_DIR);
9
+ prebuildKinkModelMarketRatesKeys(OUTPUT_DIR);
@@ -0,0 +1 @@
1
+ export declare function prebuildKinkModelMarketRatesKeys(outputDir: string): {};
@@ -0,0 +1,44 @@
1
+ import fs from "fs";
2
+ import { resolve } from "path";
3
+ import entries from "lodash/entries";
4
+ import { hashDataMap } from "../../src/utils/hash";
5
+ import { OPTIMAL_USAGE_FACTOR, BASE_BORROWING_FACTOR, ABOVE_OPTIMAL_USAGE_BORROWING_FACTOR, } from "../../src/configs/dataStore";
6
+ import { MARKETS } from "../../src/configs/markets";
7
+ export function prebuildKinkModelMarketRatesKeys(outputDir) {
8
+ const chainMarketKeys = entries(MARKETS).reduce((chainsAcc, [chainId, markets]) => {
9
+ const chainMarkets = entries(markets).reduce((marketsAcc, [marketAddress]) => {
10
+ const marketKeys = hashDataMap({
11
+ optimalUsageFactorLong: [
12
+ ["bytes32", "address", "bool"],
13
+ [OPTIMAL_USAGE_FACTOR, marketAddress, true],
14
+ ],
15
+ optimalUsageFactorShort: [
16
+ ["bytes32", "address", "bool"],
17
+ [OPTIMAL_USAGE_FACTOR, marketAddress, false],
18
+ ],
19
+ baseBorrowingFactorLong: [
20
+ ["bytes32", "address", "bool"],
21
+ [BASE_BORROWING_FACTOR, marketAddress, true],
22
+ ],
23
+ baseBorrowingFactorShort: [
24
+ ["bytes32", "address", "bool"],
25
+ [BASE_BORROWING_FACTOR, marketAddress, false],
26
+ ],
27
+ aboveOptimalUsageBorrowingFactorLong: [
28
+ ["bytes32", "address", "bool"],
29
+ [ABOVE_OPTIMAL_USAGE_BORROWING_FACTOR, marketAddress, true],
30
+ ],
31
+ aboveOptimalUsageBorrowingFactorShort: [
32
+ ["bytes32", "address", "bool"],
33
+ [ABOVE_OPTIMAL_USAGE_BORROWING_FACTOR, marketAddress, false],
34
+ ],
35
+ });
36
+ marketsAcc[marketAddress] = marketKeys;
37
+ return marketsAcc;
38
+ }, {});
39
+ chainsAcc[chainId] = chainMarkets;
40
+ return chainsAcc;
41
+ }, {});
42
+ fs.writeFileSync(resolve(outputDir, "hashedKinkModelMarketRatesKeys.json"), JSON.stringify(chainMarketKeys, null, 2));
43
+ return chainMarketKeys;
44
+ }
@@ -689,6 +689,11 @@
689
689
  "internalType": "uint256",
690
690
  "name": "minOutputAmount",
691
691
  "type": "uint256"
692
+ },
693
+ {
694
+ "internalType": "uint256",
695
+ "name": "validFromTime",
696
+ "type": "uint256"
692
697
  }
693
698
  ],
694
699
  "internalType": "struct IBaseOrderUtils.CreateOrderParamsNumbers",
@@ -1264,6 +1269,199 @@
1264
1269
  "stateMutability": "payable",
1265
1270
  "type": "function"
1266
1271
  },
1272
+ {
1273
+ "inputs": [
1274
+ {
1275
+ "components": [
1276
+ {
1277
+ "internalType": "address[]",
1278
+ "name": "primaryTokens",
1279
+ "type": "address[]"
1280
+ },
1281
+ {
1282
+ "components": [
1283
+ {
1284
+ "internalType": "uint256",
1285
+ "name": "min",
1286
+ "type": "uint256"
1287
+ },
1288
+ {
1289
+ "internalType": "uint256",
1290
+ "name": "max",
1291
+ "type": "uint256"
1292
+ }
1293
+ ],
1294
+ "internalType": "struct Price.Props[]",
1295
+ "name": "primaryPrices",
1296
+ "type": "tuple[]"
1297
+ },
1298
+ {
1299
+ "internalType": "uint256",
1300
+ "name": "minTimestamp",
1301
+ "type": "uint256"
1302
+ },
1303
+ {
1304
+ "internalType": "uint256",
1305
+ "name": "maxTimestamp",
1306
+ "type": "uint256"
1307
+ }
1308
+ ],
1309
+ "internalType": "struct OracleUtils.SimulatePricesParams",
1310
+ "name": "simulatedOracleParams",
1311
+ "type": "tuple"
1312
+ }
1313
+ ],
1314
+ "name": "simulateExecuteLatestDeposit",
1315
+ "outputs": [],
1316
+ "stateMutability": "payable",
1317
+ "type": "function"
1318
+ },
1319
+ {
1320
+ "inputs": [
1321
+ {
1322
+ "components": [
1323
+ {
1324
+ "internalType": "address[]",
1325
+ "name": "primaryTokens",
1326
+ "type": "address[]"
1327
+ },
1328
+ {
1329
+ "components": [
1330
+ {
1331
+ "internalType": "uint256",
1332
+ "name": "min",
1333
+ "type": "uint256"
1334
+ },
1335
+ {
1336
+ "internalType": "uint256",
1337
+ "name": "max",
1338
+ "type": "uint256"
1339
+ }
1340
+ ],
1341
+ "internalType": "struct Price.Props[]",
1342
+ "name": "primaryPrices",
1343
+ "type": "tuple[]"
1344
+ },
1345
+ {
1346
+ "internalType": "uint256",
1347
+ "name": "minTimestamp",
1348
+ "type": "uint256"
1349
+ },
1350
+ {
1351
+ "internalType": "uint256",
1352
+ "name": "maxTimestamp",
1353
+ "type": "uint256"
1354
+ }
1355
+ ],
1356
+ "internalType": "struct OracleUtils.SimulatePricesParams",
1357
+ "name": "simulatedOracleParams",
1358
+ "type": "tuple"
1359
+ }
1360
+ ],
1361
+ "name": "simulateExecuteLatestOrder",
1362
+ "outputs": [],
1363
+ "stateMutability": "payable",
1364
+ "type": "function"
1365
+ },
1366
+ {
1367
+ "inputs": [
1368
+ {
1369
+ "components": [
1370
+ {
1371
+ "internalType": "address[]",
1372
+ "name": "primaryTokens",
1373
+ "type": "address[]"
1374
+ },
1375
+ {
1376
+ "components": [
1377
+ {
1378
+ "internalType": "uint256",
1379
+ "name": "min",
1380
+ "type": "uint256"
1381
+ },
1382
+ {
1383
+ "internalType": "uint256",
1384
+ "name": "max",
1385
+ "type": "uint256"
1386
+ }
1387
+ ],
1388
+ "internalType": "struct Price.Props[]",
1389
+ "name": "primaryPrices",
1390
+ "type": "tuple[]"
1391
+ },
1392
+ {
1393
+ "internalType": "uint256",
1394
+ "name": "minTimestamp",
1395
+ "type": "uint256"
1396
+ },
1397
+ {
1398
+ "internalType": "uint256",
1399
+ "name": "maxTimestamp",
1400
+ "type": "uint256"
1401
+ }
1402
+ ],
1403
+ "internalType": "struct OracleUtils.SimulatePricesParams",
1404
+ "name": "simulatedOracleParams",
1405
+ "type": "tuple"
1406
+ }
1407
+ ],
1408
+ "name": "simulateExecuteLatestShift",
1409
+ "outputs": [],
1410
+ "stateMutability": "payable",
1411
+ "type": "function"
1412
+ },
1413
+ {
1414
+ "inputs": [
1415
+ {
1416
+ "components": [
1417
+ {
1418
+ "internalType": "address[]",
1419
+ "name": "primaryTokens",
1420
+ "type": "address[]"
1421
+ },
1422
+ {
1423
+ "components": [
1424
+ {
1425
+ "internalType": "uint256",
1426
+ "name": "min",
1427
+ "type": "uint256"
1428
+ },
1429
+ {
1430
+ "internalType": "uint256",
1431
+ "name": "max",
1432
+ "type": "uint256"
1433
+ }
1434
+ ],
1435
+ "internalType": "struct Price.Props[]",
1436
+ "name": "primaryPrices",
1437
+ "type": "tuple[]"
1438
+ },
1439
+ {
1440
+ "internalType": "uint256",
1441
+ "name": "minTimestamp",
1442
+ "type": "uint256"
1443
+ },
1444
+ {
1445
+ "internalType": "uint256",
1446
+ "name": "maxTimestamp",
1447
+ "type": "uint256"
1448
+ }
1449
+ ],
1450
+ "internalType": "struct OracleUtils.SimulatePricesParams",
1451
+ "name": "simulatedOracleParams",
1452
+ "type": "tuple"
1453
+ },
1454
+ {
1455
+ "internalType": "enum ISwapPricingUtils.SwapPricingType",
1456
+ "name": "swapPricingType",
1457
+ "type": "uint8"
1458
+ }
1459
+ ],
1460
+ "name": "simulateExecuteLatestWithdrawal",
1461
+ "outputs": [],
1462
+ "stateMutability": "payable",
1463
+ "type": "function"
1464
+ },
1267
1465
  {
1268
1466
  "inputs": [
1269
1467
  {
@@ -1452,6 +1650,11 @@
1452
1650
  "name": "minOutputAmount",
1453
1651
  "type": "uint256"
1454
1652
  },
1653
+ {
1654
+ "internalType": "uint256",
1655
+ "name": "validFromTime",
1656
+ "type": "uint256"
1657
+ },
1455
1658
  {
1456
1659
  "internalType": "bool",
1457
1660
  "name": "autoCancel",
@@ -845,11 +845,6 @@
845
845
  "internalType": "uint256",
846
846
  "name": "updatedAtTime",
847
847
  "type": "uint256"
848
- },
849
- {
850
- "internalType": "uint256",
851
- "name": "executionFee",
852
- "type": "uint256"
853
848
  }
854
849
  ],
855
850
  "internalType": "struct GlvShift.Numbers",
@@ -925,11 +920,6 @@
925
920
  "internalType": "uint256",
926
921
  "name": "updatedAtTime",
927
922
  "type": "uint256"
928
- },
929
- {
930
- "internalType": "uint256",
931
- "name": "executionFee",
932
- "type": "uint256"
933
923
  }
934
924
  ],
935
925
  "internalType": "struct GlvShift.Numbers",
@@ -549,7 +549,7 @@
549
549
  ],
550
550
  "name": "simulateExecuteGlvDeposit",
551
551
  "outputs": [],
552
- "stateMutability": "nonpayable",
552
+ "stateMutability": "payable",
553
553
  "type": "function"
554
554
  },
555
555
  {
@@ -601,7 +601,101 @@
601
601
  ],
602
602
  "name": "simulateExecuteGlvWithdrawal",
603
603
  "outputs": [],
604
- "stateMutability": "nonpayable",
604
+ "stateMutability": "payable",
605
+ "type": "function"
606
+ },
607
+ {
608
+ "inputs": [
609
+ {
610
+ "components": [
611
+ {
612
+ "internalType": "address[]",
613
+ "name": "primaryTokens",
614
+ "type": "address[]"
615
+ },
616
+ {
617
+ "components": [
618
+ {
619
+ "internalType": "uint256",
620
+ "name": "min",
621
+ "type": "uint256"
622
+ },
623
+ {
624
+ "internalType": "uint256",
625
+ "name": "max",
626
+ "type": "uint256"
627
+ }
628
+ ],
629
+ "internalType": "struct Price.Props[]",
630
+ "name": "primaryPrices",
631
+ "type": "tuple[]"
632
+ },
633
+ {
634
+ "internalType": "uint256",
635
+ "name": "minTimestamp",
636
+ "type": "uint256"
637
+ },
638
+ {
639
+ "internalType": "uint256",
640
+ "name": "maxTimestamp",
641
+ "type": "uint256"
642
+ }
643
+ ],
644
+ "internalType": "struct OracleUtils.SimulatePricesParams",
645
+ "name": "simulatedOracleParams",
646
+ "type": "tuple"
647
+ }
648
+ ],
649
+ "name": "simulateExecuteLatestGlvDeposit",
650
+ "outputs": [],
651
+ "stateMutability": "payable",
652
+ "type": "function"
653
+ },
654
+ {
655
+ "inputs": [
656
+ {
657
+ "components": [
658
+ {
659
+ "internalType": "address[]",
660
+ "name": "primaryTokens",
661
+ "type": "address[]"
662
+ },
663
+ {
664
+ "components": [
665
+ {
666
+ "internalType": "uint256",
667
+ "name": "min",
668
+ "type": "uint256"
669
+ },
670
+ {
671
+ "internalType": "uint256",
672
+ "name": "max",
673
+ "type": "uint256"
674
+ }
675
+ ],
676
+ "internalType": "struct Price.Props[]",
677
+ "name": "primaryPrices",
678
+ "type": "tuple[]"
679
+ },
680
+ {
681
+ "internalType": "uint256",
682
+ "name": "minTimestamp",
683
+ "type": "uint256"
684
+ },
685
+ {
686
+ "internalType": "uint256",
687
+ "name": "maxTimestamp",
688
+ "type": "uint256"
689
+ }
690
+ ],
691
+ "internalType": "struct OracleUtils.SimulatePricesParams",
692
+ "name": "simulatedOracleParams",
693
+ "type": "tuple"
694
+ }
695
+ ],
696
+ "name": "simulateExecuteLatestGlvWithdrawal",
697
+ "outputs": [],
698
+ "stateMutability": "payable",
605
699
  "type": "function"
606
700
  },
607
701
  {