Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intercept and mock e2e swaps calls #1754

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
db0810f
prevent useSwapSlippage from making unnecessary requests
greg-schrammel Oct 31, 2024
9164172
test
greg-schrammel Nov 1, 2024
1cd7b09
response
greg-schrammel Nov 4, 2024
2119c2d
popular in rainbow
greg-schrammel Nov 5, 2024
a5e1c8f
dad can you come pick me up im scared
greg-schrammel Nov 12, 2024
8624638
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes Nov 13, 2024
1752d7f
yarn setup ran lol
BrodyHughes Nov 13, 2024
5efb232
hmm
BrodyHughes Nov 13, 2024
becb035
fix test 1, test test 2
BrodyHughes Nov 14, 2024
06942ad
logging
BrodyHughes Nov 14, 2024
52efb0b
skip test
BrodyHughes Nov 19, 2024
37d9f68
okay
BrodyHughes Nov 19, 2024
5675d1a
audit fix
BrodyHughes Nov 19, 2024
74e8084
yarn install
BrodyHughes Nov 19, 2024
e9d33be
fix send
BrodyHughes Nov 19, 2024
1c3e162
reenable retries
BrodyHughes Nov 19, 2024
37d7bfc
add all mocks, fix unit tests by making them use hardhat now
BrodyHughes Nov 21, 2024
64d38ff
rm retry:0
BrodyHughes Nov 21, 2024
4030edf
clean up
BrodyHughes Nov 21, 2024
235db69
check vlock number add new hashed responses
BrodyHughes Dec 3, 2024
0de1dfa
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes Dec 3, 2024
25d7ebd
tweak script and get new responses + yarn install
BrodyHughes Dec 3, 2024
924befc
okay point the script at the anvil instance instead of our prod key
BrodyHughes Dec 3, 2024
aff68a2
undo the removal of chainIds from testIds (#1779)
BrodyHughes Dec 12, 2024
c3a70cc
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes Dec 12, 2024
6995691
bad merge oops
BrodyHughes Dec 12, 2024
d988f48
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes Dec 12, 2024
60196a9
failOnError: false
BrodyHughes Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions e2e/fetchResponses.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import { writeFile } from 'fs/promises';
/* eslint-disable @typescript-eslint/no-var-requires */

import { Hex, createClient, http, sha256 } from 'viem';
import { getBlockNumber } from 'viem/actions';
// this file is ran locally with ts-node to fetch the responses from the swap quotes urls
require('dotenv').config();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran locally to get swap_quotes outputs

const { writeFile } = require('fs/promises');

import urls from './mocks/mock_swap_quotes_urls.json';
const { createClient, http, sha256 } = require('viem');
const { getBlockNumber } = require('viem/actions');

const client = createClient({ transport: http(process.env.ETH_MAINNET_RPC) });
const blockNumber = await getBlockNumber(client);
console.log(blockNumber);
const urls = require('./mocks/mock_swap_quotes_urls.json');

await Promise.all(
urls.map(async (url) => {
const res = await fetch(url).then((r) => r.text());
const hash = sha256(url as Hex);
writeFile(`./mocks/swap_quotes/${hash}.json`, res);
}),
);
(async () => {
const client = createClient({ transport: http(process.env.ETH_MAINNET_RPC) });
const blockNumber = await getBlockNumber(client);

// check initial blockNumber
console.log('OUTSIDE FUNCTION', blockNumber.toString());

await Promise.all(
urls.map(async (url: RequestInfo | URL) => {
const res = await fetch(url).then((r) => r.text());
const hash = sha256(url);

// check if blockNumber is the same the entire time
console.log('INSIDE FUNCTION', blockNumber.toString());
await writeFile(`e2e/mocks/swap_quotes/${hash}.json`, res);
BrodyHughes marked this conversation as resolved.
Show resolved Hide resolved
}),
);
})();

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sellTokenAddress":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","sellTokenAsset":{"assetCode":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","decimals":6,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668633498/assets/ethereum/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png","name":"USD Coin","network":"mainnet","symbol":"USDC","networks":{"1":{"address":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","decimals":6},"10":{"address":"0x0b2c639c533813f4aa9d7837caf62653d097ff85","decimals":6},"137":{"address":"0x3c499c542cef5e3811e1192ce70d8cc03d5c3359","decimals":6},"42161":{"address":"0xaf88d065e77c8cc2239327c5edb3a432268e5831","decimals":6},"43114":{"address":"0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e","decimals":6},"56":{"address":"0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d","decimals":18},"8453":{"address":"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913","decimals":6}},"chainId":1,"price":{"value":1.0002804182,"available":true},"totalPrice":{"value":2501.5871028969655,"available":true}},"buyTokenAddress":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","buyTokenAsset":{"assetCode":"eth","decimals":18,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/ethereum/eth.png","name":"Ethereum","network":"mainnet","symbol":"ETH","networks":{"1":{"address":"eth","decimals":18},"10":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"42161":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"56":{"address":"0x2170ed0880ac9a755fd29b2688956bd959f933f8","decimals":18},"7777777":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"81457":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"8453":{"address":"0x0000000000000000000000000000000000000000","decimals":18}},"chainId":1,"price":{"value":3355.9700000000003,"available":true},"totalPrice":{"value":2483.462325254361,"available":true}},"allowanceTarget":"0x00000000009726632680fb29d3f7a9734e3010e2","allowanceNeeded":true,"to":"0x111111125421ca6dc452d289314280a0f8842a65","data":"0x83800a8e000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000095107d310000000000000000000000000000000000000000000000000a4113ef1a038edd388000000000000000000000e0554a476a092703abdb3ef35c80e0d76d32939fd6f29312","sellAmount":"2500885809","sellAmountMinusFees":"2500885809","sellAmountDisplay":"2500885809","sellAmountInEth":"745414024230539959","buyAmount":"746357304565681096","buyAmountMinusFees":"740013267476872807","buyAmountDisplay":"740013267476872807","buyAmountDisplayMinimum":"732613134802104080","buyAmountInEth":"740013267476872807","tradeAmountUSD":2501.5871028969655,"tradeFeeAmountUSD":21.290398148927956,"value":"0","gasPrice":"28397551754","source":"1inch","protocols":[{"name":"UNISWAP_V3","part":100}],"feeTokenAsset":{"assetCode":"eth","decimals":18,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/ethereum/eth.png","name":"Ethereum","network":"mainnet","symbol":"ETH","networks":{"1":{"address":"eth","decimals":18},"10":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"42161":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"56":{"address":"0x2170ed0880ac9a755fd29b2688956bd959f933f8","decimals":18},"7777777":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"81457":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"8453":{"address":"0x0000000000000000000000000000000000000000","decimals":18}},"chainId":1,"price":{"value":3355.9700000000003,"available":true},"totalPrice":{"value":21.290398148927956,"available":true}},"fee":"6344037088808289","feeInEth":"6344037088808289","feePercentageBasisPoints":"8500000000000000","tradeType":"exact_input","from":"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720","defaultGasLimit":"350000","swapType":"normal","txTarget":"0x00000000009726632680fb29d3f7a9734e3010e2","chainId":1}
{"sellTokenAddress":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","sellTokenAsset":{"assetCode":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","decimals":6,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668633498/assets/ethereum/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png","name":"USD Coin","network":"mainnet","symbol":"USDC","networks":{"1":{"address":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","decimals":6},"10":{"address":"0x0b2c639c533813f4aa9d7837caf62653d097ff85","decimals":6},"137":{"address":"0x3c499c542cef5e3811e1192ce70d8cc03d5c3359","decimals":6},"42161":{"address":"0xaf88d065e77c8cc2239327c5edb3a432268e5831","decimals":6},"43114":{"address":"0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e","decimals":6},"56":{"address":"0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d","decimals":18},"8453":{"address":"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913","decimals":6}},"chainId":1,"price":{"value":0.9998424300000001,"available":true},"totalPrice":{"value":2500.491744423076,"available":true}},"buyTokenAddress":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","buyTokenAsset":{"assetCode":"eth","decimals":18,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/ethereum/eth.png","name":"Ethereum","network":"mainnet","symbol":"ETH","networks":{"1":{"address":"eth","decimals":18},"10":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"42161":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"56":{"address":"0x2170ed0880ac9a755fd29b2688956bd959f933f8","decimals":18},"7777777":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"81457":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"8453":{"address":"0x0000000000000000000000000000000000000000","decimals":18}},"chainId":1,"price":{"value":3582.92,"available":true},"totalPrice":{"value":2469.4691531432627,"available":true}},"allowanceTarget":"0x00000000009726632680fb29d3f7a9734e3010e2","allowanceNeeded":true,"to":"0xdef1c0ded9bec7f1a1670819833240f027b25eff","data":"0x415565b0000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000095107d31000000000000000000000000000000000000000000000000098ce8a3ad67932f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000005e000000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000095107d31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000002556e69737761705632000000000000000000000000000000000000000000000000000000000000000000000095107d31000000000000000000000000000000000000000000000000099094e50b8078bd000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000f164fc0ec4e93095b804a4795bbe1e041497b92a00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000003ac415e18e58e000000000000000000000000ad01c20d5886137e056775af56915de824c8fce5000000000000000000000000000000000000000000000000000000000000001d00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000009ac838f94b8da3c00000000000000000000000069d6d375de8c7ade7e44446df97f49e661fdad7d000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000007f5478f2b4db1e4ff272ac68","sellAmount":"2500885809","sellAmountMinusFees":"2500885809","sellAmountDisplay":"2500885809","sellAmountInEth":"697944746046383530","buyAmount":"695142394933555086","buyAmountMinusFees":"689233684576619868","buyAmountDisplay":"689233684576619868","buyAmountDisplayMinimum":"682341347730853670","buyAmountInEth":"689285627438701197","tradeAmountUSD":2500.491744423076,"tradeFeeAmountUSD":21.17043651207033,"value":"0","gasPrice":"30015947302","source":"0x","protocols":[{"name":"Uniswap_V2","part":100}],"feeTokenAsset":{"assetCode":"eth","decimals":18,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/ethereum/eth.png","name":"Ethereum","network":"mainnet","symbol":"ETH","networks":{"1":{"address":"eth","decimals":18},"10":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"42161":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"56":{"address":"0x2170ed0880ac9a755fd29b2688956bd959f933f8","decimals":18},"7777777":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"81457":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"8453":{"address":"0x0000000000000000000000000000000000000000","decimals":18}},"chainId":1,"price":{"value":3582.92,"available":true},"totalPrice":{"value":21.17043651207033,"available":true}},"fee":"5908710356935218","feeInEth":"5909155656307574","feePercentageBasisPoints":"8500000000000000","tradeType":"exact_input","from":"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720","defaultGasLimit":"350000","swapType":"normal","txTarget":"0x00000000009726632680fb29d3f7a9734e3010e2","chainId":1}
Loading
Loading