@gmx-io/sdk 1.1.0 → 1.1.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.
@@ -21,9 +21,9 @@ function getMarketIndexName(p) {
21
21
  return `${prefix}${firstToken.baseSymbol || firstToken.symbol}/USD`;
22
22
  }
23
23
  exports.getMarketIndexName = getMarketIndexName;
24
- function getMarketPoolName(p) {
24
+ function getMarketPoolName(p, separator = "-") {
25
25
  const { longToken, shortToken } = p;
26
- return `${longToken.symbol}-${shortToken.symbol}`;
26
+ return `${longToken.symbol}${separator}${shortToken.symbol}`;
27
27
  }
28
28
  exports.getMarketPoolName = getMarketPoolName;
29
29
  function getContractMarketPrices(tokensData, market) {
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.bigNumberify = exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.formatFactor = exports.formatBalanceAmountWithUsd = exports.formatBalanceAmount = exports.formatAmountHuman = exports.formatPercentageDisplay = exports.formatUsdPrice = exports.formatRatePercentage = exports.formatTokenAmountWithUsd = exports.formatTokenAmount = exports.formatPercentage = exports.formatDeltaUsd = exports.formatUsd = exports.adjustForDecimals = exports.bigintToNumber = exports.trimZeroDecimals = exports.numberToBigint = exports.applyFactor = exports.roundUpMagnitudeDivision = exports.getBasisPoints = exports.basisPointsToFloat = exports.expandDecimals = exports.TRIGGER_PREFIX_BELOW = exports.TRIGGER_PREFIX_ABOVE = exports.PERCENT_PRECISION_DECIMALS = exports.MaxUint256 = exports.BN_NEGATIVE_ONE = exports.BN_ONE = exports.BN_ZERO = exports.PRECISION = exports.PRECISION_DECIMALS = exports.BASIS_POINTS_DIVISOR_BIGINT = exports.BASIS_POINTS_DIVISOR = exports.USD_DECIMALS = void 0;
4
- exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = void 0;
3
+ exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.bigNumberify = exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.formatFactor = exports.formatBalanceAmountWithUsd = exports.formatBalanceAmount = exports.formatAmountHuman = exports.formatPercentageDisplay = exports.formatUsdPrice = exports.formatRatePercentage = exports.formatTokenAmountWithUsd = exports.formatTokenAmount = exports.formatPercentage = exports.formatDeltaUsd = exports.formatUsd = exports.adjustForDecimals = exports.bigintToNumber = exports.trimZeroDecimals = exports.numberToBigint = exports.applyFactor = exports.roundUpMagnitudeDivision = exports.getBasisPoints = exports.basisPointsToFloat = exports.expandDecimals = exports.TRIGGER_PREFIX_BELOW = exports.TRIGGER_PREFIX_ABOVE = exports.PERCENT_PRECISION_DECIMALS = exports.MaxUint256 = exports.BN_NEGATIVE_ONE = exports.BN_ONE = exports.BN_ZERO = exports.PRECISION = exports.PRECISION_DECIMALS = exports.BASIS_POINTS_DECIMALS = exports.BASIS_POINTS_DIVISOR_BIGINT = exports.BASIS_POINTS_DIVISOR = exports.USD_DECIMALS = void 0;
4
+ exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = void 0;
5
5
  const viem_1 = require("viem");
6
6
  const bigmath_1 = require("./bigmath");
7
7
  exports.USD_DECIMALS = 30;
8
8
  exports.BASIS_POINTS_DIVISOR = 10000;
9
9
  exports.BASIS_POINTS_DIVISOR_BIGINT = 10000n;
10
+ exports.BASIS_POINTS_DECIMALS = 4;
10
11
  exports.PRECISION_DECIMALS = 30;
11
12
  exports.PRECISION = expandDecimals(1, exports.PRECISION_DECIMALS);
12
13
  exports.BN_ZERO = 0n;
@@ -41,8 +41,8 @@ function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensDa
41
41
  initialCollateralToken,
42
42
  timestamp: rawAction.timestamp,
43
43
  transaction: rawAction.transaction,
44
- reason: rawAction.reason,
45
- reasonBytes: rawAction.reasonBytes,
44
+ reason: rawAction.reason ?? undefined,
45
+ reasonBytes: rawAction.reasonBytes ?? undefined,
46
46
  twapParams: rawAction.twapGroupId && rawAction.numberOfParts
47
47
  ? {
48
48
  twapGroupId: rawAction.twapGroupId,
@@ -115,8 +115,8 @@ function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensDa
115
115
  borrowingFeeAmount: rawAction.borrowingFeeAmount ? BigInt(rawAction.borrowingFeeAmount) : undefined,
116
116
  fundingFeeAmount: rawAction.fundingFeeAmount ? BigInt(rawAction.fundingFeeAmount) : undefined,
117
117
  liquidationFeeAmount: rawAction.liquidationFeeAmount ? BigInt(rawAction.liquidationFeeAmount) : undefined,
118
- reason: rawAction.reason,
119
- reasonBytes: rawAction.reasonBytes,
118
+ reason: rawAction.reason ?? undefined,
119
+ reasonBytes: rawAction.reasonBytes ?? undefined,
120
120
  transaction: rawAction.transaction,
121
121
  timestamp: rawAction.timestamp,
122
122
  shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
@@ -1,4 +1,4 @@
1
- export { USD_DECIMALS, BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT } from "../utils/numbers";
1
+ export { USD_DECIMALS, BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT, BASIS_POINTS_DECIMALS } from "../utils/numbers";
2
2
  // V2
3
3
  export const HIGH_PRICE_IMPACT_BPS = 80; // 0.8%
4
4
  export const HIGH_POSITION_IMPACT_BPS = 50; // 0.5%
@@ -110,7 +110,7 @@ export async function increaseOrderHelper(sdk, params) {
110
110
  referralCodeForTxn: params.referralCodeForTxn,
111
111
  triggerPrice: params.limitPrice,
112
112
  collateralTokenAddress: collateralToken.address,
113
- isLong: true,
113
+ isLong: params.isLong,
114
114
  receiveTokenAddress: collateralTokenAddress,
115
115
  indexToken: marketInfo.indexToken,
116
116
  marketInfo,
@@ -63,7 +63,7 @@ export function createDecreaseEncodedPayload({ sdk, orderVaultAddress, ps, }) {
63
63
  callbackContract: zeroAddress,
64
64
  market: p.marketAddress,
65
65
  swapPath: p.swapPath,
66
- uiFeeReceiver: zeroAddress,
66
+ uiFeeReceiver: sdk.config.settings?.uiFeeReceiverAccount || zeroAddress,
67
67
  },
68
68
  numbers: {
69
69
  sizeDeltaUsd: p.sizeDeltaUsd,
@@ -32,6 +32,7 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
32
32
  acceptablePrice,
33
33
  isNativePayment,
34
34
  initialCollateralTokenAddress,
35
+ uiFeeReceiver: sdk.config.settings?.uiFeeReceiverAccount,
35
36
  });
36
37
  const simulationEncodedPayload = await createEncodedPayload({
37
38
  routerAbi: abis.ExchangeRouter,
@@ -41,6 +42,7 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
41
42
  acceptablePrice,
42
43
  isNativePayment,
43
44
  initialCollateralTokenAddress,
45
+ uiFeeReceiver: sdk.config.settings?.uiFeeReceiverAccount,
44
46
  });
45
47
  const decreaseEncodedPayload = createDecreaseEncodedPayload({
46
48
  sdk,
@@ -84,12 +86,13 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
84
86
  value: totalWntAmount,
85
87
  });
86
88
  }
87
- async function createEncodedPayload({ routerAbi, orderVaultAddress, totalWntAmount, p, acceptablePrice, isNativePayment, initialCollateralTokenAddress, }) {
89
+ async function createEncodedPayload({ routerAbi, orderVaultAddress, totalWntAmount, p, acceptablePrice, isNativePayment, initialCollateralTokenAddress, uiFeeReceiver, }) {
88
90
  const orderParams = createOrderParams({
89
91
  p,
90
92
  acceptablePrice,
91
93
  initialCollateralTokenAddress,
92
94
  isNativePayment,
95
+ uiFeeReceiver,
93
96
  });
94
97
  const multicall = [
95
98
  { method: "sendWnt", params: [orderVaultAddress, totalWntAmount] },
@@ -107,7 +110,7 @@ async function createEncodedPayload({ routerAbi, orderVaultAddress, totalWntAmou
107
110
  args: call.params,
108
111
  }));
109
112
  }
110
- function createOrderParams({ p, acceptablePrice, initialCollateralTokenAddress, isNativePayment, }) {
113
+ function createOrderParams({ p, acceptablePrice, initialCollateralTokenAddress, isNativePayment, uiFeeReceiver, }) {
111
114
  return {
112
115
  addresses: {
113
116
  cancellationReceiver: zeroAddress,
@@ -116,7 +119,7 @@ function createOrderParams({ p, acceptablePrice, initialCollateralTokenAddress,
116
119
  callbackContract: zeroAddress,
117
120
  market: p.marketAddress,
118
121
  swapPath: p.swapPath,
119
- uiFeeReceiver: zeroAddress,
122
+ uiFeeReceiver: uiFeeReceiver || zeroAddress,
120
123
  },
121
124
  numbers: {
122
125
  sizeDeltaUsd: p.sizeDeltaUsd,
@@ -41,7 +41,7 @@ async function getParams(sdk, p) {
41
41
  callbackContract: zeroAddress,
42
42
  market: zeroAddress,
43
43
  swapPath: p.swapPath,
44
- uiFeeReceiver: zeroAddress,
44
+ uiFeeReceiver: sdk.config.settings?.uiFeeReceiverAccount || zeroAddress,
45
45
  },
46
46
  numbers: {
47
47
  sizeDeltaUsd: 0n,