Skip to content

Commit

Permalink
fix: custom slippage (#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino authored Sep 25, 2024
1 parent 817e802 commit ae5df21
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 123 deletions.
3 changes: 1 addition & 2 deletions audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"GHSA-353f-5xf4-qw67",
"GHSA-j8xg-fqg3-53r7",
"GHSA-67hx-6x53-jw92",
"GHSA-c24v-8rfc-w8vw",
"GHSA-m95q-7qp3-xv42"
"GHSA-c24v-8rfc-w8vw"
]
}
13 changes: 8 additions & 5 deletions e2e/serial/swap/1_swapFlow1.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import 'chromedriver';
import 'geckodriver';
import { WebDriver } from 'selenium-webdriver';
import { Key, WebDriver } from 'selenium-webdriver';
import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from 'vitest';

import { ChainId } from '~/core/types/chains';
Expand Down Expand Up @@ -222,14 +222,16 @@ it('should be able to interact with slippage settings', async () => {
id: 'explainer-action-button',
driver,
});
await clearInput({
await typeOnTextInput({
id: 'slippage-input-mask',
driver,
text: Key.BACK_SPACE,
});
await delayTime('short');
await typeOnTextInput({
id: 'slippage-input-mask',
driver,
text: '4',
text: '5',
});
await delayTime('short');
const warning = await findElementByTestId({
Expand Down Expand Up @@ -1005,11 +1007,12 @@ it('should be able to execute swap', async () => {
id: 'swap-settings-navbar-button',
driver,
});
await delayTime('short');
await clearInput({
await typeOnTextInput({
id: 'slippage-input-mask',
driver,
text: Key.BACK_SPACE,
});
await delayTime('short');
await typeOnTextInput({
id: 'slippage-input-mask',
driver,
Expand Down
8 changes: 6 additions & 2 deletions e2e/serial/swap/2_swapFlow2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'chromedriver';
import 'geckodriver';
import { Contract } from '@ethersproject/contracts';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { WebDriver } from 'selenium-webdriver';
import { Key, WebDriver } from 'selenium-webdriver';
import { erc20Abi } from 'viem';
import {
afterAll,
Expand Down Expand Up @@ -154,6 +154,7 @@ describe('Swap Flow 2', () => {
id: `${SWAP_VARIABLES.USDC_MAINNET_ID}-token-to-sell-swap-token-input-swap-input-mask`,
driver,
});
await delayTime('medium');
await typeOnTextInput({
id: `${SWAP_VARIABLES.USDC_MAINNET_ID}-token-to-sell-swap-token-input-swap-input-mask`,
text: `\b50`,
Expand Down Expand Up @@ -181,10 +182,13 @@ describe('Swap Flow 2', () => {
driver,
});
await delayTime('short');
await clearInput({

await typeOnTextInput({
id: 'slippage-input-mask',
driver,
text: Key.BACK_SPACE,
});
await delayTime('short');
await typeOnTextInput({
id: 'slippage-input-mask',
driver,
Expand Down
9 changes: 7 additions & 2 deletions lavamoat/build-webpack/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,13 @@
"define": true
},
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true,
"webpack>terser-webpack-plugin>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true,
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": {
"globals": {
"define": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@
"micromatch": "4.0.8",
"webpack": "5.94.0",
"path-to-regexp": "6.3.0",
"dset": "3.1.4"
"dset": "3.1.4",
"zod": "3.23.8",
"rollup": "4.22.4"
},
"lavamoat": {
"allowScripts": {
Expand Down
1 change: 0 additions & 1 deletion src/core/raps/unlockAndSwap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ test('[rap/unlockAndSwap] :: create unwrap eth rap', async () => {
assetToSell: WETH_MAINNET_ASSET,
assetToBuy: ETH_MAINNET_ASSET,
});
console.log('-- rap.actions', rap.actions);
expect(rap.actions.length).toBe(1);
});

Expand Down
2 changes: 2 additions & 0 deletions src/core/utils/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { serialize } from '@ethersproject/transactions';
import BigNumber from 'bignumber.js';

import { globalColors } from '~/design-system/styles/designTokens';
import { RainbowError, logger } from '~/logger';

import { i18n } from '../languages';
import {
Expand Down Expand Up @@ -549,6 +550,7 @@ export const estimateGasWithPadding = async ({
// otherwise default to the last block gas limit
return lastBlockGasLimit;
} catch (error) {
logger.error(new RainbowError(`estimateGasWithPadding error: ${error}`));
return null;
}
};
Expand Down
4 changes: 0 additions & 4 deletions src/entries/background/handlers/handleWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { flashbotsEnabledStore } from '~/core/state';
import { WalletAction } from '~/core/types/walletActions';
import { EthereumWalletSeed } from '~/core/utils/ethereum';
import { getFlashbotsProvider } from '~/core/utils/flashbots';
import { wagmiConfig } from '~/core/wagmi';
import { getProvider } from '~/core/wagmi/clientToProvider';

type WalletActionArguments = {
Expand Down Expand Up @@ -192,12 +191,9 @@ export const handleWallets = () =>
) {
provider = getFlashbotsProvider();
} else {
console.log('get background provider');
console.log('get background wagmiconfig', wagmiConfig);
provider = getProvider({
chainId: (payload as TransactionRequest).chainId,
});
console.log(' background provider', provider);
}
response = await sendTransaction(
payload as TransactionRequest,
Expand Down
5 changes: 2 additions & 3 deletions src/entries/popup/pages/swap/SwapSettings/SwapSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { i18n } from '~/core/languages';
import { useCurrentAddressStore, useFlashbotsEnabledStore } from '~/core/state';
import { useFeatureFlagsStore } from '~/core/state/currentSettings/featureFlags';
import { ChainId } from '~/core/types/chains';
import { divide } from '~/core/utils/numbers';
import {
Bleed,
Box,
Expand Down Expand Up @@ -280,12 +279,12 @@ export const SwapSettings = ({
try {
setSettings({
source,
slippage: divide(slippage, 100).toString(),
slippage,
swapFlashbotsEnabled,
});
onDone();
} catch (e) {
console.log('DONEEEEEEE e', e);
//
}
}, [swapFlashbotsEnabled, onDone, setSettings, slippage, source]);

Expand Down
Loading

0 comments on commit ae5df21

Please sign in to comment.