Skip to content

Commit

Permalink
Merge pull request #166 from rabbitholegg/mmackz-add-limitswap-gmx
Browse files Browse the repository at this point in the history
feat(gmx): add support for limit swap
  • Loading branch information
Quazia authored Jan 16, 2024
2 parents 3783fa8 + 455a7b8 commit cab3af9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-zoos-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-gmx": minor
---

add support for limit swap ordertype to gmx swap plugin
2 changes: 1 addition & 1 deletion packages/gmx/src/GMX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/gmx/src/GMX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/gmx/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}),
Expand Down
19 changes: 19 additions & 0 deletions packages/gmx/src/test-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,25 @@ export const ALT_ETHOUT_V2: TestParams<SwapActionParams> = {
},
}

export const LIMIT_SWAP: TestParams<SwapActionParams> = {
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<OptionsActionParams> = {
transaction: {
chainId: 42161,
Expand Down

0 comments on commit cab3af9

Please sign in to comment.