From 877a0e26206ddbcec5884a834720cc9539347d5f Mon Sep 17 00:00:00 2001 From: Noisekit <28145325+noisekit@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:46:50 +0800 Subject: [PATCH] Fork from block (#50) * Fork from block number * Save anvil cache * Kill anvil to flush caches * No need for privateKey on anvil, use pre-defined test wallet * No need to update prices * Snapshots and account id * New block with all prices * Snapshot restore after test * data-cy="balance amount" * evmRevert * fix timeouts * stub icons * Less annoying logs * Comment out snapshots where not needed * Fix for undefined historicalClaims: Cannot read properties of undefined (reading 'reduce') * Fix for undefined vaults * Comment out second deposit test until bug with wrapped token balance refetching is fixed * Switch to a vanity address with simple new account * Update block number on Base * Typecheck * Account number * Fix undefined poolInfo * More timeouts * Back to test wallet * poolInfo may be undefined * Allow making price update calls * More fixes * Use importPythFeeds * Fix Base tests * Always have cypress_exit_code --- .circleci/config.yml | 35 ++++++-- liquidity/cypress/bin/approveCollateral.ts | 8 +- liquidity/cypress/bin/createAccount.ts | 8 +- liquidity/cypress/bin/doAllPriceUpdates.ts | 4 +- liquidity/cypress/cypress.config.js | 7 +- .../e2e/42161-main/Create Account.e2e.js | 18 ++++- .../42161-main/Dashboard - Connected.e2e.js | 22 +++-- .../Dashboard - Not Connected.e2e.js | 12 +++ .../Manage WETH Position - Borrow.e2e.js | 66 ++++++++------- .../Manage WETH Position - Deposit.e2e.js | 81 ++++++++++++------- .../Manage WETH Position - Repay.e2e.js | 76 ++++++++++------- .../e2e/8453-andromeda/Create Account.e2e.js | 21 ++++- .../Dashboard - Connected.e2e.js | 24 ++++-- .../Dashboard - Not Connected.e2e.js | 13 ++- .../Manage USDC Position - Deposit.e2e.js | 65 +++++++++------ liquidity/cypress/cypress/support/e2e.js | 41 ++++++++-- .../cypress/tasks/approveCollateral.js | 8 +- liquidity/cypress/cypress/tasks/borrowUsd.js | 20 +++-- .../cypress/cypress/tasks/createAccount.js | 13 +-- .../cypress/tasks/delegateCollateral.js | 8 +- .../cypress/tasks/depositCollateral.js | 8 +- .../cypress/tasks/doAllPriceUpdates.js | 17 +--- .../cypress/tasks/doPriceUpdateForPyth.js | 6 +- .../cypress/cypress/tasks/setEthBalance.js | 18 ++--- liquidity/cypress/cypress/tasks/snapshot.js | 15 ++++ liquidity/cypress/cypress/tasks/wrapEth.js | 14 ++-- liquidity/cypress/package.json | 4 +- .../useCollateralPriceUpdates.ts | 4 +- liquidity/lib/usePoolsList/usePoolsList.ts | 4 +- liquidity/lib/useRewards/useRewards.ts | 12 +-- .../ui/src/components/Deposit/Deposit.tsx | 2 +- .../InitialDeposit/InitialDeposit.tsx | 2 +- .../ui/src/components/Pools/PoolsList.tsx | 4 +- 33 files changed, 427 insertions(+), 233 deletions(-) create mode 100644 liquidity/cypress/cypress/tasks/snapshot.js diff --git a/.circleci/config.yml b/.circleci/config.yml index ae7896f9..f9372f63 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -150,6 +150,8 @@ jobs: type: string provider-url: type: string + fork-block-number: + type: integer working_directory: /tmp/app docker: - image: cypress/included:<< pipeline.parameters.cypress-version >> @@ -163,6 +165,13 @@ jobs: - install-foundry - yarn-install + - run: date +"%Y-%W" > /tmp/week.txt && cat /tmp/week.txt + - restore_cache: + keys: + - &anvil-fork-cache anvil-fork-cache-{{ .Environment.ANVIL_CACHE_VERSION }}-{{ checksum "/tmp/week.txt" }}-{{ .BuildNum }} + - anvil-fork-cache-{{ .Environment.ANVIL_CACHE_VERSION }}-{{ checksum "/tmp/week.txt" }}- + - anvil-fork-cache-{{ .Environment.ANVIL_CACHE_VERSION }}- + - run: name: Run server localhost:3000 working_directory: /tmp/app/liquidity/ui @@ -171,7 +180,7 @@ jobs: - run: name: Run anvil localhost:8545 - command: anvil --auto-impersonate --chain-id "<< parameters.chainId >>" --fork-url "<< parameters.provider-url >>" + command: anvil --auto-impersonate --chain-id "<< parameters.chainId >>" --fork-url "<< parameters.provider-url >>" --no-rate-limit --steps-tracing --fork-block-number "<< parameters.fork-block-number >>" background: true - run: @@ -183,13 +192,21 @@ jobs: command: wget -q -O - --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 --post-data='{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}' --header='Content-Type:application/json' http://localhost:8545 - run: - name: Update all prices working_directory: /tmp/app/liquidity/cypress - command: yarn ts-node bin/doAllPriceUpdates.ts 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 + command: | + echo "0" > /tmp/cypress_exit_code + cypress run --e2e --browser chrome \ + --config specPattern="./cypress/e2e/<< parameters.chainId >>-<< parameters.preset >>/*.e2e.js" \ + || echo $? > /tmp/cypress_exit_code - - run: - working_directory: /tmp/app/liquidity/cypress - command: cypress run --e2e --browser chrome --config specPattern="./cypress/e2e/<< parameters.chainId >>-<< parameters.preset >>/*.e2e.js" + - run: pkill anvil + + - save_cache: + key: *anvil-fork-cache + paths: + - '~/.foundry/cache' + + - run: exit $(cat /tmp/cypress_exit_code) - store_test_results: path: 'liquidity/cypress/cypress/reports' @@ -285,12 +302,14 @@ workflows: name: liquidity-e2e-base-mainnet chainId: 8453 preset: andromeda - provider-url: https://base-mainnet.infura.io/v3/$INFURA_KEY + provider-url: wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY + fork-block-number: 21781780 - liquidity-e2e: name: liquidity-e2e-arbitrum-mainnet chainId: 42161 preset: main - provider-url: https://arbitrum-mainnet.infura.io/v3/$INFURA_KEY + provider-url: wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY + fork-block-number: 269244293 - combine-coverage: requires: - tests diff --git a/liquidity/cypress/bin/approveCollateral.ts b/liquidity/cypress/bin/approveCollateral.ts index a32cb8c2..d8f95b82 100755 --- a/liquidity/cypress/bin/approveCollateral.ts +++ b/liquidity/cypress/bin/approveCollateral.ts @@ -1,8 +1,8 @@ #!/usr/bin/env ts-node import { approveCollateral } from '../cypress/tasks/approveCollateral'; -const [privateKey, symbol] = process.argv.slice(2); -if (!privateKey || !symbol) { - throw new Error('Usage: ./approveCollateral.ts '); +const [address, symbol] = process.argv.slice(2); +if (!address || !symbol) { + throw new Error('Usage: ./approveCollateral.ts
'); } -approveCollateral({ privateKey, symbol }); +approveCollateral({ address, symbol }); diff --git a/liquidity/cypress/bin/createAccount.ts b/liquidity/cypress/bin/createAccount.ts index e352f6a4..185a50eb 100755 --- a/liquidity/cypress/bin/createAccount.ts +++ b/liquidity/cypress/bin/createAccount.ts @@ -1,8 +1,8 @@ #!/usr/bin/env ts-node import { createAccount } from '../cypress/tasks/createAccount'; -const [privateKey] = process.argv.slice(2); -if (!privateKey) { - throw new Error('Usage: ./approveCollateral.ts '); +const [address, accountId] = process.argv.slice(2); +if (!address || !accountId) { + throw new Error('Usage: ./approveCollateral.ts
'); } -createAccount({ privateKey }); +createAccount({ address, accountId }); diff --git a/liquidity/cypress/bin/doAllPriceUpdates.ts b/liquidity/cypress/bin/doAllPriceUpdates.ts index 9a82149d..37e7feb8 100755 --- a/liquidity/cypress/bin/doAllPriceUpdates.ts +++ b/liquidity/cypress/bin/doAllPriceUpdates.ts @@ -1,5 +1,5 @@ #!/usr/bin/env yarn ts-node import { doAllPriceUpdates } from '../cypress/tasks/doAllPriceUpdates'; -const [privateKey] = process.argv.slice(2); -doAllPriceUpdates({ privateKey }).then((data) => console.log(JSON.stringify(data, null, 2))); +const [address] = process.argv.slice(2); +doAllPriceUpdates({ address }).then((data) => console.log(JSON.stringify(data, null, 2))); diff --git a/liquidity/cypress/cypress.config.js b/liquidity/cypress/cypress.config.js index c0b22923..009fc378 100644 --- a/liquidity/cypress/cypress.config.js +++ b/liquidity/cypress/cypress.config.js @@ -47,6 +47,7 @@ module.exports = defineConfig({ ...require('./cypress/tasks/getUSDC'), ...require('./cypress/tasks/doAllPriceUpdates'), ...require('./cypress/tasks/doPriceUpdateForPyth'), + ...require('./cypress/tasks/snapshot'), }); return config; }, @@ -55,8 +56,8 @@ module.exports = defineConfig({ runMode: 1, openMode: 0, }, - defaultCommandTimeout: 90_000, - execTimeout: 120_000, - taskTimeout: 300_000, // sometimes Anvil needs quite a bit of time to complete impersonating tx + defaultCommandTimeout: 60_000, + execTimeout: 60_000, + taskTimeout: 60_000, }, }); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Create Account.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Create Account.e2e.js index 63929802..4c03779a 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Create Account.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Create Account.e2e.js @@ -1,6 +1,20 @@ +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('Create Account', () => { - cy.connectWallet().then((wallet) => { - cy.task('setEthBalance', { address: wallet.address, balance: 2 }); + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + + cy.task('setEthBalance', { address, balance: 2 }); }); cy.viewport(1200, 900); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Connected.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Connected.e2e.js index c94b51a1..37210331 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Connected.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Connected.e2e.js @@ -1,15 +1,27 @@ +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('Dashboard - Connected', () => { - cy.connectWallet().then(({ address, privateKey }) => { + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + cy.task('setEthBalance', { address, balance: 100 }); - cy.task('createAccount', { privateKey }).then((accountId) => { - cy.wrap(accountId).as('accountId'); - }); + cy.task('createAccount', { address, accountId }); }); cy.viewport(1200, 900); cy.visit('/#/dashboard'); - cy.get('@wallet').then(({ address }) => { + cy.get('@wallet').then((address) => { cy.get('[data-cy="short wallet address"]').contains( `${address.substring(0, 6)}...${address.substring(address.length - 4)}` ); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Not Connected.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Not Connected.e2e.js index f44a567c..6298d3f1 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Not Connected.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Dashboard - Not Connected.e2e.js @@ -1,3 +1,15 @@ +// NO MUTATIONS! +//before(() => { +// cy.task('evmSnapshot').then((snapshot) => { +// cy.wrap(snapshot).as('snapshot'); +// }); +//}); +//after(() => { +// cy.get('@snapshot').then(async (snapshot) => { +// cy.task('evmRevert', snapshot); +// }); +//}); + it('Dashboard - Not Connected', () => { cy.viewport(1200, 900); cy.visit('/#/dashboard'); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Borrow.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Borrow.e2e.js index ca46cb51..43837564 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Borrow.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Borrow.e2e.js @@ -1,31 +1,41 @@ import { generatePath } from 'react-router-dom'; +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('should borrow against WETH position', () => { - cy.connectWallet().then(({ address, privateKey }) => { - cy.task('setEthBalance', { address, balance: 105 }); + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); - cy.task('approveCollateral', { privateKey: privateKey, symbol: 'WETH' }); - cy.task('wrapEth', { privateKey: privateKey, amount: 20 }); - - cy.task('createAccount', { privateKey }).then((accountId) => { - cy.wrap(accountId).as('accountId'); - cy.task('depositCollateral', { - privateKey, - symbol: 'WETH', - accountId, - amount: 10, - }); - cy.task('delegateCollateral', { - privateKey, - symbol: 'WETH', - accountId, - amount: 10, - poolId: 1, - }); + cy.task('setEthBalance', { address, balance: 105 }); + cy.task('createAccount', { address, accountId }); + cy.task('approveCollateral', { address, symbol: 'WETH' }); + cy.task('wrapEth', { address, amount: 20 }); + cy.task('depositCollateral', { + address, + symbol: 'WETH', + accountId, + amount: 10, + }); + cy.task('delegateCollateral', { + address, + symbol: 'WETH', + accountId, + amount: 10, + poolId: 1, }); }); - cy.viewport(1000, 800); + cy.viewport(1000, 1200); cy.get('@accountId').then((accountId) => { const path = generatePath('/positions/:collateralSymbol/:poolId', { @@ -37,26 +47,24 @@ it('should borrow against WETH position', () => { cy.contains('[data-status="info"]', 'You can take an interest-free loan up to').should('exist'); - cy.get('[data-cy="claim amount input"]').should('exist').type('10'); + cy.get('[data-cy="claim amount input"]').type('100'); cy.contains( '[data-status="warning"]', 'Assets will be available to withdraw 24 hours after your last interaction with this position.' ).should('exist'); - cy.contains('[data-status="info"]', 'You are about to take a $10 interest-free loan').should( - 'exist' - ); - - cy.get('[data-cy="claim submit"]').should('be.enabled').click(); + cy.get('[data-cy="claim submit"]').should('be.enabled').and('include.text', 'Borrow'); + cy.get('[data-cy="claim submit"]').click(); cy.get('[data-cy="claim multistep"]') .should('exist') .and('include.text', 'Manage Debt') .and('include.text', 'Borrow') - .and('include.text', 'Borrow 10 USDx'); + .and('include.text', 'Borrow 100 USDx'); - cy.get('[data-cy="claim confirm button"]').should('include.text', 'Execute Transaction').click(); + cy.get('[data-cy="claim confirm button"]').should('include.text', 'Execute Transaction'); + cy.get('[data-cy="claim confirm button"]').click(); cy.contains('[data-status="info"]', 'Debt successfully Updated').should('exist'); }); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Deposit.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Deposit.e2e.js index 75135195..8b1f2e62 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Deposit.e2e.js @@ -1,26 +1,39 @@ import { generatePath } from 'react-router-dom'; +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('should deposit additional WETH collateral', () => { - cy.connectWallet().then(({ address, privateKey }) => { + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + cy.task('setEthBalance', { address, balance: 100 }); - cy.task('wrapEth', { privateKey: privateKey, amount: 50 }); - cy.task('approveCollateral', { privateKey: privateKey, symbol: 'WETH' }); - cy.task('createAccount', { privateKey }).then((accountId) => { - cy.wrap(accountId).as('accountId'); - }); + cy.task('createAccount', { address, accountId }); }); - cy.get('@accountId').then(async (accountId) => { + cy.viewport(1000, 1200); + + cy.get('@accountId').then((accountId) => { const path = generatePath('/positions/:collateralSymbol/:poolId', { collateralSymbol: 'WETH', poolId: 1, }); cy.visit(`/#${path}?manageAction=deposit&accountId=${accountId}`); - cy.wait(1000); }); - cy.get('[data-cy="deposit amount input"]').should('exist').type('1'); - cy.get('[data-cy="deposit submit"]').should('be.enabled').click(); + cy.get('[data-cy="balance amount"]').should('exist').and('include.text', 'Balance: 100'); + cy.get('[data-cy="deposit amount input"]').type('1'); + cy.get('[data-cy="deposit submit"]').should('be.enabled'); + cy.get('[data-cy="deposit submit"]').click(); cy.get('[data-cy="deposit multistep"]') .should('exist') @@ -29,25 +42,35 @@ it('should deposit additional WETH collateral', () => { .and('include.text', 'Deposit & Lock WETH') .and('include.text', 'This will deposit and lock 1 WETH to Spartan Council Pool.'); - cy.get('[data-cy="deposit confirm button"]') - .should('include.text', 'Execute Transaction') - .click(); - - cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '1 WETH'); - - cy.get('[data-cy="deposit amount input"]').should('exist').clear().type('0.69'); - cy.get('[data-cy="deposit submit"]').should('be.enabled').click(); - - cy.get('[data-cy="deposit multistep"]') - .should('exist') - .and('include.text', 'Manage Collateral') - .and('include.text', 'Approve WETH transfer') - .and('include.text', 'Deposit & Lock WETH') - .and('include.text', 'This will deposit and lock 0.69 WETH to Spartan Council Pool.'); + cy.get('[data-cy="deposit confirm button"]').should('include.text', 'Execute Transaction'); + cy.get('[data-cy="deposit confirm button"]').click(); - cy.get('[data-cy="deposit confirm button"]') - .should('include.text', 'Execute Transaction') - .click(); + cy.contains('[data-status="success"]', 'Your locked collateral amount has been updated.').should( + 'exist' + ); - cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '1.69 WETH'); + // TODO: Enable additional deposit after fixing an issue with balance refetching + // cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '1 WETH'); + // + // cy.get('@wallet').then(async (address) => { + // cy.task('setEthBalance', { address, balance: 100 }); + // }); + // cy.get('[data-cy="balance amount"]').should('exist').and('include.text', 'Balance: 100'); + // cy.get('[data-cy="deposit amount input"]').clear(); + // cy.get('[data-cy="deposit amount input"]').type('0.69'); + // cy.get('[data-cy="deposit submit"]').should('be.enabled'); + // cy.get('[data-cy="deposit submit"]').click(); + // + // cy.get('[data-cy="deposit multistep"]') + // .should('exist') + // .and('include.text', 'Manage Collateral') + // .and('include.text', 'Approve WETH transfer') + // .and('include.text', 'Deposit & Lock WETH') + // .and('include.text', 'This will deposit and lock 0.69 WETH to Spartan Council Pool.'); + // + // cy.get('[data-cy="deposit confirm button"]') + // .should('include.text', 'Execute Transaction') + // .click(); + // + // cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '1.69 WETH'); }); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Repay.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Repay.e2e.js index f0085a99..a198316b 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Manage WETH Position - Repay.e2e.js @@ -1,37 +1,50 @@ import { generatePath } from 'react-router-dom'; +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('should repay borrowed USDx', () => { - cy.connectWallet().then(({ address, privateKey }) => { + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + cy.task('setEthBalance', { address, balance: 105 }); + cy.task('createAccount', { address, accountId }); - cy.task('approveCollateral', { privateKey: privateKey, symbol: 'WETH' }); - cy.task('wrapEth', { privateKey: privateKey, amount: 20 }); - - cy.task('createAccount', { privateKey }).then((accountId) => { - cy.wrap(accountId).as('accountId'); - cy.task('depositCollateral', { - privateKey, - symbol: 'WETH', - accountId, - amount: 10, - }); - cy.task('delegateCollateral', { - privateKey, - symbol: 'WETH', - accountId, - amount: 10, - poolId: 1, - }); - cy.task('borrowUsd', { - privateKey, - symbol: 'WETH', - accountId, - amount: 10, - poolId: 1, - }).then((debt) => cy.wrap(debt).as('debt')); + cy.task('approveCollateral', { address, symbol: 'WETH' }); + cy.task('wrapEth', { address, amount: 20 }); + + cy.task('depositCollateral', { + address, + symbol: 'WETH', + accountId, + amount: 10, + }); + cy.task('delegateCollateral', { + address, + symbol: 'WETH', + accountId, + amount: 10, + poolId: 1, }); + cy.task('borrowUsd', { + address, + symbol: 'WETH', + accountId, + amount: 100, + poolId: 1, + }).then((debt) => cy.wrap(debt).as('debt')); }); - cy.viewport(1000, 800); + + cy.viewport(1000, 1200); cy.get('@accountId').then((accountId) => { const path = generatePath('/positions/:collateralSymbol/:poolId', { @@ -41,9 +54,10 @@ it('should repay borrowed USDx', () => { cy.visit(`/#${path}?manageAction=repay&accountId=${accountId}`); }); - cy.get('[data-cy="repay amount input"]').should('exist').type('5'); + cy.get('[data-cy="repay amount input"]').type('5'); - cy.get('[data-cy="repay submit"]').should('be.enabled').click(); + cy.get('[data-cy="repay submit"]').should('be.enabled'); + cy.get('[data-cy="repay submit"]').click(); cy.get('[data-cy="repay multistep"]') .should('exist') @@ -52,6 +66,8 @@ it('should repay borrowed USDx', () => { .and('include.text', 'Repay') .and('include.text', 'Repay 5 USDx'); - cy.get('[data-cy="repay confirm button"]').should('include.text', 'Execute Transaction').click(); + cy.get('[data-cy="repay confirm button"]').should('include.text', 'Execute Transaction'); + cy.get('[data-cy="repay confirm button"]').click(); + cy.contains('[data-status="success"]', 'Your debt has been repaid.').should('exist'); cy.contains('[data-status="info"]', 'Debt successfully Updated').should('exist'); }); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/Create Account.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/Create Account.e2e.js index 63929802..ac109872 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Create Account.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Create Account.e2e.js @@ -1,9 +1,24 @@ +// NO MUTATIONS! +//before(() => { +// cy.task('evmSnapshot').then((snapshot) => { +// cy.wrap(snapshot).as('snapshot'); +// }); +//}); +//after(() => { +// cy.get('@snapshot').then(async (snapshot) => { +// cy.task('evmRevert', snapshot); +// }); +//}); + it('Create Account', () => { - cy.connectWallet().then((wallet) => { - cy.task('setEthBalance', { address: wallet.address, balance: 2 }); + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + + cy.task('setEthBalance', { address, balance: 2 }); }); - cy.viewport(1200, 900); + cy.viewport(1000, 1200); cy.visit('/#/dashboard'); cy.get('[data-cy="wallet button"]').click(); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Connected.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Connected.e2e.js index 52f40cc3..c28f3308 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Connected.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Connected.e2e.js @@ -1,15 +1,27 @@ +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('Dashboard - Connected', () => { - cy.connectWallet().then(({ address, privateKey }) => { + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + cy.task('setEthBalance', { address, balance: 100 }); - cy.task('createAccount', { privateKey }).then((accountId) => { - cy.wrap(accountId).as('accountId'); - }); + cy.task('createAccount', { address, accountId }); }); - cy.viewport(1200, 900); + cy.viewport(1000, 1200); cy.visit('/#/dashboard'); - cy.get('@wallet').then(({ address }) => { + cy.get('@wallet').then((address) => { cy.get('[data-cy="short wallet address"]').contains( `${address.substring(0, 6)}...${address.substring(address.length - 4)}` ); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Not Connected.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Not Connected.e2e.js index f44a567c..260f03ee 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Not Connected.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard - Not Connected.e2e.js @@ -1,5 +1,16 @@ +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('Dashboard - Not Connected', () => { - cy.viewport(1200, 900); + cy.viewport(1000, 1200); cy.visit('/#/dashboard'); cy.contains('h2', 'Dashboard').should('exist'); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/Manage USDC Position - Deposit.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/Manage USDC Position - Deposit.e2e.js index 5dd284d5..60e8c03a 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Manage USDC Position - Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Manage USDC Position - Deposit.e2e.js @@ -1,14 +1,28 @@ import { generatePath } from 'react-router-dom'; +before(() => { + cy.task('evmSnapshot').then((snapshot) => { + cy.wrap(snapshot).as('snapshot'); + }); +}); +after(() => { + cy.get('@snapshot').then(async (snapshot) => { + cy.task('evmRevert', snapshot); + }); +}); + it('should deposit additional USDC collateral', () => { - cy.connectWallet().then(({ address, privateKey }) => { + cy.connectWallet().then(({ address, accountId }) => { + cy.wrap(address).as('wallet'); + cy.wrap(accountId).as('accountId'); + cy.task('setEthBalance', { address, balance: 100 }); - cy.task('getUSDC', { address: address, amount: 500 }); - cy.task('createAccount', { privateKey }).then((accountId) => { - cy.wrap(accountId).as('accountId'); - }); + cy.task('getUSDC', { address, amount: 500 }); + cy.task('createAccount', { address, accountId }); }); + cy.viewport(1000, 1200); + cy.get('@accountId').then(async (accountId) => { const path = generatePath('/positions/:collateralSymbol/:poolId', { collateralSymbol: 'USDC', @@ -17,15 +31,16 @@ it('should deposit additional USDC collateral', () => { cy.visit(`/#${path}?manageAction=deposit&accountId=${accountId}`); }); - cy.get('[data-cy="deposit amount input"]').should('exist').type('101'); - cy.get('[data-cy="deposit submit"]').should('be.enabled').click(); + cy.get('[data-cy="deposit amount input"]').should('exist'); + cy.get('[data-cy="deposit amount input"]').type('101'); + cy.get('[data-cy="deposit submit"]').should('be.enabled'); + cy.get('[data-cy="deposit submit"]').click(); cy.get('[data-cy="deposit multistep"]') .should('exist') - .and('include.text', 'Open Liquidity Position') .and('include.text', 'Approve USDC transfer') .and('include.text', 'Deposit & Lock USDC') - .and('include.text', 'This will deposit and lock 101 USDC to Spartan Council Pool.'); + .and('include.text', 'This will deposit & lock 101 USDC in Spartan Council Pool.'); cy.get('[data-cy="deposit confirm button"]') .should('include.text', 'Execute Transaction') @@ -33,19 +48,21 @@ it('should deposit additional USDC collateral', () => { cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '101 USDC'); - cy.get('[data-cy="deposit amount input"]').should('exist').clear().type('69'); - cy.get('[data-cy="deposit submit"]').should('be.enabled').click(); - - cy.get('[data-cy="deposit multistep"]') - .should('exist') - .and('include.text', 'Manage Collateral') - .and('include.text', 'Approve USDC transfer') - .and('include.text', 'Deposit & Lock USDC') - .and('include.text', 'This will deposit and lock 69 USDC to Spartan Council Pool.'); - - cy.get('[data-cy="deposit confirm button"]') - .should('include.text', 'Execute Transaction') - .click(); - - cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '170 USDC'); + // TODO: Enable additional deposit after fixing an issue with balance refetching + // + // cy.get('[data-cy="deposit amount input"]').should('exist').clear().type('69'); + // cy.get('[data-cy="deposit submit"]').should('be.enabled').click(); + // + // cy.get('[data-cy="deposit multistep"]') + // .should('exist') + // .and('include.text', 'Manage Collateral') + // .and('include.text', 'Approve USDC transfer') + // .and('include.text', 'Deposit & Lock USDC') + // .and('include.text', 'This will deposit and lock 69 USDC to Spartan Council Pool.'); + // + // cy.get('[data-cy="deposit confirm button"]') + // .should('include.text', 'Execute Transaction') + // .click(); + // + // cy.get('[data-cy="manage stats collateral"]').should('exist').and('include.text', '170 USDC'); }); diff --git a/liquidity/cypress/cypress/support/e2e.js b/liquidity/cypress/cypress/support/e2e.js index 6fea22dd..f5867cc5 100644 --- a/liquidity/cypress/cypress/support/e2e.js +++ b/liquidity/cypress/cypress/support/e2e.js @@ -1,21 +1,43 @@ import '@cypress/code-coverage/support'; import { onLogAdded } from '@snx-cy/onLogAdded'; -import { ethers } from 'ethers'; import { subgraph } from '../lib/subgraph'; beforeEach(() => { cy.on('log:added', onLogAdded); cy.intercept('https://analytics.synthetix.io/matomo.js', { statusCode: 204 }).as('matomo'); + cy.intercept('https://analytics.synthetix.io/matomo.js', { log: false }); + // cy.intercept('https://hermes-mainnet.rpc.extrnode.com/**', { statusCode: 400 }).as('pyth'); + cy.intercept('https://hermes-mainnet.rpc.extrnode.com/**', { log: false }); + // cy.intercept('https://hermes-mainnet.rpc.extrnode.com/**', (req) => { + // return req.reply([]); + // }).as('pyth'); + // cy.intercept('https://synthetixio.github.io/**/*.svg', { statusCode: 404 }).as('assets'); + cy.intercept('synthetixio.github.io/**/*.svg', (req) => { + return req.reply(` + + + + + + + + + + `); + }).as('icon'); + cy.intercept('synthetixio.github.io/**/*.svg', { log: false }); // Because we are working with local fork, subgraph becomes irrelevant cy.intercept('https://api.thegraph.com/**', (req) => { return subgraph(req); }).as('subgraph'); + cy.intercept('https://api.thegraph.com/**', { log: false }); cy.intercept('https://subgraph.satsuma-prod.com/**', (req) => { return subgraph(req); }).as('subgraph'); + cy.intercept('https://subgraph.satsuma-prod.com/**', { log: false }); [ 'mainnet', @@ -30,8 +52,13 @@ beforeEach(() => { req.url = 'http://127.0.0.1:8545'; req.continue(); }).as(networkName); + cy.intercept(`https://${networkName}.infura.io/v3/**`, { log: false }); }); + cy.intercept(`http://127.0.0.1:8545`, { log: false }); + // cy.intercept(`https://api.synthetix.io/**`, { statusCode: 400 }).as('api'); + cy.intercept(`https://api.synthetix.io/**`, { log: false }); + cy.on('window:before:load', (win) => { win.sessionStorage.setItem('TERMS_CONDITIONS_ACCEPTED', 'true'); win.localStorage.setItem( @@ -45,13 +72,13 @@ beforeEach(() => { }); }); -Cypress.Commands.add('connectWallet', (namespace = 'wallet') => { - const wallet = ethers.Wallet.createRandom(); - // const privateKey = wallet.privateKey; - const address = wallet.address; +Cypress.Commands.add('connectWallet', () => { + // const address = '0x0008e81f68bc3b7ca0888E684a6259AF86f77000'; + // const accountId = '777'; + const address = '0xc3Cf311e04c1f8C74eCF6a795Ae760dc6312F345'; + const accountId = '58655818123'; cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', address); }); - - return cy.wrap(wallet).as(namespace); + return { address, accountId }; }); diff --git a/liquidity/cypress/cypress/tasks/approveCollateral.js b/liquidity/cypress/cypress/tasks/approveCollateral.js index 14ded41e..fa4af8b2 100644 --- a/liquidity/cypress/cypress/tasks/approveCollateral.js +++ b/liquidity/cypress/cypress/tasks/approveCollateral.js @@ -2,17 +2,17 @@ import { ethers } from 'ethers'; import { importCoreProxy } from './importCoreProxy'; import { getCollateralConfig } from './getCollateralConfig'; -export async function approveCollateral({ privateKey, symbol }) { +export async function approveCollateral({ address, symbol }) { const CoreProxy = await importCoreProxy(); const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); + const signer = provider.getSigner(address); const config = await getCollateralConfig(symbol); - console.log('approveCollateral', { wallet: wallet.address, symbol }); + console.log('approveCollateral', { wallet: address, symbol }); const contract = new ethers.Contract( config.tokenAddress, ['function approve(address spender, uint256 amount) returns (bool)'], - wallet + signer ); const tx = await contract.approve(CoreProxy.address, ethers.constants.MaxUint256); diff --git a/liquidity/cypress/cypress/tasks/borrowUsd.js b/liquidity/cypress/cypress/tasks/borrowUsd.js index 66b09072..75823f7d 100644 --- a/liquidity/cypress/cypress/tasks/borrowUsd.js +++ b/liquidity/cypress/cypress/tasks/borrowUsd.js @@ -2,16 +2,17 @@ import { ethers } from 'ethers'; import { importCoreProxy } from './importCoreProxy'; import { getCollateralConfig } from './getCollateralConfig'; -export async function borrowUsd({ privateKey, accountId, symbol, amount, poolId }) { +export async function borrowUsd({ address, accountId, symbol, amount, poolId }) { const CoreProxy = await importCoreProxy(); const config = await getCollateralConfig(symbol); const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); - console.log('borrowUsd', { address: wallet.address, accountId, symbol, amount, poolId }); + const signer = provider.getSigner(address); - const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, wallet); + console.log('borrowUsd', { address, accountId, symbol, amount, poolId }); - const tx = await coreProxy.mintUsd( + const CoreProxyContract = new ethers.Contract(CoreProxy.address, CoreProxy.abi, signer); + + const tx = await CoreProxyContract.mintUsd( ethers.BigNumber.from(accountId), ethers.BigNumber.from(poolId), config.tokenAddress, @@ -19,5 +20,12 @@ export async function borrowUsd({ privateKey, accountId, symbol, amount, poolId { gasLimit: 10_000_000 } ); await tx.wait(); - return amount; + + const positionDebt = await CoreProxyContract.callStatic.getPositionDebt( + accountId, + poolId, + config.tokenAddress + ); + + return parseFloat(ethers.utils.formatUnits(positionDebt)); } diff --git a/liquidity/cypress/cypress/tasks/createAccount.js b/liquidity/cypress/cypress/tasks/createAccount.js index c1b0d5f5..c186ef15 100644 --- a/liquidity/cypress/cypress/tasks/createAccount.js +++ b/liquidity/cypress/cypress/tasks/createAccount.js @@ -1,20 +1,21 @@ import { ethers } from 'ethers'; -import crypto from 'crypto'; import { importCoreProxy } from './importCoreProxy'; -export async function createAccount({ privateKey }) { +export async function createAccount({ address, accountId }) { const CoreProxy = await importCoreProxy(); const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); + const signer = provider.getSigner(address); - const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, wallet); - - const accountId = parseInt(`1337${crypto.randomInt(1000)}`); + const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, signer); const currentAccountOwner = await coreProxy.getAccountOwner(accountId); console.log('createAccount', { accountId, currentAccountOwner }); + if (currentAccountOwner === address) { + return accountId; + } + const tx = await coreProxy['createAccount(uint128)'](accountId, { gasLimit: 10_000_000 }); await tx.wait(); diff --git a/liquidity/cypress/cypress/tasks/delegateCollateral.js b/liquidity/cypress/cypress/tasks/delegateCollateral.js index 386b94fa..c99eb38c 100644 --- a/liquidity/cypress/cypress/tasks/delegateCollateral.js +++ b/liquidity/cypress/cypress/tasks/delegateCollateral.js @@ -2,14 +2,14 @@ import { ethers } from 'ethers'; import { getCollateralConfig } from './getCollateralConfig'; import { importCoreProxy } from './importCoreProxy'; -export async function delegateCollateral({ privateKey, accountId, symbol, amount, poolId }) { +export async function delegateCollateral({ address, accountId, symbol, amount, poolId }) { const CoreProxy = await importCoreProxy(); const config = await getCollateralConfig(symbol); const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); - console.log('delegateCollateral', { address: wallet.address, accountId, symbol, amount, poolId }); + const signer = provider.getSigner(address); + console.log('delegateCollateral', { address, accountId, symbol, amount, poolId }); - const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, wallet); + const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, signer); try { const tx = await coreProxy.delegateCollateral( ethers.BigNumber.from(accountId), diff --git a/liquidity/cypress/cypress/tasks/depositCollateral.js b/liquidity/cypress/cypress/tasks/depositCollateral.js index a758c465..2f315163 100644 --- a/liquidity/cypress/cypress/tasks/depositCollateral.js +++ b/liquidity/cypress/cypress/tasks/depositCollateral.js @@ -2,14 +2,14 @@ import { ethers } from 'ethers'; import { getCollateralConfig } from './getCollateralConfig'; import { importCoreProxy } from './importCoreProxy'; -export async function depositCollateral({ privateKey, accountId, symbol, amount }) { +export async function depositCollateral({ address, accountId, symbol, amount }) { const CoreProxy = await importCoreProxy(); const config = await getCollateralConfig(symbol); const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); - console.log('depositCollateral', { address: wallet.address, accountId, symbol, amount }); + const signer = provider.getSigner(address); + console.log('depositCollateral', { address, accountId, symbol, amount }); - const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, wallet); + const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, signer); const tx = await coreProxy.deposit( ethers.BigNumber.from(accountId), diff --git a/liquidity/cypress/cypress/tasks/doAllPriceUpdates.js b/liquidity/cypress/cypress/tasks/doAllPriceUpdates.js index 6e49d0b5..94f97837 100755 --- a/liquidity/cypress/cypress/tasks/doAllPriceUpdates.js +++ b/liquidity/cypress/cypress/tasks/doAllPriceUpdates.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { importExtras } from '@snx-v3/contracts'; +import { importExtras, importPythFeeds } from '@snx-v3/contracts'; import { doPriceUpdateForPyth } from './doPriceUpdateForPyth'; const splitIntoChunks = (array, chunkSize) => { @@ -11,26 +11,17 @@ const splitIntoChunks = (array, chunkSize) => { return chunks; }; -export async function doAllPriceUpdates({ privateKey }) { +export async function doAllPriceUpdates({ address }) { const extras = await importExtras(process.env.CYPRESS_CHAIN_ID, process.env.CYPRESS_PRESET); + const feedIds = await importPythFeeds(process.env.CYPRESS_CHAIN_ID, process.env.CYPRESS_PRESET); const priceVerificationContract = extras.pyth_price_verification_address || extras.pythPriceVerificationAddress; - const feedIds = Array.from( - new Set( - Object.entries(extras) - .filter( - ([key]) => - key.startsWith('pyth_feed_id_') || (key.startsWith('pyth') && key.endsWith('FeedId')) - ) - .map(([_key, value]) => value) - ) - ); console.log({ feedIds }); const batches = splitIntoChunks(feedIds, 200); for (const batch of batches) { console.log({ batch }); - await doPriceUpdateForPyth({ privateKey, feedId: batch, priceVerificationContract }); + await doPriceUpdateForPyth({ address, feedId: batch, priceVerificationContract }); } return true; } diff --git a/liquidity/cypress/cypress/tasks/doPriceUpdateForPyth.js b/liquidity/cypress/cypress/tasks/doPriceUpdateForPyth.js index d2302444..cdefd7b9 100755 --- a/liquidity/cypress/cypress/tasks/doPriceUpdateForPyth.js +++ b/liquidity/cypress/cypress/tasks/doPriceUpdateForPyth.js @@ -80,7 +80,7 @@ const PYTH_ABI = [ 'function wormhole() view returns (address)', ]; -export async function doPriceUpdateForPyth({ privateKey, feedId, priceVerificationContract }) { +export async function doPriceUpdateForPyth({ address, feedId, priceVerificationContract }) { const priceService = new EvmPriceServiceConnection(PYTH_MAINNET_ENDPOINT); const feedIds = Array.isArray(feedId) ? feedId : [feedId]; @@ -88,11 +88,11 @@ export async function doPriceUpdateForPyth({ privateKey, feedId, priceVerificati console.log({ offchainData }); const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); + const signer = provider.getSigner(address); const PriceVerificationContract = new ethers.Contract( priceVerificationContract, PYTH_ABI, - wallet + signer ); const fee = feedIds.length * 4; const args = [ diff --git a/liquidity/cypress/cypress/tasks/setEthBalance.js b/liquidity/cypress/cypress/tasks/setEthBalance.js index 5c897c2e..62eac143 100644 --- a/liquidity/cypress/cypress/tasks/setEthBalance.js +++ b/liquidity/cypress/cypress/tasks/setEthBalance.js @@ -1,20 +1,16 @@ import { ethers } from 'ethers'; export async function setEthBalance({ address, balance }) { - const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); + const provider = new ethers.providers.JsonRpcProvider( + process.env.RPC_URL || 'http://127.0.0.1:8545' + ); const oldBalance = parseFloat(ethers.utils.formatUnits(await provider.getBalance(address))); console.log('setEthBalance', { address, oldBalance }); - const delta = balance - oldBalance; - if (delta > 0) { - const signer = provider.getSigner(0); - const tx = await signer.sendTransaction({ - to: address, - value: ethers.utils.parseEther(delta.toString()), - }); - await tx.wait(); - } - + await provider.send('anvil_setBalance', [ + address, + ethers.utils.parseEther(`${balance}`).toHexString(), + ]); const newBalance = parseFloat(ethers.utils.formatUnits(await provider.getBalance(address))); console.log('setEthBalance', { address, newBalance }); return newBalance; diff --git a/liquidity/cypress/cypress/tasks/snapshot.js b/liquidity/cypress/cypress/tasks/snapshot.js new file mode 100644 index 00000000..9901bec8 --- /dev/null +++ b/liquidity/cypress/cypress/tasks/snapshot.js @@ -0,0 +1,15 @@ +import { ethers } from 'ethers'; + +export async function evmSnapshot() { + const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); + const snapshot = await provider.send('evm_snapshot', []); + console.log('evm_snapshot', { snapshot }); + return snapshot; +} + +export async function evmRevert(snapshot) { + const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); + console.log('evm_revert', { snapshot }); + await provider.send('evm_revert', [snapshot]); + return null; +} diff --git a/liquidity/cypress/cypress/tasks/wrapEth.js b/liquidity/cypress/cypress/tasks/wrapEth.js index c06d4cdd..32596302 100644 --- a/liquidity/cypress/cypress/tasks/wrapEth.js +++ b/liquidity/cypress/cypress/tasks/wrapEth.js @@ -7,15 +7,13 @@ const erc20Abi = [ 'function deposit() payable', ]; -export async function wrapEth({ privateKey, amount }) { +export async function wrapEth({ address, amount }) { const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); - const wallet = new ethers.Wallet(privateKey, provider); + const signer = provider.getSigner(address); const WETH = await getCollateralConfig('WETH'); - const WETHContract = new ethers.Contract(WETH.tokenAddress, erc20Abi, wallet); - const balance = parseFloat( - ethers.utils.formatUnits(await WETHContract.balanceOf(wallet.address)) - ); + const WETHContract = new ethers.Contract(WETH.tokenAddress, erc20Abi, signer); + const balance = parseFloat(ethers.utils.formatUnits(await WETHContract.balanceOf(address))); if (balance >= amount) { console.log('wrapEth', { balance }); @@ -27,9 +25,7 @@ export async function wrapEth({ privateKey, amount }) { value: ethers.utils.hexValue(ethers.utils.parseEther(`${amount}`).toHexString()), }); await wrapTx.wait(); - const newBalance = parseFloat( - ethers.utils.formatUnits(await WETHContract.balanceOf(wallet.address)) - ); + const newBalance = parseFloat(ethers.utils.formatUnits(await WETHContract.balanceOf(address))); console.log('wrapEth', { balance: newBalance }); console.log('wrapEth', { result: 'OK' }); return newBalance; diff --git a/liquidity/cypress/package.json b/liquidity/cypress/package.json index 85284c10..f682f1ed 100644 --- a/liquidity/cypress/package.json +++ b/liquidity/cypress/package.json @@ -4,9 +4,9 @@ "main": "index.ts", "version": "0.0.9", "scripts": { - "anvil:arbitrum": "anvil --auto-impersonate --chain-id 42161 --fork-url wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY --timeout 5000 --retries 0 --no-rate-limit --steps-tracing", + "anvil:arbitrum": "anvil --auto-impersonate --chain-id 42161 --fork-url wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY --timeout 5000 --retries 0 --no-rate-limit --steps-tracing --fork-block-number 269244293", "anvil:sepolia": "anvil --auto-impersonate --chain-id 11155111 --fork-url wss://sepolia.infura.io/ws/v3/$INFURA_KEY --timeout 5000 --retries 0 --no-rate-limit --steps-tracing", - "anvil:base": "anvil --auto-impersonate --chain-id 8453 --fork-url wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY --timeout 5000 --retries 0 --no-rate-limit --steps-tracing", + "anvil:base": "anvil --auto-impersonate --chain-id 8453 --fork-url wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY --timeout 5000 --retries 0 --no-rate-limit --steps-tracing --fork-block-number 21781780", "cy": "NODE_ENV=test cypress open --component --browser chrome", "e2e:arbitrum": "NODE_ENV=test CYPRESS_CHAIN_ID=42161 CYPRESS_PRESET=main cypress open --e2e --browser chrome --config specPattern='./cypress/e2e/42161-main/*.e2e.js'", "e2e:base": "NODE_ENV=test CYPRESS_CHAIN_ID=8453 CYPRESS_PRESET=andromeda cypress open --e2e --browser chrome --config specPattern='./cypress/e2e/8453-andromeda/*.e2e.js'", diff --git a/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts b/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts index 1921aba9..26429d6b 100644 --- a/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts +++ b/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts @@ -4,6 +4,7 @@ import { importExtras, importMulticall3, importPythERC7412Wrapper, + importPythFeeds, importPythVerfier, } from '@snx-v3/contracts'; import { parseUnits } from '@snx-v3/format'; @@ -28,8 +29,7 @@ function getAllPriceIdsEntries(extras: any) { } export async function getPythFeedIds(network: Network) { - const extras = await importExtras(network.id, network.preset); - return getAllPriceIdsEntries(extras).map(([_key, value]) => value); + return await importPythFeeds(network.id, network.preset); } async function getPythFeedIdsFromCollateralList( diff --git a/liquidity/lib/usePoolsList/usePoolsList.ts b/liquidity/lib/usePoolsList/usePoolsList.ts index b01df79f..f7b570d7 100644 --- a/liquidity/lib/usePoolsList/usePoolsList.ts +++ b/liquidity/lib/usePoolsList/usePoolsList.ts @@ -31,7 +31,7 @@ export function usePool(networkId: number, poolId: string) { // TODO: In the future if we have multiple pools per network filter by poolId also return { data: data?.synthetixPools.find( - (p) => p.network.id === networkId && p.poolInfo[0].pool.id === poolId + (p) => p.network.id === networkId && p?.poolInfo?.[0]?.pool?.id === poolId ), isLoading, }; @@ -90,7 +90,7 @@ async function fetchPoolsList() { return responses.map((response, i) => ({ network: networksOffline[i], - poolInfo: response.data.vaults as PoolInfo[], + poolInfo: (response?.data?.vaults ?? []) as PoolInfo[], })); } diff --git a/liquidity/lib/useRewards/useRewards.ts b/liquidity/lib/useRewards/useRewards.ts index 8cd3c7bb..255ca2dc 100644 --- a/liquidity/lib/useRewards/useRewards.ts +++ b/liquidity/lib/useRewards/useRewards.ts @@ -192,11 +192,13 @@ export function useRewards({ payoutTokenAddress: item.payoutToken.address, claimableAmount: wei(0), lifetimeClaimed: historicalClaims - .reduce( - (acc: Wei, item: { amount: string }) => acc.add(wei(item.amount, 18, true)), - wei(0) - ) - .toNumber(), + ? historicalClaims + .reduce( + (acc: Wei, item: { amount: string }) => acc.add(wei(item.amount, 18, true)), + wei(0) + ) + .toNumber() + : 0, }; } diff --git a/liquidity/ui/src/components/Deposit/Deposit.tsx b/liquidity/ui/src/components/Deposit/Deposit.tsx index 5dd7d6b8..39dd192a 100644 --- a/liquidity/ui/src/components/Deposit/Deposit.tsx +++ b/liquidity/ui/src/components/Deposit/Deposit.tsx @@ -164,7 +164,7 @@ export const DepositUi: FC<{ } > - + Balance: {maxAmount?.gt(0) && ( } > - + Balance: { {filteredPools?.length > 0 ? filteredPools.map( ({ network, poolInfo, apr, collateralTypes, rewardsDistributors }) => { - const { pool } = poolInfo[0]; - const filteredCollateralTypes = collateralTypes?.filter((collateralType) => { if (!collaterals.length) { return true; @@ -294,7 +292,7 @@ export const PoolsList = () => { collateralPrices={allCollateralPrices} apr={apr} network={network} - pool={pool} + pool={poolInfo?.[0]?.pool} rewardsPayoutTokens={rewardsPayoutTokens} /> );