@gmx-io/sdk 2.6.0-next.0 → 2.7.0

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.
package/README.md CHANGED
@@ -231,6 +231,31 @@ sdk.orders.swap({
231
231
 
232
232
  Note the distinction between `payTokenAddress` and `collateralTokenAddress`. These represent the ERC20 token addresses for payment and collateral respectively. Some markets use synthetic tokens, so you'll need to provide the correct underlying token address. For example, the BTC/USD [WETH-USDC] market has a synthetic BTC token as its `indexTokenAddress`, so you should pass the WBTC address instead of BTC.
233
233
 
234
+ ### Execution-fee deposits with a zero-tip bundler
235
+
236
+ The v2 API client's `prepareOrder` and `prepareCollateral` methods accept
237
+ `skipExecutionFeePriorityFeeAllowance?: boolean`, which defaults to `false`:
238
+
239
+ ```typescript
240
+ const prepared = await api.prepareOrder({
241
+ ...request,
242
+ mode: "classic",
243
+ skipExecutionFeePriorityFeeAllowance: true,
244
+ });
245
+ ```
246
+
247
+ Set this to `true` only when the outer transaction your bundler submits to Arbitrum uses zero priority
248
+ fee, including retries and wallet fallbacks. A zero tip on a UserOperation alone is not sufficient.
249
+ This removes only the 0.03 gwei-per-gas wallet-tip allowance and preserves `executionFeeBufferBps`,
250
+ including the default 30% buffer, and the remaining execution-fee calculation. It applies to attached
251
+ TP/SL orders, every TWAP part and collateral operations. Express and other chains retain their current
252
+ calculation.
253
+
254
+ The keeper executes separately later, so this does not guarantee future gas costs or a refund.
255
+ A later tipped submission or order edit can fail with `InsufficientExecutionFee`; use
256
+ `executionFeeTopUp` when an edit needs more funding. The API deployment must support the option before
257
+ clients send it; older deployments reject the unknown field. Malformed values return HTTP 400.
258
+
234
259
  ### JIT-aware trading capacity
235
260
 
236
261
  Use the v2 API client to get the current increase-order capacity for one market side:
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [
4
+ {
5
+ inputs: [
6
+ { internalType: "address", name: "token", type: "address" },
7
+ { internalType: "bytes", name: "", type: "bytes" },
8
+ ],
9
+ name: "getOraclePrice",
10
+ outputs: [
11
+ {
12
+ components: [
13
+ { internalType: "address", name: "token", type: "address" },
14
+ { internalType: "uint256", name: "min", type: "uint256" },
15
+ { internalType: "uint256", name: "max", type: "uint256" },
16
+ { internalType: "uint256", name: "timestamp", type: "uint256" },
17
+ { internalType: "address", name: "provider", type: "address" },
18
+ ],
19
+ internalType: "struct OracleUtils.ValidatedPrice",
20
+ name: "",
21
+ type: "tuple",
22
+ },
23
+ ],
24
+ stateMutability: "view",
25
+ type: "function",
26
+ },
27
+ ];
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [
4
+ {
5
+ inputs: [],
6
+ name: "paused",
7
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
8
+ stateMutability: "view",
9
+ type: "function",
10
+ },
11
+ ];
@@ -8,6 +8,7 @@ const viem_1 = require("viem");
8
8
  const AbstractSubaccountApprovalNonceable_1 = __importDefault(require("./AbstractSubaccountApprovalNonceable"));
9
9
  const ArbitrumNodeInterface_1 = __importDefault(require("./ArbitrumNodeInterface"));
10
10
  const ArbSys_1 = __importDefault(require("./ArbSys"));
11
+ const ChainlinkPriceFeedProvider_1 = __importDefault(require("./ChainlinkPriceFeedProvider"));
11
12
  const ClaimHandler_1 = __importDefault(require("./ClaimHandler"));
12
13
  const CustomErrors_1 = __importDefault(require("./CustomErrors"));
13
14
  const CustomErrorsV2_2_1_1 = __importDefault(require("./CustomErrorsV2_2_1"));
@@ -33,6 +34,7 @@ const MultichainOrderRouter_1 = __importDefault(require("./MultichainOrderRouter
33
34
  const MultichainSubaccountRouter_1 = __importDefault(require("./MultichainSubaccountRouter"));
34
35
  const MultichainTransferRouter_1 = __importDefault(require("./MultichainTransferRouter"));
35
36
  const MultichainVault_1 = __importDefault(require("./MultichainVault"));
37
+ const Pausable_1 = __importDefault(require("./Pausable"));
36
38
  const Reader_1 = __importDefault(require("./Reader"));
37
39
  const ReaderV2_1 = __importDefault(require("./ReaderV2"));
38
40
  const ReferralStorage_1 = __importDefault(require("./ReferralStorage"));
@@ -67,6 +69,7 @@ exports.abis = {
67
69
  AbstractSubaccountApprovalNonceable: AbstractSubaccountApprovalNonceable_1.default,
68
70
  ArbitrumNodeInterface: ArbitrumNodeInterface_1.default,
69
71
  ArbSys: ArbSys_1.default,
72
+ ChainlinkPriceFeedProvider: ChainlinkPriceFeedProvider_1.default,
70
73
  ClaimHandler: ClaimHandler_1.default,
71
74
  CustomErrors: [...CustomErrors_1.default, ...CustomErrorsV2_2_1_1.default],
72
75
  DataStore: DataStore_1.default,
@@ -91,6 +94,7 @@ exports.abis = {
91
94
  MultichainSubaccountRouter: MultichainSubaccountRouter_1.default,
92
95
  MultichainTransferRouter: MultichainTransferRouter_1.default,
93
96
  MultichainVault: MultichainVault_1.default,
97
+ Pausable: Pausable_1.default,
94
98
  ReferralStorage: ReferralStorage_1.default,
95
99
  RelayParams: RelayParams_1.default,
96
100
  RewardReader: RewardReader_1.default,
@@ -16,6 +16,7 @@ const GAS_PAYMENT_TOKENS = {
16
16
  (0, tokens_1.getTokenBySymbol)(chains_1.ARBITRUM, "USDC").address,
17
17
  (0, tokens_1.getTokenBySymbol)(chains_1.ARBITRUM, "WETH").address,
18
18
  (0, tokens_1.getTokenBySymbol)(chains_1.ARBITRUM, "USDT").address,
19
+ (0, tokens_1.getTokenBySymbol)(chains_1.ARBITRUM, "USDG").address,
19
20
  ],
20
21
  [chains_1.AVALANCHE]: [
21
22
  (0, tokens_1.getTokenBySymbol)(chains_1.AVALANCHE, "USDC").address,
@@ -134,6 +134,9 @@ exports.TOKENS = {
134
134
  isStable: true,
135
135
  imageUrl: "https://coin-images.coingecko.com/coins/images/51281/small/GDN_USDG_Token_200x200.png?1730484111",
136
136
  explorerUrl: "https://arbiscan.io/token/0x004B506865409877C9fA29bfb1ebA929984B9bbC",
137
+ isPermitSupported: true,
138
+ // the contract has no version() to read it from
139
+ contractVersion: "1",
137
140
  },
138
141
  {
139
142
  name: "Tether",
@@ -120,13 +120,23 @@ function decodeMulticall(data) {
120
120
  const [decodedDstEid] = (0, viem_1.decodeAbiParameters)([{ type: "uint32" }], params.data);
121
121
  (0, vitest_1.expect)(decodedDstEid).toBe(multichain_1.CHAIN_ID_TO_ENDPOINT_ID[chains_1.SOURCE_BASE_MAINNET]);
122
122
  });
123
- (0, vitest_1.it)("defaults minAmountOut to amount when slippage is unspecified", () => {
123
+ (0, vitest_1.it)("leaves 50 bps for the bridge fee when slippage is unspecified", () => {
124
124
  const params = (0, api_1.buildCrossChainWithdrawBridgeOutParams)({
125
125
  tokenAddress: USDC_ARBITRUM,
126
126
  amount: 1000000n,
127
127
  dstChainId: chains_1.SOURCE_BASE_MAINNET,
128
128
  stargateAddress: STARGATE_USDC_ARBITRUM,
129
129
  });
130
+ (0, vitest_1.expect)(params.minAmountOut).toBe(995000n);
131
+ });
132
+ (0, vitest_1.it)("keeps minAmountOut equal to amount with zero slippage", () => {
133
+ const params = (0, api_1.buildCrossChainWithdrawBridgeOutParams)({
134
+ tokenAddress: USDC_ARBITRUM,
135
+ amount: 1000000n,
136
+ dstChainId: chains_1.SOURCE_BASE_MAINNET,
137
+ stargateAddress: STARGATE_USDC_ARBITRUM,
138
+ slippageBps: 0,
139
+ });
130
140
  (0, vitest_1.expect)(params.minAmountOut).toBe(1000000n);
131
141
  });
132
142
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeSameChainWithdraw = exports.executeSameChainDeposit = exports.buildCrossChainWithdrawBridgeOutParams = exports.buildSameChainWithdrawTxn = exports.buildSameChainWithdrawBridgeOutParams = exports.getEmptyBridgeFeeParams = exports.buildSameChainDepositTxn = void 0;
3
+ exports.executeSameChainWithdraw = exports.executeSameChainDeposit = exports.buildCrossChainWithdrawBridgeOutParams = exports.DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS = exports.buildSameChainWithdrawTxn = exports.buildSameChainWithdrawBridgeOutParams = exports.getEmptyBridgeFeeParams = exports.buildSameChainDepositTxn = void 0;
4
4
  const viem_1 = require("viem");
5
5
  const getAbi_1 = require("../../abis/getAbi");
6
6
  const contracts_1 = require("../../configs/contracts");
@@ -86,6 +86,7 @@ function buildSameChainWithdrawTxn(request) {
86
86
  return { to: router, data, value: 0n };
87
87
  }
88
88
  exports.buildSameChainWithdrawTxn = buildSameChainWithdrawTxn;
89
+ exports.DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS = 50;
89
90
  /**
90
91
  * `BridgeOutParams.data` for cross-chain delivery is a single `uint32 dstEid`
91
92
  * pointing at the destination LayerZero endpoint; the on-chain provider takes
@@ -94,7 +95,7 @@ exports.buildSameChainWithdrawTxn = buildSameChainWithdrawTxn;
94
95
  * `utils/express/utils/bridgeOutUtils`.
95
96
  */
96
97
  function buildCrossChainWithdrawBridgeOutParams(params) {
97
- const { tokenAddress, amount, dstChainId, stargateAddress, slippageBps = 0 } = params;
98
+ const { tokenAddress, amount, dstChainId, stargateAddress, slippageBps = exports.DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS, } = params;
98
99
  if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps >= 10000) {
99
100
  throw new Error(`slippageBps must be an integer in range [0, 10000), got ${slippageBps}`);
100
101
  }
@@ -0,0 +1,25 @@
1
+ export default [
2
+ {
3
+ inputs: [
4
+ { internalType: "address", name: "token", type: "address" },
5
+ { internalType: "bytes", name: "", type: "bytes" },
6
+ ],
7
+ name: "getOraclePrice",
8
+ outputs: [
9
+ {
10
+ components: [
11
+ { internalType: "address", name: "token", type: "address" },
12
+ { internalType: "uint256", name: "min", type: "uint256" },
13
+ { internalType: "uint256", name: "max", type: "uint256" },
14
+ { internalType: "uint256", name: "timestamp", type: "uint256" },
15
+ { internalType: "address", name: "provider", type: "address" },
16
+ ],
17
+ internalType: "struct OracleUtils.ValidatedPrice",
18
+ name: "",
19
+ type: "tuple",
20
+ },
21
+ ],
22
+ stateMutability: "view",
23
+ type: "function",
24
+ },
25
+ ];
@@ -0,0 +1,9 @@
1
+ export default [
2
+ {
3
+ inputs: [],
4
+ name: "paused",
5
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
6
+ stateMutability: "view",
7
+ type: "function",
8
+ },
9
+ ];
@@ -2,6 +2,7 @@ import { erc20Abi } from "viem";
2
2
  import AbstractSubaccountApprovalNonceable from "./AbstractSubaccountApprovalNonceable";
3
3
  import ArbitrumNodeInterface from "./ArbitrumNodeInterface";
4
4
  import ArbSys from "./ArbSys";
5
+ import ChainlinkPriceFeedProvider from "./ChainlinkPriceFeedProvider";
5
6
  import ClaimHandler from "./ClaimHandler";
6
7
  import CustomErrors from "./CustomErrors";
7
8
  import CustomErrorsV2_2_1 from "./CustomErrorsV2_2_1";
@@ -27,6 +28,7 @@ import MultichainOrderRouter from "./MultichainOrderRouter";
27
28
  import MultichainSubaccountRouter from "./MultichainSubaccountRouter";
28
29
  import MultichainTransferRouter from "./MultichainTransferRouter";
29
30
  import MultichainVault from "./MultichainVault";
31
+ import Pausable from "./Pausable";
30
32
  import Reader from "./Reader";
31
33
  import ReaderV2 from "./ReaderV2";
32
34
  import ReferralStorage from "./ReferralStorage";
@@ -61,6 +63,7 @@ export const abis = {
61
63
  AbstractSubaccountApprovalNonceable,
62
64
  ArbitrumNodeInterface,
63
65
  ArbSys,
66
+ ChainlinkPriceFeedProvider,
64
67
  ClaimHandler,
65
68
  CustomErrors: [...CustomErrors, ...CustomErrorsV2_2_1],
66
69
  DataStore,
@@ -85,6 +88,7 @@ export const abis = {
85
88
  MultichainSubaccountRouter,
86
89
  MultichainTransferRouter,
87
90
  MultichainVault,
91
+ Pausable,
88
92
  ReferralStorage,
89
93
  RelayParams,
90
94
  RewardReader,
@@ -13,6 +13,7 @@ const GAS_PAYMENT_TOKENS = {
13
13
  getTokenBySymbol(ARBITRUM, "USDC").address,
14
14
  getTokenBySymbol(ARBITRUM, "WETH").address,
15
15
  getTokenBySymbol(ARBITRUM, "USDT").address,
16
+ getTokenBySymbol(ARBITRUM, "USDG").address,
16
17
  ],
17
18
  [AVALANCHE]: [
18
19
  getTokenBySymbol(AVALANCHE, "USDC").address,
@@ -131,6 +131,9 @@ export const TOKENS = {
131
131
  isStable: true,
132
132
  imageUrl: "https://coin-images.coingecko.com/coins/images/51281/small/GDN_USDG_Token_200x200.png?1730484111",
133
133
  explorerUrl: "https://arbiscan.io/token/0x004B506865409877C9fA29bfb1ebA929984B9bbC",
134
+ isPermitSupported: true,
135
+ // the contract has no version() to read it from
136
+ contractVersion: "1",
134
137
  },
135
138
  {
136
139
  name: "Tether",
@@ -118,13 +118,23 @@ describe("multichain api: buildCrossChainWithdrawBridgeOutParams", () => {
118
118
  const [decodedDstEid] = decodeAbiParameters([{ type: "uint32" }], params.data);
119
119
  expect(decodedDstEid).toBe(CHAIN_ID_TO_ENDPOINT_ID[SOURCE_BASE_MAINNET]);
120
120
  });
121
- it("defaults minAmountOut to amount when slippage is unspecified", () => {
121
+ it("leaves 50 bps for the bridge fee when slippage is unspecified", () => {
122
122
  const params = buildCrossChainWithdrawBridgeOutParams({
123
123
  tokenAddress: USDC_ARBITRUM,
124
124
  amount: 1000000n,
125
125
  dstChainId: SOURCE_BASE_MAINNET,
126
126
  stargateAddress: STARGATE_USDC_ARBITRUM,
127
127
  });
128
+ expect(params.minAmountOut).toBe(995000n);
129
+ });
130
+ it("keeps minAmountOut equal to amount with zero slippage", () => {
131
+ const params = buildCrossChainWithdrawBridgeOutParams({
132
+ tokenAddress: USDC_ARBITRUM,
133
+ amount: 1000000n,
134
+ dstChainId: SOURCE_BASE_MAINNET,
135
+ stargateAddress: STARGATE_USDC_ARBITRUM,
136
+ slippageBps: 0,
137
+ });
128
138
  expect(params.minAmountOut).toBe(1000000n);
129
139
  });
130
140
  });
@@ -79,6 +79,7 @@ export function buildSameChainWithdrawTxn(request) {
79
79
  });
80
80
  return { to: router, data, value: 0n };
81
81
  }
82
+ export const DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS = 50;
82
83
  /**
83
84
  * `BridgeOutParams.data` for cross-chain delivery is a single `uint32 dstEid`
84
85
  * pointing at the destination LayerZero endpoint; the on-chain provider takes
@@ -87,7 +88,7 @@ export function buildSameChainWithdrawTxn(request) {
87
88
  * `utils/express/utils/bridgeOutUtils`.
88
89
  */
89
90
  export function buildCrossChainWithdrawBridgeOutParams(params) {
90
- const { tokenAddress, amount, dstChainId, stargateAddress, slippageBps = 0 } = params;
91
+ const { tokenAddress, amount, dstChainId, stargateAddress, slippageBps = DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS, } = params;
91
92
  if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps >= 10000) {
92
93
  throw new Error(`slippageBps must be an integer in range [0, 10000), got ${slippageBps}`);
93
94
  }