@gmx-io/sdk 0.1.0 → 0.1.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 (69) 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/modules/markets/index.js +2 -3
  24. package/build/src/modules/markets/markets.spec.js +0 -6
  25. package/build/src/modules/markets/types.d.ts +8 -0
  26. package/build/src/modules/oracle.js +1 -16
  27. package/build/src/modules/orders/orders.d.ts +2 -1
  28. package/build/src/modules/orders/orders.js +4 -3
  29. package/build/src/modules/orders/transactions/cancelOrdersTxn.js +1 -1
  30. package/build/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
  31. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -0
  32. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +3 -1
  33. package/build/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
  34. package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
  35. package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +3 -1
  36. package/build/src/modules/orders/transactions/updateOrderTxn.js +7 -5
  37. package/build/src/modules/orders/utils.js +1 -1
  38. package/build/src/modules/positions/positions.d.ts +1 -1
  39. package/build/src/modules/positions/positions.js +10 -86
  40. package/build/src/modules/trades/trades.js +1 -2
  41. package/build/src/modules/utils/utils.js +3 -8
  42. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +760 -0
  43. package/build/src/prebuilt/hashedMarketConfigKeys.json +1050 -0
  44. package/build/src/prebuilt/hashedMarketValuesKeys.json +315 -0
  45. package/build/src/prebuilt/index.d.ts +8 -2
  46. package/build/src/prebuilt/index.js +3 -1
  47. package/build/src/prebuilt/index.ts +19 -2
  48. package/build/src/types/amounts.d.ts +1 -1
  49. package/build/src/types/fees.d.ts +1 -2
  50. package/build/src/types/orders.d.ts +2 -2
  51. package/build/src/types/positions.d.ts +2 -2
  52. package/build/src/types/sdk.d.ts +4 -4
  53. package/build/src/types/syntheticsEvents.d.ts +3 -3
  54. package/build/src/types/tokens.d.ts +4 -0
  55. package/build/src/types/trade.d.ts +1 -1
  56. package/build/src/utils/fees/executionFee.d.ts +1 -5
  57. package/build/src/utils/fees/executionFee.js +3 -12
  58. package/build/src/utils/objects.d.ts +0 -5
  59. package/build/src/utils/objects.js +0 -17
  60. package/build/src/utils/orders.js +0 -8
  61. package/build/src/utils/simulateExecuteOrder.js +8 -21
  62. package/build/src/utils/testUtil.d.ts +2 -3
  63. package/build/src/utils/testUtil.js +2 -3
  64. package/build/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +1 -1
  66. package/build/src/configs/subgraph.d.ts +0 -3
  67. package/build/src/configs/subgraph.js +0 -3
  68. package/build/src/utils/slidingWindowFallbackSwitcher.d.ts +0 -24
  69. package/build/src/utils/slidingWindowFallbackSwitcher.js +0 -40
@@ -1,10 +1,8 @@
1
1
  import { decodeErrorResult, encodeFunctionData, withRetry } from "viem";
2
2
  import CustomErrors from "../abis/CustomErrors.json";
3
- import DataStore from "../abis/DataStore.json";
4
3
  import ExchangeRouter from "../abis/ExchangeRouter.json";
5
4
  import Multicall from "../abis/Multicall.json";
6
5
  import { getContract } from "../configs/contracts";
7
- import { NONCE_KEY, orderKey } from "../configs/dataStore";
8
6
  import { convertTokenAddress } from "../configs/tokens";
9
7
  import { convertToContractPrice, getTokenData } from "./tokens";
10
8
  import { extractError } from "./contracts";
@@ -15,26 +13,15 @@ export async function simulateExecuteOrder(sdk, p) {
15
13
  if (!account) {
16
14
  throw new Error("Account is not defined");
17
15
  }
18
- const dataStoreAddress = getContract(chainId, "DataStore");
19
16
  const multicallAddress = getContract(chainId, "Multicall");
20
17
  const exchangeRouterAddress = getContract(chainId, "ExchangeRouter");
21
- const [nonce, blockTimestamp] = await Promise.all([
22
- client.readContract({
23
- address: dataStoreAddress,
24
- abi: DataStore.abi,
25
- functionName: "getUint",
26
- args: [NONCE_KEY],
27
- }),
28
- client.readContract({
29
- address: multicallAddress,
30
- abi: Multicall.abi,
31
- functionName: "getCurrentBlockTimestamp",
32
- args: [],
33
- }),
34
- ]);
18
+ const blockTimestamp = await client.readContract({
19
+ address: multicallAddress,
20
+ abi: Multicall.abi,
21
+ functionName: "getCurrentBlockTimestamp",
22
+ args: [],
23
+ });
35
24
  const blockNumber = await client.getBlockNumber();
36
- const nextNonce = nonce + 1n;
37
- const nextKey = orderKey(dataStoreAddress, nextNonce);
38
25
  const { primaryTokens, primaryPrices } = getSimulationPrices(chainId, p.tokensData, p.primaryPriceOverrides);
39
26
  const priceTimestamp = blockTimestamp + 10n;
40
27
  const simulationPriceParams = {
@@ -49,8 +36,8 @@ export async function simulateExecuteOrder(sdk, p) {
49
36
  let encodedFunctionData;
50
37
  encodedFunctionData = encodeFunctionData({
51
38
  abi: routerAbi,
52
- functionName: "simulateExecuteOrder",
53
- args: [nextKey, simulationPriceParams],
39
+ functionName: "simulateExecuteLatestOrder",
40
+ args: [simulationPriceParams],
54
41
  });
55
42
  simulationPayloadData.push(encodedFunctionData);
56
43
  try {
@@ -568,8 +568,7 @@ export declare const arbitrumSdkConfig: {
568
568
  watchEvent: <const TAbiEvent_2 extends import("abitype").AbiEvent | undefined = undefined, const TAbiEvents_2 extends readonly unknown[] | readonly import("abitype").AbiEvent[] | undefined = TAbiEvent_2 extends import("abitype").AbiEvent ? [TAbiEvent_2] : undefined, TStrict_6 extends boolean | undefined = undefined>(args: import("viem").WatchEventParameters<TAbiEvent_2, TAbiEvents_2, TStrict_6, import("viem").HttpTransport>) => import("viem").WatchEventReturnType;
569
569
  watchPendingTransactions: (args: import("viem").WatchPendingTransactionsParameters<import("viem").HttpTransport>) => import("viem").WatchPendingTransactionsReturnType;
570
570
  } & import("viem").TestActions>;
571
- subgraph: {
572
- subsquid: string;
573
- };
571
+ subsquidUrl: string;
572
+ subgraphUrl: string;
574
573
  };
575
574
  export declare const arbitrumSdk: GmxSdk;
@@ -14,8 +14,7 @@ export const arbitrumSdkConfig = {
14
14
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
15
15
  rpcUrl: "https://arb1.arbitrum.io/rpc",
16
16
  walletClient: client,
17
- subgraph: {
18
- subsquid: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql",
19
- },
17
+ subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql",
18
+ subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api",
20
19
  };
21
20
  export const arbitrumSdk = new GmxSdk(arbitrumSdkConfig);