From df10b72c7e8586d86e62c33ec4232c1c5050620d Mon Sep 17 00:00:00 2001
From: jsy1218 <91580504+jsy1218@users.noreply.github.com>
Date: Mon, 18 Sep 2023 09:13:02 -0700
Subject: [PATCH] Fix: add tenderly env variables to github workflow (#401)

---
 .github/workflows/tests.yml                   | 168 +++++++++++++++++-
 .../alpha-router.integration.test.ts          |  13 +-
 test/test-util/whales.ts                      |  22 ++-
 3 files changed, 191 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 9a286fcd9..61f132ae1 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -41,8 +41,8 @@ jobs:
           JSON_RPC_PROVIDER_ARBITRUM_ONE: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_ONE }}
           JSON_RPC_PROVIDER_POLYGON: ${{ secrets.JSON_RPC_PROVIDER_POLYGON }}
 
-  integration-tests-alpha-router-integration-mainnet-alpha-0:
-    name: Integration Tests - Alpha Router Integration Mainnet Alpha 0
+  integration-tests-alpha-router-integration-mainnet-alpha-exact_input-erc20-to-erc20:
+    name: Integration Tests - Alpha Router Integration Mainnet Alpha EXACT_INPUT ERC20 -> ERC20
     runs-on: ubuntu-latest
 
     steps:
@@ -67,12 +67,16 @@ jobs:
         run: npm run build
 
       - name: Run Integration tests
-        run: npm run integ-test  -- -t 'mainnet alpha - 0'
+        run: npm run integ-test  -- -t 'mainnet alpha - 0 * erc20 -> erc20'
         env:
           JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
 
-  integration-tests-alpha-router-integration-mainnet-alpha-1:
-    name: Integration Tests - Alpha Router Integration Mainnet Alpha 1
+  integration-tests-alpha-router-integration-mainnet-alpha-exact_input-hardhat:
+    name: Integration Tests - Alpha Router Integration Mainnet Alpha EXACT_INPUT Execute On Hardhat Fork
     runs-on: ubuntu-latest
 
     steps:
@@ -97,9 +101,149 @@ jobs:
         run: npm run build
 
       - name: Run Integration tests
-        run: npm run integ-test  -- -t 'mainnet alpha - 1'
+        run: npm run integ-test  -- -t 'mainnet alpha - 0 * \+ Execute on Hardhat fork'
         env:
           JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
+
+  integration-tests-alpha-router-integration-mainnet-alpha-exact_input-tenderly-hardhat:
+    name: Integration Tests - Alpha Router Integration Mainnet Alpha EXACT_INPUT Simulate On Tenderly Execute On Hardhat Fork
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v1
+      - uses: actions/setup-node@v1
+        with:
+          node-version: 18.x
+          registry-url: https://registry.npmjs.org
+
+      - uses: actions/cache@v2
+        with:
+          path: ~/.npm
+          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-node-
+
+      - name: Install dependencies
+        run: npm install
+
+      # This is required separately from yarn test because it generates the typechain definitions
+      - name: Compile
+        run: npm run build
+
+      - name: Run Integration tests
+        run: npm run integ-test  -- -t 'mainnet alpha - 0 * \+ Simulate on Tenderly \+ Execute on Hardhat fork'
+        env:
+          JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
+
+  integration-tests-alpha-router-integration-mainnet-alpha-exact_output-erc20-to-erc20:
+    name: Integration Tests - Alpha Router Integration Mainnet Alpha EXACT_OUTPUT ERC20 -> ERC20
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v1
+      - uses: actions/setup-node@v1
+        with:
+          node-version: 18.x
+          registry-url: https://registry.npmjs.org
+
+      - uses: actions/cache@v2
+        with:
+          path: ~/.npm
+          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-node-
+
+      - name: Install dependencies
+        run: npm install
+
+      # This is required separately from yarn test because it generates the typechain definitions
+      - name: Compile
+        run: npm run build
+
+      - name: Run Integration tests
+        run: npm run integ-test  -- -t 'mainnet alpha - 1 * erc20 -> erc20'
+        env:
+          JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
+
+  integration-tests-alpha-router-integration-mainnet-alpha-exact_output-hardhat:
+    name: Integration Tests - Alpha Router Integration Mainnet Alpha EXACT_OUTPUT Execute On Hardhat Fork
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v1
+      - uses: actions/setup-node@v1
+        with:
+          node-version: 18.x
+          registry-url: https://registry.npmjs.org
+
+      - uses: actions/cache@v2
+        with:
+          path: ~/.npm
+          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-node-
+
+      - name: Install dependencies
+        run: npm install
+
+      # This is required separately from yarn test because it generates the typechain definitions
+      - name: Compile
+        run: npm run build
+
+      - name: Run Integration tests
+        run: npm run integ-test  -- -t 'mainnet alpha - 1 * \+ Execute on Hardhat fork'
+        env:
+          JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
+
+  integration-tests-alpha-router-integration-mainnet-alpha-exact_output-tenderly-hardhat:
+    name: Integration Tests - Alpha Router Integration Mainnet Alpha EXACT_OUTPUT Simulate On Tenderly Execute On Hardhat Fork
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v1
+      - uses: actions/setup-node@v1
+        with:
+          node-version: 18.x
+          registry-url: https://registry.npmjs.org
+
+      - uses: actions/cache@v2
+        with:
+          path: ~/.npm
+          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-node-
+
+      - name: Install dependencies
+        run: npm install
+
+      # This is required separately from yarn test because it generates the typechain definitions
+      - name: Compile
+        run: npm run build
+
+      - name: Run Integration tests
+        run: npm run integ-test  -- -t 'mainnet alpha - 1 * \+ Simulate on Tenderly \+ Execute on Hardhat fork'
+        env:
+          JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
 
   integration-tests-alpha-router-integration-mixed-routes:
     name: Integration Tests - Alpha Router Integration Mixed Routes
