From ba18121fb49c8266a6d13c45874f244da55bd275 Mon Sep 17 00:00:00 2001 From: peiman3 Date: Fri, 20 Dec 2024 16:29:55 +0330 Subject: [PATCH 01/11] Exclude locked collateral from available to withdraw. --- liquidity/lib/useAccountCollateral/index.ts | 1 + .../lib/useAccountCollateral/package.json | 17 +++++ .../useAccountCollateral.ts | 74 +++++++++++++++++++ .../src/components/Manage/CollateralStats.tsx | 32 ++++++++ .../src/components/Positions/PositionsRow.tsx | 5 ++ .../ui/src/components/Withdraw/Withdraw.tsx | 27 +++++-- yarn.lock | 16 ++++ 7 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 liquidity/lib/useAccountCollateral/index.ts create mode 100644 liquidity/lib/useAccountCollateral/package.json create mode 100644 liquidity/lib/useAccountCollateral/useAccountCollateral.ts diff --git a/liquidity/lib/useAccountCollateral/index.ts b/liquidity/lib/useAccountCollateral/index.ts new file mode 100644 index 00000000..2864a95e --- /dev/null +++ b/liquidity/lib/useAccountCollateral/index.ts @@ -0,0 +1 @@ +export * from './useAccountCollateral'; diff --git a/liquidity/lib/useAccountCollateral/package.json b/liquidity/lib/useAccountCollateral/package.json new file mode 100644 index 00000000..7ed795ed --- /dev/null +++ b/liquidity/lib/useAccountCollateral/package.json @@ -0,0 +1,17 @@ +{ + "name": "@snx-v3/useAccountCollateral", + "private": true, + "main": "index.ts", + "version": "0.0.1", + "dependencies": { + "@snx-v3/tsHelpers": "workspace:*", + "@snx-v3/useBlockchain": "workspace:*", + "@snx-v3/useCoreProxy": "workspace:*", + "@snx-v3/withERC7412": "workspace:*", + "@synthetixio/wei": "^2.74.4", + "@tanstack/react-query": "^5.8.3", + "debug": "^4.3.7", + "ethers": "^5.7.2", + "react": "^18.2.0" + } +} diff --git a/liquidity/lib/useAccountCollateral/useAccountCollateral.ts b/liquidity/lib/useAccountCollateral/useAccountCollateral.ts new file mode 100644 index 00000000..8db339de --- /dev/null +++ b/liquidity/lib/useAccountCollateral/useAccountCollateral.ts @@ -0,0 +1,74 @@ +import { contractsHash } from '@snx-v3/tsHelpers'; +import { Network, useNetwork, useProviderForChain } from '@snx-v3/useBlockchain'; +import { useCoreProxy } from '@snx-v3/useCoreProxy'; +import { erc7412Call } from '@snx-v3/withERC7412'; +import Wei, { wei } from '@synthetixio/wei'; +import { useQuery } from '@tanstack/react-query'; +import debug from 'debug'; +import { ethers } from 'ethers'; + +const log = debug('snx:useAccountCollateral'); + +export const useAccountCollateral = ({ + accountId, + tokenAddress, + network: networkOverride, +}: { + accountId?: string; + tokenAddress?: string; + network?: Network; +}) => { + const { network: currentNetwork } = useNetwork(); + const network = networkOverride || currentNetwork; + const { data: CoreProxy } = useCoreProxy(network); + const provider = useProviderForChain(network); + + return useQuery({ + queryKey: [ + `${network?.id}-${network?.preset}`, + 'AccountCollateral', + { accountId }, + { tokenAddress }, + { contractsHash: contractsHash([CoreProxy]) }, + ], + enabled: Boolean( + network && provider && CoreProxy && accountId && tokenAddress && network.id === 1 + ), + queryFn: async (): Promise<{ + totalDeposited: Wei; + totalAssigned: Wei; + totalLocked: Wei; + }> => { + if (!(network && provider && CoreProxy && accountId && tokenAddress)) { + throw new Error('OMFG'); + } + const CoreProxyContract = new ethers.Contract(CoreProxy.address, CoreProxy.abi, provider); + + const getAccountCollateralCallPromised = + CoreProxyContract.populateTransaction.getAccountCollateral(accountId, tokenAddress); + const calls = await Promise.all([getAccountCollateralCallPromised]); + + return await erc7412Call( + network, + provider, + calls, + (encoded) => { + if (!Array.isArray(encoded) || calls.length !== encoded.length) { + throw new Error('[useAccountCollateral] Unexpected multicall response'); + } + + const [totalDeposited, totalAssigned, totalLocked] = + CoreProxyContract.interface.decodeFunctionResult('getAccountCollateral', encoded[0]); + + log({ totalDeposited, totalAssigned, totalLocked }); + return { + totalDeposited: wei(totalDeposited), + totalAssigned: wei(totalAssigned), + totalLocked: wei(totalLocked), + }; + }, + 'useAccountCollateral' + ); + }, + }); +}; diff --git a/liquidity/ui/src/components/Manage/CollateralStats.tsx b/liquidity/ui/src/components/Manage/CollateralStats.tsx index 7c12c067..29d319ff 100644 --- a/liquidity/ui/src/components/Manage/CollateralStats.tsx +++ b/liquidity/ui/src/components/Manage/CollateralStats.tsx @@ -7,6 +7,8 @@ import { useCollateralType } from '@snx-v3/useCollateralTypes'; import { useLiquidityPosition } from '@snx-v3/useLiquidityPosition'; import { type PositionPageSchemaType, useParams } from '@snx-v3/useParams'; import { type Wei } from '@synthetixio/wei'; +import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; +import { Amount } from '@snx-v3/Amount'; export function CollateralStats({ newCollateralAmount, @@ -21,6 +23,10 @@ export function CollateralStats({ accountId: params.accountId, collateralType, }); + const { data: accountCollateral } = useAccountCollateral({ + accountId: params.accountId, + tokenAddress: collateralType?.address, + }); return ( @@ -67,7 +73,33 @@ export function CollateralStats({ ) : null} + + {accountCollateral?.totalLocked.gt(0) && ( + + + Escrowed + + + + + + )} ); } + +//totalAssigned +302.8257661995; +// +302.8257661995; diff --git a/liquidity/ui/src/components/Positions/PositionsRow.tsx b/liquidity/ui/src/components/Positions/PositionsRow.tsx index b9153702..fea99be7 100644 --- a/liquidity/ui/src/components/Positions/PositionsRow.tsx +++ b/liquidity/ui/src/components/Positions/PositionsRow.tsx @@ -11,6 +11,7 @@ import { makeSearch, useParams } from '@snx-v3/useParams'; import { useWithdrawTimer } from '@snx-v3/useWithdrawTimer'; import { CRatioAmount } from '../CRatioBar/CRatioAmount'; import { CRatioBadge } from '../CRatioBar/CRatioBadge'; +import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; export function PositionRow({ liquidityPosition, @@ -20,6 +21,10 @@ export function PositionRow({ apr?: number; }) { const [params, setParams] = useParams(); + useAccountCollateral({ + accountId: params.accountId, + tokenAddress: liquidityPosition.collateralType.address, + }); const { network } = useNetwork(); const isStataUSDC = useIsSynthStataUSDC({ diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index 5a95562f..ac3149a1 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -13,6 +13,7 @@ import { type PositionPageSchemaType, useParams } from '@snx-v3/useParams'; import { useSystemToken } from '@snx-v3/useSystemToken'; import { useWithdrawTimer } from '@snx-v3/useWithdrawTimer'; import React from 'react'; +import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: boolean }) { const [params] = useParams(); @@ -39,12 +40,24 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool const { minutes, hours, isRunning } = useWithdrawTimer(params.accountId); const unlockDate = !isLoadingDate ? accountCollateralUnlockDate : null; - const maxWithdrawable = - network?.preset === 'andromeda' && liquidityPosition - ? liquidityPosition.availableCollateral.add(liquidityPosition.availableSystemToken) - : isDebtWithdrawal - ? liquidityPosition?.availableSystemToken - : liquidityPosition?.availableCollateral; + const { data: accountCollateral } = useAccountCollateral({ + accountId: params.accountId, + tokenAddress: collateralType?.address, + }); + + const maxWithdrawable = React.useMemo(() => { + if (network?.preset === 'andromeda' && liquidityPosition) { + return liquidityPosition.availableCollateral.add(liquidityPosition.availableSystemToken); + } + + if (network?.id === 1 && accountCollateral) { + return liquidityPosition?.availableCollateral.sub(accountCollateral.totalLocked); + } + + return isDebtWithdrawal + ? liquidityPosition?.availableSystemToken + : liquidityPosition?.availableCollateral; + }, [accountCollateral, isDebtWithdrawal, liquidityPosition, network?.id, network?.preset]); return ( @@ -66,7 +79,7 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool <>   {maxWithdrawable.gt(0) && ( diff --git a/yarn.lock b/yarn.lock index 3762a0b5..df83f646 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5244,6 +5244,22 @@ __metadata: languageName: unknown linkType: soft +"@snx-v3/useAccountCollateral@workspace:liquidity/lib/useAccountCollateral": + version: 0.0.0-use.local + resolution: "@snx-v3/useAccountCollateral@workspace:liquidity/lib/useAccountCollateral" + dependencies: + "@snx-v3/tsHelpers": "workspace:*" + "@snx-v3/useBlockchain": "workspace:*" + "@snx-v3/useCoreProxy": "workspace:*" + "@snx-v3/withERC7412": "workspace:*" + "@synthetixio/wei": "npm:^2.74.4" + "@tanstack/react-query": "npm:^5.8.3" + debug: "npm:^4.3.7" + ethers: "npm:^5.7.2" + react: "npm:^18.2.0" + languageName: unknown + linkType: soft + "@snx-v3/useAccountCollateralUnlockDate@workspace:*, @snx-v3/useAccountCollateralUnlockDate@workspace:liquidity/lib/useAccountCollateralUnlockDate": version: 0.0.0-use.local resolution: "@snx-v3/useAccountCollateralUnlockDate@workspace:liquidity/lib/useAccountCollateralUnlockDate" From 475dc189dfc08647f8ddd2c3886717ae1c686237 Mon Sep 17 00:00:00 2001 From: peiman3 Date: Fri, 20 Dec 2024 19:02:30 +0330 Subject: [PATCH 02/11] locked amount in positions table. --- .../src/components/Positions/PositionsRow.tsx | 45 ++++++++++++++++++- .../ui/src/components/Positions/lock.svg | 4 ++ .../ui/src/components/Withdraw/Withdraw.tsx | 5 ++- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 liquidity/ui/src/components/Positions/lock.svg diff --git a/liquidity/ui/src/components/Positions/PositionsRow.tsx b/liquidity/ui/src/components/Positions/PositionsRow.tsx index fea99be7..3ed23130 100644 --- a/liquidity/ui/src/components/Positions/PositionsRow.tsx +++ b/liquidity/ui/src/components/Positions/PositionsRow.tsx @@ -1,5 +1,16 @@ import { TimeIcon } from '@chakra-ui/icons'; -import { Box, Button, Collapse, Fade, Flex, Link, Td, Text, Tooltip } from '@chakra-ui/react'; +import { + Box, + Button, + Collapse, + Fade, + Flex, + Image, + Link, + Td, + Text, + Tooltip, +} from '@chakra-ui/react'; import { Amount } from '@snx-v3/Amount'; import { DebtAmount, PnlAmount } from '@snx-v3/DebtAmount'; import { TokenIcon } from '@snx-v3/TokenIcon'; @@ -12,6 +23,7 @@ import { useWithdrawTimer } from '@snx-v3/useWithdrawTimer'; import { CRatioAmount } from '../CRatioBar/CRatioAmount'; import { CRatioBadge } from '../CRatioBar/CRatioBadge'; import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; +import lockIcon from './lock.svg'; export function PositionRow({ liquidityPosition, @@ -27,6 +39,11 @@ export function PositionRow({ }); const { network } = useNetwork(); + const { data: accountCollateral } = useAccountCollateral({ + accountId: params.accountId, + tokenAddress: liquidityPosition.collateralType?.address, + }); + const isStataUSDC = useIsSynthStataUSDC({ tokenAddress: liquidityPosition.collateralType.tokenAddress, customNetwork: network, @@ -81,8 +98,31 @@ export function PositionRow({ - + + + Including in   + +   Escrow that cannot be unlocked until the unlocking date has been reached + + } + > + + + {liquidityPosition.availableCollateral.gt(0) && isRunning && ( diff --git a/liquidity/ui/src/components/Positions/lock.svg b/liquidity/ui/src/components/Positions/lock.svg new file mode 100644 index 00000000..599388c8 --- /dev/null +++ b/liquidity/ui/src/components/Positions/lock.svg @@ -0,0 +1,4 @@ + + + + diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index ac3149a1..cd73df55 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -51,7 +51,8 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool } if (network?.id === 1 && accountCollateral) { - return liquidityPosition?.availableCollateral.sub(accountCollateral.totalLocked); + const amount = liquidityPosition?.availableCollateral.sub(accountCollateral.totalLocked); + return amount?.gt(0) ? amount : ZEROWEI; } return isDebtWithdrawal @@ -79,7 +80,7 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool <>   {maxWithdrawable.gt(0) && ( From 1876ba7333068afed67ac31a3dc13e6f7f9a2c36 Mon Sep 17 00:00:00 2001 From: peiman3 Date: Fri, 20 Dec 2024 19:14:04 +0330 Subject: [PATCH 03/11] fix: svg --- liquidity/ui/src/components/Positions/lock.svg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liquidity/ui/src/components/Positions/lock.svg b/liquidity/ui/src/components/Positions/lock.svg index 599388c8..0f3417f3 100644 --- a/liquidity/ui/src/components/Positions/lock.svg +++ b/liquidity/ui/src/components/Positions/lock.svg @@ -1,4 +1,4 @@ - - - + + + From f687c5ed41fca6044d3f65f63707ff266d9407fb Mon Sep 17 00:00:00 2001 From: Noisekit <28145325+noisekit@users.noreply.github.com> Date: Sat, 21 Dec 2024 07:40:04 +1100 Subject: [PATCH 04/11] Remove mainnet check --- liquidity/ui/src/components/Withdraw/Withdraw.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index cd73df55..48173d69 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -50,7 +50,7 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool return liquidityPosition.availableCollateral.add(liquidityPosition.availableSystemToken); } - if (network?.id === 1 && accountCollateral) { + if (accountCollateral) { const amount = liquidityPosition?.availableCollateral.sub(accountCollateral.totalLocked); return amount?.gt(0) ? amount : ZEROWEI; } From 4e7806ec91c7d5eccb5bc17f462ead869788dcce Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sat, 21 Dec 2024 07:55:20 +1100 Subject: [PATCH 05/11] Fix `maxWithdrawable` logic to cover all scenarios --- .../ui/src/components/Withdraw/Withdraw.tsx | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index 48173d69..9f3575df 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -46,19 +46,22 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool }); const maxWithdrawable = React.useMemo(() => { - if (network?.preset === 'andromeda' && liquidityPosition) { - return liquidityPosition.availableCollateral.add(liquidityPosition.availableSystemToken); + if (isDebtWithdrawal && liquidityPosition) { + return liquidityPosition.availableSystemToken; } - - if (accountCollateral) { - const amount = liquidityPosition?.availableCollateral.sub(accountCollateral.totalLocked); - return amount?.gt(0) ? amount : ZEROWEI; + if (!isDebtWithdrawal && liquidityPosition && accountCollateral) { + const unlockedCollateral = liquidityPosition.availableCollateral.sub( + accountCollateral.totalLocked + ); + if (unlockedCollateral.lte(0)) { + // should not be possible but just in case + return ZEROWEI; + } + return network?.preset === 'andromeda' + ? unlockedCollateral.add(liquidityPosition.availableSystemToken) + : unlockedCollateral; } - - return isDebtWithdrawal - ? liquidityPosition?.availableSystemToken - : liquidityPosition?.availableCollateral; - }, [accountCollateral, isDebtWithdrawal, liquidityPosition, network?.id, network?.preset]); + }, [accountCollateral, isDebtWithdrawal, liquidityPosition, network]); return ( From 18142e7ecc14df7b17152285b36ff133b511b72e Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sun, 22 Dec 2024 16:58:35 +1100 Subject: [PATCH 06/11] Dont filter by mainnet --- liquidity/lib/useAccountCollateral/useAccountCollateral.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/liquidity/lib/useAccountCollateral/useAccountCollateral.ts b/liquidity/lib/useAccountCollateral/useAccountCollateral.ts index 8db339de..0d328a80 100644 --- a/liquidity/lib/useAccountCollateral/useAccountCollateral.ts +++ b/liquidity/lib/useAccountCollateral/useAccountCollateral.ts @@ -31,9 +31,7 @@ export const useAccountCollateral = ({ { tokenAddress }, { contractsHash: contractsHash([CoreProxy]) }, ], - enabled: Boolean( - network && provider && CoreProxy && accountId && tokenAddress && network.id === 1 - ), + enabled: Boolean(network && provider && CoreProxy && accountId && tokenAddress), queryFn: async (): Promise<{ totalDeposited: Wei; totalAssigned: Wei; From bac2de18f10e5cdcebb96fd7d8f5746613243ef7 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sun, 22 Dec 2024 17:04:48 +1100 Subject: [PATCH 07/11] Deps --- liquidity/components/ClaimModal/ClaimSuccessBanner.tsx | 2 +- liquidity/ui/package.json | 1 + liquidity/ui/src/components/Manage/CollateralStats.tsx | 4 ++-- liquidity/ui/src/components/Positions/PositionsRow.tsx | 2 +- liquidity/ui/src/components/Withdraw/Withdraw.tsx | 2 +- yarn.lock | 3 ++- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/liquidity/components/ClaimModal/ClaimSuccessBanner.tsx b/liquidity/components/ClaimModal/ClaimSuccessBanner.tsx index baff5629..fc12b57d 100644 --- a/liquidity/components/ClaimModal/ClaimSuccessBanner.tsx +++ b/liquidity/components/ClaimModal/ClaimSuccessBanner.tsx @@ -1,6 +1,6 @@ import { ArrowUpIcon } from '@chakra-ui/icons'; import { Button, Divider, Flex, Heading, Image, Link, Text } from '@chakra-ui/react'; -import SynthetixLogo from '../../lib/useBlockchain/SynthetixIcon.svg'; +import SynthetixLogo from '@snx-v3/useBlockchain/SynthetixIcon.svg'; export function ClaimSuccessBanner({ onClose }: { onClose: () => void }) { return ( diff --git a/liquidity/ui/package.json b/liquidity/ui/package.json index 369b6020..64bb0d56 100644 --- a/liquidity/ui/package.json +++ b/liquidity/ui/package.json @@ -38,6 +38,7 @@ "@snx-v3/icons": "workspace:*", "@snx-v3/isBaseAndromeda": "workspace:*", "@snx-v3/theme": "workspace:*", + "@snx-v3/useAccountCollateral": "workspace:*", "@snx-v3/useAccountCollateralUnlockDate": "workspace:*", "@snx-v3/useAccountPermissions": "workspace:*", "@snx-v3/useAccountProxy": "workspace:*", diff --git a/liquidity/ui/src/components/Manage/CollateralStats.tsx b/liquidity/ui/src/components/Manage/CollateralStats.tsx index 29d319ff..41281a58 100644 --- a/liquidity/ui/src/components/Manage/CollateralStats.tsx +++ b/liquidity/ui/src/components/Manage/CollateralStats.tsx @@ -1,14 +1,14 @@ import { Flex, Text } from '@chakra-ui/react'; +import { Amount } from '@snx-v3/Amount'; import { BorderBox } from '@snx-v3/BorderBox'; import { ChangeStat } from '@snx-v3/ChangeStat'; import { ZEROWEI } from '@snx-v3/constants'; import { currency } from '@snx-v3/format'; +import { useAccountCollateral } from '@snx-v3/useAccountCollateral'; import { useCollateralType } from '@snx-v3/useCollateralTypes'; import { useLiquidityPosition } from '@snx-v3/useLiquidityPosition'; import { type PositionPageSchemaType, useParams } from '@snx-v3/useParams'; import { type Wei } from '@synthetixio/wei'; -import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; -import { Amount } from '@snx-v3/Amount'; export function CollateralStats({ newCollateralAmount, diff --git a/liquidity/ui/src/components/Positions/PositionsRow.tsx b/liquidity/ui/src/components/Positions/PositionsRow.tsx index 3ed23130..f09aeb3e 100644 --- a/liquidity/ui/src/components/Positions/PositionsRow.tsx +++ b/liquidity/ui/src/components/Positions/PositionsRow.tsx @@ -14,6 +14,7 @@ import { import { Amount } from '@snx-v3/Amount'; import { DebtAmount, PnlAmount } from '@snx-v3/DebtAmount'; import { TokenIcon } from '@snx-v3/TokenIcon'; +import { useAccountCollateral } from '@snx-v3/useAccountCollateral'; import { useStataUSDCApr } from '@snx-v3/useApr/useStataUSDCApr'; import { useNetwork } from '@snx-v3/useBlockchain'; import { useIsSynthStataUSDC } from '@snx-v3/useIsSynthStataUSDC'; @@ -22,7 +23,6 @@ import { makeSearch, useParams } from '@snx-v3/useParams'; import { useWithdrawTimer } from '@snx-v3/useWithdrawTimer'; import { CRatioAmount } from '../CRatioBar/CRatioAmount'; import { CRatioBadge } from '../CRatioBar/CRatioBadge'; -import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; import lockIcon from './lock.svg'; export function PositionRow({ diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index 9f3575df..a971d14f 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -5,6 +5,7 @@ import { ZEROWEI } from '@snx-v3/constants'; import { ManagePositionContext } from '@snx-v3/ManagePositionContext'; import { NumberInput } from '@snx-v3/NumberInput'; import { TokenIcon } from '@snx-v3/TokenIcon'; +import { useAccountCollateral } from '@snx-v3/useAccountCollateral'; import { useAccountCollateralUnlockDate } from '@snx-v3/useAccountCollateralUnlockDate'; import { useNetwork } from '@snx-v3/useBlockchain'; import { useCollateralType } from '@snx-v3/useCollateralTypes'; @@ -13,7 +14,6 @@ import { type PositionPageSchemaType, useParams } from '@snx-v3/useParams'; import { useSystemToken } from '@snx-v3/useSystemToken'; import { useWithdrawTimer } from '@snx-v3/useWithdrawTimer'; import React from 'react'; -import { useAccountCollateral } from '../../../../lib/useAccountCollateral'; export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: boolean }) { const [params] = useParams(); diff --git a/yarn.lock b/yarn.lock index df83f646..e7ddf8d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5076,6 +5076,7 @@ __metadata: "@snx-v3/icons": "workspace:*" "@snx-v3/isBaseAndromeda": "workspace:*" "@snx-v3/theme": "workspace:*" + "@snx-v3/useAccountCollateral": "workspace:*" "@snx-v3/useAccountCollateralUnlockDate": "workspace:*" "@snx-v3/useAccountPermissions": "workspace:*" "@snx-v3/useAccountProxy": "workspace:*" @@ -5244,7 +5245,7 @@ __metadata: languageName: unknown linkType: soft -"@snx-v3/useAccountCollateral@workspace:liquidity/lib/useAccountCollateral": +"@snx-v3/useAccountCollateral@workspace:*, @snx-v3/useAccountCollateral@workspace:liquidity/lib/useAccountCollateral": version: 0.0.0-use.local resolution: "@snx-v3/useAccountCollateral@workspace:liquidity/lib/useAccountCollateral" dependencies: From a1b06e18c449618a5bd334fed32eda1916cc6cc4 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sun, 22 Dec 2024 17:07:00 +1100 Subject: [PATCH 08/11] Show Max --- .../ui/src/components/Withdraw/Withdraw.tsx | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/liquidity/ui/src/components/Withdraw/Withdraw.tsx b/liquidity/ui/src/components/Withdraw/Withdraw.tsx index a971d14f..0b40b23f 100644 --- a/liquidity/ui/src/components/Withdraw/Withdraw.tsx +++ b/liquidity/ui/src/components/Withdraw/Withdraw.tsx @@ -86,17 +86,15 @@ export function Withdraw({ isDebtWithdrawal = false }: { isDebtWithdrawal?: bool value={maxWithdrawable} />   - {maxWithdrawable.gt(0) && ( - setWithdrawAmount(maxWithdrawable)} - color="cyan.500" - fontWeight={700} - > - Max - - )} + setWithdrawAmount(maxWithdrawable)} + color="cyan.500" + fontWeight={700} + > + Max + ) : null} From e5c0edb77eb4a624f404d09db042abda8a387796 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sun, 22 Dec 2024 17:12:02 +1100 Subject: [PATCH 09/11] Cleanup --- liquidity/ui/src/components/Manage/CollateralStats.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/liquidity/ui/src/components/Manage/CollateralStats.tsx b/liquidity/ui/src/components/Manage/CollateralStats.tsx index 41281a58..df870a9b 100644 --- a/liquidity/ui/src/components/Manage/CollateralStats.tsx +++ b/liquidity/ui/src/components/Manage/CollateralStats.tsx @@ -98,8 +98,3 @@ export function CollateralStats({ ); } - -//totalAssigned -302.8257661995; -// -302.8257661995; From 2c5921208df24bd9c966dc4266b5ee9a1fdcad16 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sun, 22 Dec 2024 17:41:27 +1100 Subject: [PATCH 10/11] Test withdrawals with clearing debt and undelegation --- .../e2e/8453-andromeda/USDC_Withdraw.e2e.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js index 20724e02..12ca1cca 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js @@ -3,17 +3,14 @@ import { makeSearch } from '@snx-v3/useParams'; describe(__filename, () => { Cypress.env('chainId', '8453'); Cypress.env('preset', 'andromeda'); - Cypress.env('walletAddress', '0xDf29B49eDE0289ba00a507E900552C46deed0DAc'); - Cypress.env('accountId', '1'); - - // Cypress.env('walletAddress', '0xc77b0cd1B1E73F6De8f606685Fb09Ace95f614c3'); - // Cypress.env('accountId', '170141183460469231731687303715884105949'); + Cypress.env('walletAddress', '0xc3Cf311e04c1f8C74eCF6a795Ae760dc6312F345'); + Cypress.env('accountId', '522433293696'); beforeEach(() => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, - block: '22991081', + block: '24030036', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -29,6 +26,9 @@ describe(__filename, () => { it(__filename, () => { cy.setEthBalance({ balance: 100 }); cy.getUSDC({ amount: 1000 }); + cy.clearDebt({ symbol: 'USDC', poolId: 1 }); + // Reduce delegation to 150 + cy.delegateCollateral({ symbol: 'USDC', amount: 150, poolId: 1 }); cy.visit( `?${makeSearch({ @@ -56,8 +56,16 @@ describe(__filename, () => { cy.get('[data-cy="withdraw confirm button"]').should('include.text', 'Execute Transaction'); cy.get('[data-cy="withdraw confirm button"]').click(); + cy.contains('[data-status="error"]', 'AccountActivityTimeoutPending').should('exist'); + cy.get('[data-status="error"] [aria-label="Close"]').click(); + + cy.setWithdrawTimeout({ timeout: '0' }); + + cy.get('[data-cy="withdraw confirm button"]').should('include.text', 'Retry'); + cy.get('[data-cy="withdraw confirm button"]').click(); + cy.contains('[data-status="success"]', 'Collateral successfully Withdrawn', { - timeout: 180_000, + timeout: 120_000, }).should('exist'); }); }); From cfc738bbfb04878c296c73ad6fa428e75fcd3b93 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Sun, 22 Dec 2024 17:52:18 +1100 Subject: [PATCH 11/11] Bypass price checks --- liquidity/cypress/cypress.d.ts | 2 ++ .../cypress/cypress/e2e/1-main/Create_Account.e2e.js | 1 + .../cypress/e2e/1-main/Dashboard_Connected.e2e.js | 1 + liquidity/cypress/cypress/e2e/1-main/SNX_Borrow.e2e.js | 1 + liquidity/cypress/cypress/e2e/1-main/SNX_Close.e2e.js | 1 + .../cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js | 1 + liquidity/cypress/cypress/e2e/1-main/SNX_Repay.e2e.js | 1 + liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js | 1 + .../cypress/cypress/e2e/1-main/SNX_Withdraw.e2e.js | 1 + .../cypress/e2e/1-main/SNX_Withdraw_sUSD.e2e.js | 1 + .../cypress/e2e/42161-main/Claim_All_Rewards.e2e.js | 1 + .../cypress/e2e/42161-main/Create_Account.e2e.js | 1 + .../cypress/e2e/42161-main/Synths_Unwrapping.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/USDC_Borrow.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/USDC_Close.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/USDC_Deposit.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/USDC_Repay.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/USDC_Unlock.e2e.js | 1 + .../cypress/e2e/42161-main/USDC_Withdraw.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/WETH_Borrow.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/WETH_Close.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js | 1 + .../cypress/cypress/e2e/42161-main/WETH_Unlock.e2e.js | 1 + .../cypress/e2e/42161-main/WETH_Withdraw.e2e.js | 1 + .../cypress/e2e/42161-main/WETH_Withdraw_USDx.e2e.js | 1 + .../e2e/8453-andromeda/Claim_All_Rewards.e2e.js | 1 + .../cypress/e2e/8453-andromeda/Create_Account.e2e.js | 1 + .../cypress/e2e/8453-andromeda/USDC_Close.e2e.js | 1 + .../cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js | 1 + .../cypress/e2e/8453-andromeda/USDC_Repay.e2e.js | 1 + .../8453-andromeda/USDC_Unlock_negative_debt.e2e.js | 1 + .../8453-andromeda/USDC_Unlock_positive_debt.e2e.js | 1 + .../cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js | 2 +- .../cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js | 1 + .../e2e/8453-andromeda/stataUSDC_Deposit.e2e.js | 1 + .../cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js | 1 + .../cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js | 1 + .../e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js | 1 + .../cypress/cypress/support/commands/pythBypass.js | 10 ++++++++++ liquidity/cypress/cypress/support/e2e.js | 2 ++ 41 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 liquidity/cypress/cypress/support/commands/pythBypass.js diff --git a/liquidity/cypress/cypress.d.ts b/liquidity/cypress/cypress.d.ts index a1037250..0ed50a6f 100644 --- a/liquidity/cypress/cypress.d.ts +++ b/liquidity/cypress/cypress.d.ts @@ -94,6 +94,8 @@ declare global { getSUSD: ({ address, amount }: { address?: string; amount: number }) => Promise; getSystemToken: ({ address, amount }: { address?: string; amount: number }) => Promise; + + pythBypass: () => Promise; } } } diff --git a/liquidity/cypress/cypress/e2e/1-main/Create_Account.e2e.js b/liquidity/cypress/cypress/e2e/1-main/Create_Account.e2e.js index 3b8648a7..0a5ee729 100644 --- a/liquidity/cypress/cypress/e2e/1-main/Create_Account.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/Create_Account.e2e.js @@ -10,6 +10,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/1-main/Dashboard_Connected.e2e.js b/liquidity/cypress/cypress/e2e/1-main/Dashboard_Connected.e2e.js index 7600d1cf..21241c41 100644 --- a/liquidity/cypress/cypress/e2e/1-main/Dashboard_Connected.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/Dashboard_Connected.e2e.js @@ -10,6 +10,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Borrow.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Borrow.e2e.js index 054fbe46..23427b32 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Borrow.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Borrow.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Close.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Close.e2e.js index fc7ced0f..aa7909c0 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Close.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Close.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 12451142..05184bf8 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Repay.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Repay.e2e.js index 31527d93..df008a0a 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Repay.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 cce6d35a..c7a9dcf3 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw.e2e.js index e1009d1b..e932444b 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw_sUSD.e2e.js b/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw_sUSD.e2e.js index e407617f..88fef315 100644 --- a/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw_sUSD.e2e.js +++ b/liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw_sUSD.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '21233424', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Claim_All_Rewards.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Claim_All_Rewards.e2e.js index 90814c8b..3460f95c 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Claim_All_Rewards.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Claim_All_Rewards.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '285379110', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 997c3896..f786f16e 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Create_Account.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Create_Account.e2e.js @@ -10,6 +10,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/Synths_Unwrapping.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/Synths_Unwrapping.e2e.js index 1980c8a4..96abef43 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/Synths_Unwrapping.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/Synths_Unwrapping.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '285379110', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/USDC_Borrow.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/USDC_Borrow.e2e.js index 4b6dc954..76763056 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/USDC_Borrow.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/USDC_Borrow.e2e.js @@ -14,6 +14,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/USDC_Close.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/USDC_Close.e2e.js index 826a34c0..b159fd25 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/USDC_Close.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/USDC_Close.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/USDC_Deposit.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/USDC_Deposit.e2e.js index 42a28b80..2fb3c8f0 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/USDC_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/USDC_Deposit.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/USDC_Repay.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/USDC_Repay.e2e.js index 9ec67480..97d4da4c 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/USDC_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/USDC_Repay.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '285187379', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/USDC_Unlock.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/USDC_Unlock.e2e.js index d4cb1831..d45f95fe 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/USDC_Unlock.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/USDC_Unlock.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/USDC_Withdraw.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/USDC_Withdraw.e2e.js index 40e55f3b..12757df9 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/USDC_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/USDC_Withdraw.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Borrow.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Borrow.e2e.js index dab26f02..4caa1914 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Borrow.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Borrow.e2e.js @@ -14,6 +14,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Close.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Close.e2e.js index ba8f375e..b51bb424 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Close.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Close.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 62c6291b..8c79d55f 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Deposit.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 a5837ce5..23d5730b 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '285255179', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Unlock.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Unlock.e2e.js index acf8997a..20c9959d 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Unlock.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Unlock.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw.e2e.js index cfd06fb4..6d82eca5 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw_USDx.e2e.js b/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw_USDx.e2e.js index 2af8c0e0..9507a55e 100644 --- a/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw_USDx.e2e.js +++ b/liquidity/cypress/cypress/e2e/42161-main/WETH_Withdraw_USDx.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://arbitrum-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '271813668', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js index 37e40d29..a666ef68 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js @@ -16,6 +16,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '23771246', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 f57ddef6..d277652a 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Create_Account.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Create_Account.e2e.js @@ -10,6 +10,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Close.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Close.e2e.js index 098c2023..570a360c 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Close.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Close.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 8cb122ab..9c90636f 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Deposit.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Repay.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Repay.e2e.js index a5d46773..4faa2e2d 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Repay.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 af9a03b2..9304ac39 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 @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22683522', // negative debt }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 d570f405..49a3e17e 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 @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', // positive debt }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js index 12ca1cca..0d7319c3 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js @@ -12,7 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '24030036', }).then(() => cy.log('Anvil started')); - + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); win.localStorage.setItem( 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 3e1f8579..6ee4e94f 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Close.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 f6aba19e..fb2c45eb 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Deposit.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Deposit.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 191f43bd..b1273201 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Repay.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 d2ff028e..df16d08c 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Unlock.e2e.js @@ -12,6 +12,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); 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 6523155b..ae13250f 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/stataUSDC_Withdraw.e2e.js @@ -15,6 +15,7 @@ describe(__filename, () => { forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, block: '22991081', }).then(() => cy.log('Anvil started')); + cy.pythBypass(); cy.on('window:before:load', (win) => { win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress')); diff --git a/liquidity/cypress/cypress/support/commands/pythBypass.js b/liquidity/cypress/cypress/support/commands/pythBypass.js new file mode 100644 index 00000000..7a271634 --- /dev/null +++ b/liquidity/cypress/cypress/support/commands/pythBypass.js @@ -0,0 +1,10 @@ +import { ethers } from 'ethers'; + +export async function pythBypass() { + const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545'); + await provider.send('hardhat_setCode', [ + '0x1234123412341234123412341234123412341234', + ethers.utils.hexlify(ethers.utils.toUtf8Bytes('FORK')), + ]); + return true; +} diff --git a/liquidity/cypress/cypress/support/e2e.js b/liquidity/cypress/cypress/support/e2e.js index fcca7286..97059365 100644 --- a/liquidity/cypress/cypress/support/e2e.js +++ b/liquidity/cypress/cypress/support/e2e.js @@ -14,6 +14,7 @@ import { wrapEth } from './commands/wrapEth'; import { setWithdrawTimeout } from './commands/setWithdrawTimeout'; import { getSUSD } from './commands/getSUSD'; import { getSystemToken } from './commands/getSystemToken'; +import { pythBypass } from './commands/pythBypass'; installLogsCollector({ enableExtendedCollector: true, @@ -44,6 +45,7 @@ addTxnCommand('setEthBalance', setEthBalance, { timeout: 30_000 }); addTxnCommand('setWithdrawTimeout', setWithdrawTimeout, { timeout: 60_000 }); addTxnCommand('wrapCollateral', wrapCollateral, { timeout: 120_000 }); addTxnCommand('wrapEth', wrapEth, { timeout: 60_000 }); +addTxnCommand('pythBypass', pythBypass); function subgraph(req) { const body = JSON.parse(req.body);