From 575b6f028cd4313570998076e811fd6f1dd7e0e3 Mon Sep 17 00:00:00 2001 From: Noisekit <28145325+noisekit@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:05:06 +1100 Subject: [PATCH] Deploy new DebtRepayer contract (#71) * Deploy debt repayer * Update block number for base * Adjust anvil params and timeouts * No need for XL * Wait longer for initial data load * Fix wonky withdrawal that failed because cypress was clicking submit too fast --- .circleci/config.yml | 2 +- README.md | 12 +- contracts/close-position-arbitrum/README.md | 6 + .../close-position-arbitrum/foundry.toml | 4 + .../debt-repayer-base-andromeda/README.md | 25 ++ .../debt-repayer-base-andromeda/foundry.toml | 6 +- .../WithdrawModal/WithdrawModal.tsx | 215 ++++++++---------- .../components/WithdrawModal/package.json | 1 - .../cypress/e2e/1-main/SNX_Deposit.e2e.js | 6 +- .../cypress/e2e/1-main/SNX_Unlock.e2e.js | 6 +- .../e2e/42161-main/WETH_Deposit.e2e.js | 6 +- .../cypress/e2e/42161-main/WETH_Repay.e2e.js | 6 +- .../e2e/8453-andromeda/Create_Account.e2e.js | 6 +- .../8453-andromeda/Dashboard_Connected.e2e.js | 2 +- .../e2e/8453-andromeda/USDC_Deposit.e2e.js | 8 +- .../USDC_Unlock_negative_debt.e2e.js | 6 +- .../USDC_Unlock_positive_debt.e2e.js | 8 +- .../e2e/8453-andromeda/stataUSDC_Close.e2e.js | 2 +- .../8453-andromeda/stataUSDC_Deposit.e2e.js | 8 +- .../e2e/8453-andromeda/stataUSDC_Repay.e2e.js | 2 +- .../8453-andromeda/stataUSDC_Unlock.e2e.js | 6 +- .../8453-andromeda/stataUSDC_Withdraw.e2e.js | 9 +- liquidity/cypress/cypress/tasks/anvil.js | 6 +- .../contracts/importers/importDebtRepayer.js | 17 +- .../src/components/Manage/ManageActions.tsx | 14 +- .../ui/src/components/Withdraw/Withdraw.tsx | 29 ++- yarn.lock | 1 - 27 files changed, 216 insertions(+), 203 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0228ba647..7a3ed60b7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -141,7 +141,7 @@ jobs: e2e: docker: - image: cimg/node:<< pipeline.parameters.node-version >> - resource_class: xlarge + resource_class: large parallelism: 3 steps: - checkout diff --git a/README.md b/README.md index 8b84cbca6..86d8fbf4b 100644 --- a/README.md +++ b/README.md @@ -61,14 +61,14 @@ and all transactions will be automatically signed, without any popups ```sh # Mainnets - anvil --auto-impersonate --chain-id 1 --fork-url wss://mainnet.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing --fork-block-number 21233424 - anvil --auto-impersonate --chain-id 8453 --fork-url wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing --fork-block-number 22946353 - anvil --auto-impersonate --chain-id 42161 --fork-url wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing --fork-block-number 271813668 + anvil --auto-impersonate --chain-id 1 --fork-url wss://mainnet.infura.io/ws/v3/$INFURA_KEY --fork-block-number 21233424 + anvil --auto-impersonate --chain-id 8453 --fork-url wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY --fork-block-number 22991081 + anvil --auto-impersonate --chain-id 42161 --fork-url wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY --fork-block-number 271813668 # Testnets - anvil --auto-impersonate --chain-id 11155111 --fork-url wss://sepolia.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing - anvil --auto-impersonate --chain-id 84532 --fork-url wss://base-sepolia.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing - anvil --auto-impersonate --chain-id 421614 --fork-url wss://arbitrum-sepolia.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing + anvil --auto-impersonate --chain-id 11155111 --fork-url wss://sepolia.infura.io/ws/v3/$INFURA_KEY + anvil --auto-impersonate --chain-id 84532 --fork-url wss://base-sepolia.infura.io/ws/v3/$INFURA_KEY + anvil --auto-impersonate --chain-id 421614 --fork-url wss://arbitrum-sepolia.infura.io/ws/v3/$INFURA_KEY ``` 2. Run Liquidity app locally diff --git a/contracts/close-position-arbitrum/README.md b/contracts/close-position-arbitrum/README.md index 5945cb1bd..2bbdcaad8 100644 --- a/contracts/close-position-arbitrum/README.md +++ b/contracts/close-position-arbitrum/README.md @@ -85,4 +85,10 @@ forge verify-contract \ --etherscan-api-key $ETHERSCAN_API_KEY \ 0x800B12D24ebb639BCe7280861b05149F0D60F99e \ src/ClosePosition.sol:ClosePosition + +forge verify-contract \ + --verifier-url "https://api.arbiscan.io/api" \ + --etherscan-api-key $ARBISCAN_API_KEY \ + 0x800B12D24ebb639BCe7280861b05149F0D60F99e \ + src/DebtRepayer.sol:DebtRepayer ``` diff --git a/contracts/close-position-arbitrum/foundry.toml b/contracts/close-position-arbitrum/foundry.toml index cb712bf83..5c4bb8c68 100644 --- a/contracts/close-position-arbitrum/foundry.toml +++ b/contracts/close-position-arbitrum/foundry.toml @@ -8,3 +8,7 @@ allow_paths = [ "../../node_modules" ] fs_permissions = [{ access = "read", path = "./" }, { access = "read", path = "../../node_modules" }] + +optimizer = true +optimizer_runs = 200 +compiler.version = "0.8.27+commit.40a35a09" diff --git a/contracts/debt-repayer-base-andromeda/README.md b/contracts/debt-repayer-base-andromeda/README.md index e39a7933d..5d32c4d0b 100644 --- a/contracts/debt-repayer-base-andromeda/README.md +++ b/contracts/debt-repayer-base-andromeda/README.md @@ -40,7 +40,32 @@ forge create \ --rpc-url https://base-mainnet.infura.io/v3/$INFURA_API_KEY \ --chain 8453 \ --private-key $MAINNET_DEPLOYER_PRIVATE_KEY \ + --verifier-url "https://api.basescan.org/api" \ --etherscan-api-key $BASESCAN_API_KEY \ --verify \ src/DebtRepayer.sol:DebtRepayer ``` + +## Verify contract + +If something went wrong verifying first time + +```sh +forge verify-contract \ + --watch \ + --chain 84532 \ + --verifier etherscan \ + --verifier-url "https://api-sepolia.basescan.org/api" \ + --etherscan-api-key $BASESCAN_API_KEY \ + 0xe4b0233F06a308B4732282e24ce7aE0c87bdEcbc \ + src/DebtRepayer.sol:DebtRepayer + +forge verify-contract \ + --watch \ + --chain 8453 \ + --verifier etherscan \ + --verifier-url "https://api.basescan.org/api" \ + --etherscan-api-key $BASESCAN_API_KEY \ + 0x624f2aB0f1DFF2297b9eca320898381Fbba4E3E3 \ + src/DebtRepayer.sol:DebtRepayer +``` diff --git a/contracts/debt-repayer-base-andromeda/foundry.toml b/contracts/debt-repayer-base-andromeda/foundry.toml index 8039cf1f1..5c4bb8c68 100644 --- a/contracts/debt-repayer-base-andromeda/foundry.toml +++ b/contracts/debt-repayer-base-andromeda/foundry.toml @@ -7,4 +7,8 @@ libs = [ allow_paths = [ "../../node_modules" ] -fs_permissions = [{ access = "read", path = "./" }, { access = "read", path = "../../node_modules" }] \ No newline at end of file +fs_permissions = [{ access = "read", path = "./" }, { access = "read", path = "../../node_modules" }] + +optimizer = true +optimizer_runs = 200 +compiler.version = "0.8.27+commit.40a35a09" diff --git a/liquidity/components/WithdrawModal/WithdrawModal.tsx b/liquidity/components/WithdrawModal/WithdrawModal.tsx index eeec7d235..66229cc0a 100644 --- a/liquidity/components/WithdrawModal/WithdrawModal.tsx +++ b/liquidity/components/WithdrawModal/WithdrawModal.tsx @@ -10,120 +10,22 @@ import { useAccountCollateral } from '@snx-v3/useAccountCollateral'; import { useDefaultProvider, useNetwork, useWallet } from '@snx-v3/useBlockchain'; import { useCollateralType } from '@snx-v3/useCollateralTypes'; import { useContractErrorParser } from '@snx-v3/useContractErrorParser'; -import { LiquidityPosition } from '@snx-v3/useLiquidityPosition'; +import { useLiquidityPosition } from '@snx-v3/useLiquidityPosition'; import { useParams } from '@snx-v3/useParams'; import { useStaticAaveUSDC } from '@snx-v3/useStaticAaveUSDC'; import { useSystemToken } from '@snx-v3/useSystemToken'; import { useUnwrapStataUSDC } from '@snx-v3/useUnwrapStataUSDC'; import { useWithdraw } from '@snx-v3/useWithdraw'; import { useWithdrawBaseAndromeda } from '@snx-v3/useWithdrawBaseAndromeda'; -import { Wei } from '@synthetixio/wei'; import { useQueryClient } from '@tanstack/react-query'; import { ethers } from 'ethers'; -import React, { FC, useContext, useState } from 'react'; +import React, { useContext, useState } from 'react'; import { LiquidityPositionUpdated } from '../../ui/src/components/Manage/LiquidityPositionUpdated'; -export const WithdrawModalUi: FC<{ - amount: Wei; - isOpen: boolean; - onClose: () => void; - symbol?: string; - state: { - step: number; - status: string; - }; - onSubmit: () => void; - isDebtWithdrawal: boolean; - isStataUSDC: boolean; -}> = ({ isStataUSDC, isDebtWithdrawal, amount, isOpen, onClose, onSubmit, state, symbol }) => { - if (isOpen) { - if (state.status === 'success') { - return ( - - Your {isDebtWithdrawal ? 'Debt' : 'Collateral'} has been withdrawn, read more - about it in the{' '} - - Synthetix V3 Documentation - - - } - alertText={(isDebtWithdrawal ? 'Debt' : 'Collateral') + ' successfully Withdrawn'} - /> - ); - } - - return ( -
- - - Manage {isDebtWithdrawal ? 'Debt' : 'Collateral'} - - - - } - status={{ - failed: state.step === 1 && state.status === 'error', - success: state.step > 1, - loading: state.step === 1 && state.status === 'pending', - }} - /> - {isStataUSDC && ( - unwrap Static aUSDC into USDC} - status={{ - failed: state.step === 2 && state.status === 'error', - success: state.status === 'success', - loading: state.step === 2 && state.status === 'pending', - }} - /> - )} - - -
- ); - } -}; - export function WithdrawModal({ - liquidityPosition, onClose, - isOpen, isDebtWithdrawal = false, }: { - liquidityPosition?: LiquidityPosition; - isOpen: boolean; onClose: () => void; isDebtWithdrawal?: boolean; }) { @@ -143,14 +45,19 @@ export function WithdrawModal({ const { data: collateralType } = useCollateralType(params.collateralSymbol); const errorParser = useContractErrorParser(); - const accountId = liquidityPosition?.accountId; + + const { data: liquidityPosition } = useLiquidityPosition({ + tokenAddress: collateralType?.tokenAddress, + accountId: params.accountId, + poolId: params.poolId, + }); const isBase = isBaseAndromeda(network?.id, network?.preset); const isStataUSDC = collateralType?.address.toLowerCase() === getWrappedStataUSDCOnBase(network?.id).toLowerCase(); const { data: systemToken } = useSystemToken(); - const { data: systemTokenBalance } = useAccountCollateral(accountId, systemToken?.address); + const { data: systemTokenBalance } = useAccountCollateral(params.accountId, systemToken?.address); const { data: StaticAaveUSDC } = useStaticAaveUSDC(); @@ -158,14 +65,14 @@ export function WithdrawModal({ const { mutation: withdrawMain } = useWithdraw({ amount: withdrawAmount, - accountId, + accountId: params.accountId, collateralTypeAddress: isDebtWithdrawal ? systemToken?.address : liquidityPosition?.accountCollateral?.tokenAddress, }); const { mutation: withdrawAndromeda } = useWithdrawBaseAndromeda({ - accountId, + accountId: params.accountId, availableCollateral: liquidityPosition?.accountCollateral.availableCollateral || ZEROWEI, snxUSDCollateral: systemTokenBalance?.availableCollateral || ZEROWEI, amountToWithdraw: withdrawAmount, @@ -230,20 +137,16 @@ export function WithdrawModal({ } queryClient.invalidateQueries({ - queryKey: [`${network?.id}-${network?.preset}`, 'LiquidityPosition', { accountId }], + queryKey: [`${network?.id}-${network?.preset}`, 'LiquidityPosition'], }); queryClient.invalidateQueries({ - queryKey: [`${network?.id}-${network?.preset}`, 'AccountSpecificCollateral', { accountId }], + queryKey: [`${network?.id}-${network?.preset}`, 'AccountSpecificCollateral'], }); queryClient.invalidateQueries({ - queryKey: [`${network?.id}-${network?.preset}`, 'LiquidityPositions', { accountId }], + queryKey: [`${network?.id}-${network?.preset}`, 'LiquidityPositions'], }); queryClient.invalidateQueries({ - queryKey: [ - `${network?.id}-${network?.preset}`, - 'AccountCollateralUnlockDate', - { accountId }, - ], + queryKey: [`${network?.id}-${network?.preset}`, 'AccountCollateralUnlockDate'], }); queryClient.invalidateQueries({ queryKey: [`${network?.id}-${network?.preset}`, 'TokenBalance'], @@ -276,16 +179,84 @@ export function WithdrawModal({ } }; + const amount = withdrawAmount; + const symbol = isDebtWithdrawal ? systemToken?.symbol : collateralType?.displaySymbol; + const state = txState; + + if (state.status === 'success') { + return ( + + Your {isDebtWithdrawal ? 'Debt' : 'Collateral'} has been withdrawn, read more + about it in the{' '} + + Synthetix V3 Documentation + + + } + alertText={(isDebtWithdrawal ? 'Debt' : 'Collateral') + ' successfully Withdrawn'} + /> + ); + } + return ( - +
+ + + Manage {isDebtWithdrawal ? 'Debt' : 'Collateral'} + + + + } + status={{ + failed: state.step === 1 && state.status === 'error', + success: state.step > 1, + loading: state.step === 1 && state.status === 'pending', + }} + /> + {isStataUSDC && ( + unwrap Static aUSDC into USDC} + status={{ + failed: state.step === 2 && state.status === 'error', + success: state.status === 'success', + loading: state.step === 2 && state.status === 'pending', + }} + /> + )} + + +
); } diff --git a/liquidity/components/WithdrawModal/package.json b/liquidity/components/WithdrawModal/package.json index 00e33fbb0..e848b403e 100644 --- a/liquidity/components/WithdrawModal/package.json +++ b/liquidity/components/WithdrawModal/package.json @@ -23,7 +23,6 @@ "@snx-v3/useUnwrapStataUSDC": "workspace:*", "@snx-v3/useWithdraw": "workspace:*", "@snx-v3/useWithdrawBaseAndromeda": "workspace:*", - "@synthetixio/wei": "^2.74.4", "@tanstack/react-query": "^5.8.3", "ethers": "^5.7.2", "react": "^18.2.0" diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js index 2945608fc..8122c82bf 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js @@ -27,8 +27,10 @@ describe(__filename, () => { cy.visit(`/#/positions/SNX/1?manageAction=deposit&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="deposit and lock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="balance amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="deposit and lock collateral form"]').should('exist'); + cy.get('[data-cy="balance amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="deposit amount input"]').type('101'); cy.get('[data-cy="deposit submit"]').should('be.enabled'); diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js index d69230350..55ed97495 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js @@ -30,8 +30,10 @@ describe(__filename, () => { cy.visit(`/#/positions/SNX/1?manageAction=undelegate&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="unlock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="locked amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="unlock collateral form"]').should('exist'); + cy.get('[data-cy="locked amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="undelegate amount input"]').should('exist'); cy.get('[data-cy="undelegate amount input"]').type('30'); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js index 99c011498..feb014800 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js @@ -32,8 +32,10 @@ describe(__filename, () => { cy.visit(`/#/positions/WETH/1?manageAction=deposit&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="deposit and lock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="balance amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="deposit and lock collateral form"]').should('exist'); + cy.get('[data-cy="balance amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="deposit amount input"]').type('1'); cy.get('[data-cy="deposit submit"]').should('be.enabled'); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js index 7562508bf..797026503 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js @@ -31,8 +31,10 @@ describe(__filename, () => { cy.visit(`/#/positions/WETH/1?manageAction=repay&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="repay debt form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="current debt amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="repay debt form"]').should('exist'); + cy.get('[data-cy="current debt amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="repay amount input"]').type('5'); 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 efc02f217..b342c007e 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Create_Account.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Create_Account.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -42,6 +42,8 @@ describe(__filename, () => { expect(urlAccountId).equal(Cypress.env('accountId')); }); - cy.get(`[data-cy="account id"][data-account-id="${Cypress.env('accountId')}"]`).should('exist'); + cy.get(`[data-cy="account id"][data-account-id="${Cypress.env('accountId')}"]`, { + timeout: 180_000, + }).should('exist'); }); }); 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 2126c47c6..1188ad8a0 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard_Connected.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Dashboard_Connected.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js index 15d1b595c..875654043 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -27,8 +27,10 @@ describe(__filename, () => { cy.visit(`/#/positions/USDC/1?manageAction=deposit&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="deposit and lock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="balance amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="deposit and lock collateral form"]').should('exist'); + cy.get('[data-cy="balance amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="deposit amount input"]').should('exist'); cy.get('[data-cy="deposit amount input"]').type('101'); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_negative_debt.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_negative_debt.e2e.js index 111cefbbc..f1a341849 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_negative_debt.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_negative_debt.e2e.js @@ -32,8 +32,10 @@ describe(__filename, () => { cy.visit(`/#/positions/USDC/1?manageAction=undelegate&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="unlock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="locked amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="unlock collateral form"]').should('exist'); + cy.get('[data-cy="locked amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="undelegate amount input"]').should('exist'); cy.get('[data-cy="undelegate amount input"]').type('30'); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_positive_debt.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_positive_debt.e2e.js index c77102aa0..8881423f6 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_positive_debt.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Unlock_positive_debt.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', // positive debt + block: '22991081', // positive debt }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -27,8 +27,10 @@ describe(__filename, () => { cy.visit(`/#/positions/USDC/1?manageAction=undelegate&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="unlock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="locked amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="unlock collateral form"]').should('exist'); + cy.get('[data-cy="locked amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="undelegate amount input"]').should('exist'); cy.get('[data-cy="undelegate amount input"]').type('30'); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js index 7b816fa2a..9ef106843 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Deposit.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Deposit.e2e.js index d1ba61273..20702ef7f 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Deposit.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -27,8 +27,10 @@ describe(__filename, () => { cy.visit(`/#/positions/stataUSDC/1?manageAction=deposit&accountId=${Cypress.env('accountId')}`); - cy.get('[data-cy="deposit and lock collateral form"]', { timeout: 180_000 }).should('exist'); - cy.get('[data-cy="balance amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="deposit and lock collateral form"]').should('exist'); + cy.get('[data-cy="balance amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="deposit amount input"]').should('exist'); cy.get('[data-cy="deposit amount input"]').type('1'); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js index 12ec8dca4..d427051b0 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js index 8d6b6c307..4c08189c6 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js @@ -8,7 +8,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -30,7 +30,9 @@ describe(__filename, () => { ); cy.get('[data-cy="unlock collateral form"]').should('exist'); - cy.get('[data-cy="locked amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="locked amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="undelegate amount input"]').should('exist'); cy.get('[data-cy="undelegate amount input"]').type('1'); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js index abef5ab04..9c91d2e84 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js @@ -1,6 +1,9 @@ describe(__filename, () => { Cypress.env('chainId', '8453'); Cypress.env('preset', 'andromeda'); + // Cypress.env('walletAddress', '0xc3Cf311e04c1f8C74eCF6a795Ae760dc6312F345'); + // Cypress.env('accountId', '522433293696'); + Cypress.env('walletAddress', '0xc77b0cd1B1E73F6De8f606685Fb09Ace95f614c3'); Cypress.env('accountId', '170141183460469231731687303715884105949'); @@ -8,7 +11,7 @@ describe(__filename, () => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `wss://base-mainnet.infura.io/ws/v3/${Cypress.env('INFURA_KEY')}`, - block: '22946353', + block: '22991081', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -30,7 +33,9 @@ describe(__filename, () => { ); cy.get('[data-cy="withdraw form"]').should('exist'); - cy.get('[data-cy="withdraw amount"]').should('exist').and('include.text', 'Max'); + cy.get('[data-cy="withdraw amount"]', { timeout: 180_000 }) + .should('exist') + .and('include.text', 'Max'); cy.get('[data-cy="withdraw amount input"]').should('exist'); cy.get('[data-cy="withdraw amount input"]').type('1'); diff --git a/liquidity/cypress/cypress/tasks/anvil.js b/liquidity/cypress/cypress/tasks/anvil.js index ec478cead..a3fe13c13 100644 --- a/liquidity/cypress/cypress/tasks/anvil.js +++ b/liquidity/cypress/cypress/tasks/anvil.js @@ -15,12 +15,14 @@ export async function startAnvil({ chainId, forkUrl, block }) { chainId, '--fork-url', forkUrl, - // '--no-rate-limit', + '--no-rate-limit', // '--steps-tracing', + '--accounts', + '0', '--fork-block-number', block, '--memory-limit', - '12884901888', // 12G + '6442450944', // 6G ]; console.log(`Starting anvil:`, cmd, args.join(' ')); return new Promise(async (resolve, reject) => { diff --git a/liquidity/lib/contracts/importers/importDebtRepayer.js b/liquidity/lib/contracts/importers/importDebtRepayer.js index 586f87418..fbe520c56 100644 --- a/liquidity/lib/contracts/importers/importDebtRepayer.js +++ b/liquidity/lib/contracts/importers/importDebtRepayer.js @@ -6,22 +6,13 @@ export async function importDebtRepayer(chainId, preset) { const deployment = `${Number(chainId).toFixed(0)}-${preset}`; switch (deployment) { case '8453-andromeda': { - // https://basescan.org/address/0x220bd4ba855a954a57d5eac74ca686e73c58f388#code - return { address: '0x220bd4ba855a954a57d5eac74ca686e73c58f388', abi }; + // https://basescan.org/address/0x624f2aB0f1DFF2297b9eca320898381Fbba4E3E3#code + return { address: '0x624f2aB0f1DFF2297b9eca320898381Fbba4E3E3', abi }; } case '84532-andromeda': { - // https://sepolia.basescan.org/address/0x4e41a49dc192b3c31acea9db38be74ac224e7212#code - return { address: '0x4e41a49dc192b3c31acea9db38be74ac224e7212', abi }; + // https://sepolia.basescan.org/address/0xe4b0233F06a308B4732282e24ce7aE0c87bdEcbc#code + return { address: '0xe4b0233F06a308B4732282e24ce7aE0c87bdEcbc', abi }; } - // Arbitrum contracts cannot be the same as Base as the workflow is different - // case '42161-main': { - // // https://arbiscan.io/address/0x2305f5f9ef3abf0d6d02411aca44f85113b247af#code - // return { address: '0x2305f5f9ef3abf0d6d02411aca44f85113b247af', abi }; - // } - // case '421614-main': { - // // https://sepolia.arbiscan.io/address/0xd88de2ee855f145ab1ecfff8273661c3d59fc8ad#code - // return { address: '0xd88de2ee855f145ab1ecfff8273661c3d59fc8ad', abi }; - // } default: { throw new Error(`Unsupported deployment ${deployment} for DebtRepayer`); } diff --git a/liquidity/ui/src/components/Manage/ManageActions.tsx b/liquidity/ui/src/components/Manage/ManageActions.tsx index c15e310c6..7c5bd0062 100644 --- a/liquidity/ui/src/components/Manage/ManageActions.tsx +++ b/liquidity/ui/src/components/Manage/ManageActions.tsx @@ -208,12 +208,8 @@ export const ManageAction = ({ {manageAction === 'claim' ? : null} - {manageAction === 'withdraw' ? ( - - ) : null} - {manageAction === 'withdraw-debt' ? ( - - ) : null} + {manageAction === 'withdraw' ? : null} + {manageAction === 'withdraw-debt' ? : null} {manageAction === 'deposit' ? : null} {manageAction === 'repay' ? : null} {manageAction === 'undelegate' ? ( @@ -279,29 +275,23 @@ export const ManageAction = ({ ) : null} {txnModalOpen === 'withdraw' ? ( { setCollateralChange(wei(0)); setDebtChange(wei(0)); setWithdrawAmount(wei(0)); setTxnModalOpen(undefined); }} - isOpen={txnModalOpen === 'withdraw'} - account /> ) : null} {txnModalOpen === 'withdraw-debt' ? ( { setCollateralChange(wei(0)); setDebtChange(wei(0)); setWithdrawAmount(wei(0)); setTxnModalOpen(undefined); }} - isOpen={txnModalOpen === 'withdraw-debt'} - account isDebtWithdrawal /> ) : null} diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index 098c23c2c..0e8a906db 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -9,30 +9,29 @@ import { useAccountCollateral } from '@snx-v3/useAccountCollateral'; import { useAccountCollateralUnlockDate } from '@snx-v3/useAccountCollateralUnlockDate'; import { useNetwork } from '@snx-v3/useBlockchain'; import { useCollateralType } from '@snx-v3/useCollateralTypes'; -import { LiquidityPosition } from '@snx-v3/useLiquidityPosition'; +import { useLiquidityPosition } from '@snx-v3/useLiquidityPosition'; +import { useParams } from '@snx-v3/useParams'; import { useSystemToken } from '@snx-v3/useSystemToken'; import { useTokenPrice } from '@snx-v3/useTokenPrice'; import { useWithdrawTimer } from '@snx-v3/useWithdrawTimer'; import { useContext, useMemo } from 'react'; -import { useParams } from 'react-router-dom'; import { TokenIcon } from '../TokenIcon/TokenIcon'; -export const Withdraw = ({ - liquidityPosition, - isDebtWithdrawal = false, -}: { - liquidityPosition?: LiquidityPosition; - isDebtWithdrawal?: boolean; -}) => { +export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: boolean }) { const { setWithdrawAmount, withdrawAmount } = useContext(ManagePositionContext); - const accountId = liquidityPosition?.accountId; const params = useParams(); const { data: collateralType } = useCollateralType(params.collateralSymbol); const { network } = useNetwork(); const isBase = isBaseAndromeda(network?.id, network?.preset); + const { data: liquidityPosition } = useLiquidityPosition({ + tokenAddress: collateralType?.tokenAddress, + accountId: params.accountId, + poolId: params.poolId, + }); + const { data: systemToken } = useSystemToken(); - const { data: systemTokenBalance } = useAccountCollateral(accountId, systemToken?.address); + const { data: systemTokenBalance } = useAccountCollateral(params.accountId, systemToken?.address); const maxWithdrawable = useMemo(() => { if (isBase) { @@ -52,13 +51,11 @@ export const Withdraw = ({ ]); const { data: accountCollateralUnlockDate, isLoading: isLoadingDate } = - useAccountCollateralUnlockDate({ - accountId, - }); + useAccountCollateralUnlockDate({ accountId: params.accountId }); const symbol = isDebtWithdrawal ? systemToken?.symbol : collateralType?.symbol; const price = useTokenPrice(symbol); - const { minutes, hours, isRunning } = useWithdrawTimer(accountId); + const { minutes, hours, isRunning } = useWithdrawTimer(params.accountId); const unlockDate = !isLoadingDate ? accountCollateralUnlockDate : null; return ( @@ -156,4 +153,4 @@ export const Withdraw = ({ ); -}; +} diff --git a/yarn.lock b/yarn.lock index f582f133d..7fbb32989 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4923,7 +4923,6 @@ __metadata: "@snx-v3/useUnwrapStataUSDC": "workspace:*" "@snx-v3/useWithdraw": "workspace:*" "@snx-v3/useWithdrawBaseAndromeda": "workspace:*" - "@synthetixio/wei": "npm:^2.74.4" "@tanstack/react-query": "npm:^5.8.3" ethers: "npm:^5.7.2" react: "npm:^18.2.0"