@@ -130,6 +274,10 @@ jobs:
         run: npm run integ-test  -- -t 'Mixed routes'
         env:
           JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
 
   integration-tests-external-class-tests:
     name: Integration Tests - External Class Tests
@@ -160,6 +308,10 @@ jobs:
         run: npm run integ-test  -- -t 'external class tests'
         env:
           JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
 
   integration-tests-quote-for-other-networks:
     name: Integration Tests - Quote For Other Networks
@@ -202,3 +354,7 @@ jobs:
           JSON_RPC_PROVIDER_BNB: ${{ secrets.JSON_RPC_PROVIDER_BNB }}
           JSON_RPC_PROVIDER_AVALANCHE: ${{ secrets.JSON_RPC_PROVIDER_AVALANCHE }}
           JSON_RPC_PROVIDER_BASE: ${{ secrets.JSON_RPC_PROVIDER_BASE }}
+          TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
+          TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
+          TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
+          TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
diff --git a/test/integ/routers/alpha-router/alpha-router.integration.test.ts b/test/integ/routers/alpha-router/alpha-router.integration.test.ts
index 28d155b37..36204e96d 100644
--- a/test/integ/routers/alpha-router/alpha-router.integration.test.ts
+++ b/test/integ/routers/alpha-router/alpha-router.integration.test.ts
@@ -555,7 +555,7 @@ describe('alpha router integration', () => {
    *  tests are 1:1 with routing api integ tests
    */
   for (const tradeType of [TradeType.EXACT_INPUT, TradeType.EXACT_OUTPUT]) {
-    describe(`${ID_TO_NETWORK_NAME(1)} alpha - ${tradeType}`, () => {
+    describe(`${ID_TO_NETWORK_NAME(1)} alpha - ${tradeType.toString()}`, () => {
       describe(`+ Execute on Hardhat Fork`, () => {
         it('erc20 -> erc20', async () => {
           // declaring these to reduce confusion
@@ -2384,6 +2384,8 @@ describe('alpha router integration', () => {
     describe(`exactIn mixedPath routes`, () => {
       describe('+ simulate swap', () => {
         it('BOND -> APE', async () => {
+          jest.setTimeout(1000 * 1000); // 1000s
+
           const tokenIn = BOND_MAINNET;
           const tokenOut = APE_MAINNET;
 
@@ -2922,7 +2924,7 @@ describe('quote for other networks', () => {
         });
 
         if (isTenderlyEnvironmentSet()) {
-          describe(`Simulate + Swap`, function() {
+          describe(`Simulate + Swap ${tradeType.toString()}`, function() {
             // Tenderly does not support Celo
             if ([ChainId.CELO, ChainId.CELO_ALFAJORES].includes(chain)) {
               return;
@@ -2962,6 +2964,7 @@ describe('quote for other networks', () => {
                   // @ts-ignore[TS7053] - complaining about switch being non exhaustive
                   ...DEFAULT_ROUTING_CONFIG_BY_CHAIN[chain],
                   protocols: [Protocol.V3, Protocol.V2],
+                  saveTenderlySimulationIfFailed: true,
                 }
               );
               expect(swap).toBeDefined();
@@ -3017,6 +3020,7 @@ describe('quote for other networks', () => {
                   // @ts-ignore[TS7053] - complaining about switch being non exhaustive
                   ...DEFAULT_ROUTING_CONFIG_BY_CHAIN[chain],
                   protocols: [Protocol.V3, Protocol.V2],
+                  saveTenderlySimulationIfFailed: true,
                 }
               );
               expect(swap).toBeDefined();
@@ -3039,7 +3043,9 @@ describe('quote for other networks', () => {
 
             it(`${native} -> erc20`, async () => {
               const tokenIn = nativeOnChain(chain);
-              const tokenOut = erc2;
+              // TODO ROUTE-64: Remove this once smart-order-router supports ETH native currency on BASE
+              // see https://uniswapteam.slack.com/archives/C021SU4PMR7/p1691593679108459?thread_ts=1691532336.742419&cid=C021SU4PMR7
+              const tokenOut = chain == ChainId.BASE ? USDC_ON(ChainId.BASE) : erc2
               const amount =
                 tradeType == TradeType.EXACT_INPUT
                   ? parseAmount('1', tokenIn)
@@ -3072,6 +3078,7 @@ describe('quote for other networks', () => {
                   // @ts-ignore[TS7053] - complaining about switch being non exhaustive
                   ...DEFAULT_ROUTING_CONFIG_BY_CHAIN[chain],
                   protocols: [Protocol.V3, Protocol.V2],
+                  saveTenderlySimulationIfFailed: true,
                 }
               );
               expect(swap).toBeDefined();
diff --git a/test/test-util/whales.ts b/test/test-util/whales.ts
index 71451bd18..c5c96b36f 100644
--- a/test/test-util/whales.ts
+++ b/test/test-util/whales.ts
@@ -19,7 +19,7 @@ import {
 export const WHALES = (token: Currency): string => {
   switch (token) {
     case Ether.onChain(ChainId.MAINNET) as Currency:
-      return '0x0716a17FBAeE714f1E6aB0f9d59edbC5f09815C0';
+      return '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
     case ExtendedEther.onChain(ChainId.MAINNET):
       return '0x0716a17FBAeE714f1E6aB0f9d59edbC5f09815C0';
     case ExtendedEther.onChain(ChainId.ARBITRUM_ONE):
@@ -28,8 +28,16 @@ export const WHALES = (token: Currency): string => {
       return '0xe7804c37c13166ff0b37f5ae0bb07a3aebb6e245';
     case nativeOnChain(ChainId.GOERLI):
       return '0x08505F42D5666225d5d73B842dAdB87CCA44d1AE';
+    case nativeOnChain(ChainId.BASE):
+      return '0x428ab2ba90eba0a4be7af34c9ac451ab061ac010';
+    case nativeOnChain(ChainId.AVALANCHE):
+      return '0x4aeFa39caEAdD662aE31ab0CE7c8C2c9c0a013E8';
+    case nativeOnChain(ChainId.BNB):
+      return '0x8894E0a0c962CB723c1976a4421c95949bE2D4E3';
+    case nativeOnChain(ChainId.OPTIMISM):
+      return '0x12478d1a60a910C9CbFFb90648766a2bDD5918f5';
     case WETH9[1]:
-      return '0x06920c9fc643de77b99cb7670a944ad31eaaa260';
+      return '0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3';
     case WNATIVE_ON(ChainId.MAINNET):
       return '0xf04a5cc80b1e94c69b48f5ee68a08cd2f09a7c3e';
     case WNATIVE_ON(ChainId.ARBITRUM_ONE):
@@ -40,6 +48,12 @@ export const WHALES = (token: Currency): string => {
       return '0x369582d2010b6ed950b571f4101e3bb9b554876f';
     case WNATIVE_ON(ChainId.BASE):
       return '0x755554f1716d2241d6af94ea1d7dbb1631af9a40';
+    case WNATIVE_ON(ChainId.OPTIMISM):
+      return '0x12478d1a60a910C9CbFFb90648766a2bDD5918f5';
+    case WNATIVE_ON(ChainId.BNB):
+      return '0x59d779BED4dB1E734D3fDa3172d45bc3063eCD69';
+    case WNATIVE_ON(ChainId.AVALANCHE):
+      return '0xba12222222228d8ba445958a75a0704d566bf2c8';
     case USDC_MAINNET:
       return '0x8eb8a3b98659cce290402893d0123abb75e3ab28';
     case UNI_MAINNET:
@@ -64,8 +78,10 @@ export const WHALES = (token: Currency): string => {
       return '0x48520ff9b32d8b5bf87abf789ea7b3c394c95ebe';
     case USDC_ON(ChainId.AVALANCHE):
       return '0x9f8c163cBA728e99993ABe7495F06c0A3c8Ac8b9';
+    case USDC_ON(ChainId.BNB):
+      return '0x8894E0a0c962CB723c1976a4421c95949bE2D4E3';
     case USDC_ON(ChainId.BASE):
-      return '0x389bfa91ad0d143e8cb26c15cb52d942ee9651f7';
+      return '0x4a3636608d7bc5776cb19eb72caa36ebb9ea683b';
     case DAI_ON(ChainId.GOERLI):
       return '0x20918f71e99c09ae2ac3e33dbde33457d3be01f4';
     case DAI_ON(ChainId.SEPOLIA):