From 13e026c9ca44bc3b0759994de2dbcb8435aa3362 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sun, 14 Jan 2024 14:32:53 -0800 Subject: [PATCH 1/3] test(gmx): add test for limit swap --- packages/gmx/src/GMX.test.ts | 2 +- packages/gmx/src/test-setup.ts | 2 ++ packages/gmx/src/test-transactions.ts | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/gmx/src/GMX.test.ts b/packages/gmx/src/GMX.test.ts index 296a4d2df..35d2d50ed 100644 --- a/packages/gmx/src/GMX.test.ts +++ b/packages/gmx/src/GMX.test.ts @@ -64,7 +64,7 @@ describe('Given the gmx plugin', () => { $abiAbstract: GMX_SWAPV2_ABI, params: { numbers: { minOutputAmount: { $gte: '100000' } }, - orderType: 0, + orderType: { $lte: 1 }, addresses: { initialCollateralToken: Tokens.USDCe, receiver: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', diff --git a/packages/gmx/src/test-setup.ts b/packages/gmx/src/test-setup.ts index 43420d728..df38d12c0 100644 --- a/packages/gmx/src/test-setup.ts +++ b/packages/gmx/src/test-setup.ts @@ -16,6 +16,7 @@ import { USDCe_FOR_WETH_V2, REDUCE_ORDER_V2, ALT_ETHOUT_V2, + LIMIT_SWAP, MARKET_SHORT_ETH_ORDER_V2, LIMIT_LONG_ARB_ORDER_V2, MARKET_LONG_ARB_WITH_USDC_ORDER_V2, @@ -72,6 +73,7 @@ export const passingTestCasesV2 = [ createTestCase(USDCe_FOR_WETH_V2, 'when swapping USDC.e to WETH'), createTestCase(ALT_ETHOUT_V2, 'when swapping USDC.e to ETH'), createTestCase(SWAP_TOKENS_V2, 'when all parameters are correct'), + createTestCase(LIMIT_SWAP, 'when making a limit swap'), createTestCase(TOKENS_FOR_TOKENS_V2, 'when tokenIn is set to "any', { tokenIn: undefined, }), diff --git a/packages/gmx/src/test-transactions.ts b/packages/gmx/src/test-transactions.ts index 26557c805..f602b339a 100644 --- a/packages/gmx/src/test-transactions.ts +++ b/packages/gmx/src/test-transactions.ts @@ -264,6 +264,25 @@ export const ALT_ETHOUT_V2: TestParams = { }, } +export const LIMIT_SWAP: TestParams = { + transaction: { + chainId: 42161, + to: '0x7c68c7866a64fa2160f78eeae12217ffbf871fa8', + from: '0x169719222a053c8214ee3e5e5c2c735b3c0029cb', + hash: '0x7ab8e55400d725df382770a48164107220b4f23e8ed03352afe6dde00ca16e40', + input: + '0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d50000000000000000000000000000000000000000000000000003e871b540c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064e6d66ac8000000000000000000000000912ce59144191c1204e64559fe8253a0e49e654800000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000015181ff25a9800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e44a393a41000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e871b540c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000494fd5e170344000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000169646f7265000000000000000000000000000000000000000000000000000000000000000000000000000000169719222a053c8214ee3e5e5c2c735b3c0029cb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000912ce59144191c1204e64559fe8253a0e49e654800000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c25cef6061cf5de5eb761b50e4743c1f5d7e540700000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000000000000000000000000000000000000', + value: '1100000000000000', + }, + params: { + chainId: ARB_ONE_CHAIN_ID, + tokenIn: '0x912ce59144191c1204e64559fe8253a0e49e6548', // ARB + tokenOut: ETH_ADDRESS, // ETH + amountIn: GreaterThanOrEqual(parseUnits('1.52', 6)), + amountOut: GreaterThanOrEqual(parseEther('0.0011')), + }, +} + export const LIMIT_LONG_ARB_ORDER_V2: TestParams = { transaction: { chainId: 42161, From 4e58b50a920d3e0a331d5ace7e40fcc6a6a8e58d Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sun, 14 Jan 2024 14:33:07 -0800 Subject: [PATCH 2/3] feat(gmx): add support for limit swap --- packages/gmx/src/GMX.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gmx/src/GMX.ts b/packages/gmx/src/GMX.ts index 20662df72..a215cc660 100644 --- a/packages/gmx/src/GMX.ts +++ b/packages/gmx/src/GMX.ts @@ -65,7 +65,7 @@ export const swap = async ( numbers: { minOutputAmount: amountOut, }, - orderType: OrderType.MarketSwap, + orderType: { $lte: OrderType.LimitSwap }, addresses: { initialCollateralToken: ETH_USED ? Tokens.WETH : tokenIn, receiver: recipient, From 455a7b8ba6da2d32234a6bd84ffc2a12d308a12a Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sun, 14 Jan 2024 14:36:29 -0800 Subject: [PATCH 3/3] chore(pnpm): generate changes --- .changeset/lovely-zoos-burn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lovely-zoos-burn.md diff --git a/.changeset/lovely-zoos-burn.md b/.changeset/lovely-zoos-burn.md new file mode 100644 index 000000000..e6360d7d5 --- /dev/null +++ b/.changeset/lovely-zoos-burn.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-gmx": minor +--- + +add support for limit swap ordertype to gmx swap plugin