Skip to content

Commit

Permalink
Exclude locked collateral from available to withdraw. (#121)
Browse files Browse the repository at this point in the history
* Exclude locked collateral from available to withdraw.

* locked amount in positions table.

* fix: svg

* Remove mainnet check

* Fix `maxWithdrawable` logic to cover all scenarios

* Dont filter by mainnet

* Deps

* Show Max

* Cleanup

* Test withdrawals with clearing debt and undelegation

* Bypass price checks

* delegateCollateralAndromeda task

---------

Co-authored-by: Noisekit <[email protected]>
Co-authored-by: Noisekit <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2024
1 parent cbdacd8 commit d3749a0
Show file tree
Hide file tree
Showing 53 changed files with 427 additions and 28 deletions.
2 changes: 1 addition & 1 deletion liquidity/components/ClaimModal/ClaimSuccessBanner.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
16 changes: 16 additions & 0 deletions liquidity/cypress/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ declare global {
poolId: number;
}) => Promise<void>;

delegateCollateralAndromeda: ({
address,
accountId,
symbol,
amount,
poolId,
}: {
address?: string;
accountId?: string;
symbol: string;
amount: number;
poolId: number;
}) => Promise<void>;

depositCollateral: ({
address,
accountId,
Expand Down Expand Up @@ -94,6 +108,8 @@ declare global {
getSUSD: ({ address, amount }: { address?: string; amount: number }) => Promise<void>;

getSystemToken: ({ address, amount }: { address?: string; amount: number }) => Promise<void>;

pythBypass: () => Promise<void>;
}
}
}
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/Create_Account.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/SNX_Borrow.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/SNX_Close.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/SNX_Deposit.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/SNX_Repay.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/SNX_Unlock.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/1-main/SNX_Withdraw.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/42161-main/USDC_Close.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/42161-main/USDC_Repay.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/42161-main/WETH_Close.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions liquidity/cypress/cypress/e2e/42161-main/WETH_Repay.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
18 changes: 10 additions & 8 deletions liquidity/cypress/cypress/e2e/8453-andromeda/USDC_Withdraw.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ 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.pythBypass();
cy.on('window:before:load', (win) => {
win.localStorage.setItem('MAGIC_WALLET', Cypress.env('walletAddress'));
win.localStorage.setItem(
Expand All @@ -29,6 +26,10 @@ describe(__filename, () => {
it(__filename, () => {
cy.setEthBalance({ balance: 100 });
cy.getUSDC({ amount: 1000 });
// Reduce delegation to 150
cy.delegateCollateralAndromeda({ symbol: 'sUSDC', amount: 150, poolId: 1 });
// Remove withdrawals delay
cy.setWithdrawTimeout({ timeout: '0' });

cy.visit(
`?${makeSearch({
Expand All @@ -46,6 +47,7 @@ describe(__filename, () => {

cy.get('[data-cy="withdraw amount input"]').should('exist');
cy.get('[data-cy="withdraw amount input"]').type('1');

cy.get('[data-cy="withdraw submit"]').should('be.enabled');
cy.get('[data-cy="withdraw submit"]').click();

Expand All @@ -57,7 +59,7 @@ describe(__filename, () => {
cy.get('[data-cy="withdraw confirm button"]').click();

cy.contains('[data-status="success"]', 'Collateral successfully Withdrawn', {
timeout: 180_000,
timeout: 120_000,
}).should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Loading

0 comments on commit d3749a0

Please sign in to comment.