Skip to content

Commit

Permalink
Merge pull request #89 from OasisDEX/deposit-extra-collateral
Browse files Browse the repository at this point in the history
Deposit extra collateral
  • Loading branch information
juan-langa authored Nov 27, 2023
2 parents bff718a + 375d643 commit db00136
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ test.describe('Aave v3 Multiply - Arbitrum - Wallet connected', async () => {
});

test.setTimeout(veryLongTestTimeout);

// New fork needed to be able to close a Multiply position
await test.step('Test setup - New fork', async () => {
({ forkId } = await setupNewFork({ app, network: 'arbitrum' }));
Expand Down
32 changes: 22 additions & 10 deletions tests/withWallet/aaveV3/base/aaveV3BorrowBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ test.describe('Aave V3 Borrow - Base - Wallet connected', async () => {
await resetState();
});

test('It should adjust risk of an existent Aave V3 Borrow Base position - Up @regression', async () => {
test('It should deposit extra collateral on an existent Aave V3 Borrow Base position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13065',
description: '13035',
});

test.setTimeout(extremelyLongTestTimeout);
Expand All @@ -50,18 +50,30 @@ test.describe('Aave V3 Borrow - Base - Wallet connected', async () => {
await app.page.goto('/base/aave/v3/2#overview');

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.enter({ token: 'ETH', amount: '15' });

await test.step('Adding some collateral to empty position', async () => {
await app.position.manage.enter({ token: 'ETH', amount: '15' });
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();
await app.position.overview.shouldHaveNetValue({
value: '[0-9]{2},[0-9]{3}.[0-9]{2}',
token: 'USDBC',
});
await app.position.overview.shouldHaveExposure({ amount: '15.00000', token: 'ETH' });
});

test('It should adjust risk of an existent Aave V3 Borrow Base position - Up @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13065',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.openManageOptions({ currentLabel: 'Manage ETH' });
await app.position.manage.select('Adjust');

Expand Down
54 changes: 34 additions & 20 deletions tests/withWallet/aaveV3/ethereum/aaveV3EarnEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {
await resetState();
});

test('It should adjust risk of an existent Aave V3 Earn Ethereum position - Up @regression', async () => {
test('It should deposit extra collateral on an existent Aave V3 Ethereum Earn position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13060',
description: '13078',
});

test.setTimeout(extremelyLongTestTimeout);
Expand All @@ -53,26 +53,40 @@ test.describe('Aave V3 Earn - Ethereum - Wallet connected', async () => {

await app.position.manage.shouldBeVisible('Manage Earn position');

await test.step('Adding some collateral to empty position', async () => {
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.enter({ token: 'WSTETH', amount: '20' });
await expect(async () => {
await app.position.setup.setupAllowance();
await app.position.setup.approveAllowance();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.setup.continueShouldBeVisible();
}).toPass();
await app.position.setup.continue();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Manage collateral');
await app.position.manage.enter({ token: 'WSTETH', amount: '20' });
await expect(async () => {
await app.position.setup.setupAllowance();
await app.position.setup.approveAllowance();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();
await app.position.setup.continueShouldBeVisible();
}).toPass();
await app.position.setup.continue();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.overview.shouldHaveNetValue({
value: '[0-9]{2}.[0-9]{2}ETH',
});
await app.position.overview.shouldHaveTotalCollateral({ amount: '20.00000', token: 'WSTETH' });
});

test('It should adjust risk of an existent Aave V3 Earn Ethereum position - Up @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13060',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Earn position');

const initialLiqPrice = await app.position.manage.getLiquidationPrice();

Expand Down
154 changes: 153 additions & 1 deletion tests/withWallet/spark/sparkBorrow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserContext, test } from '@playwright/test';
import { expect, metamaskSetUp } from 'utils/setup';
import { expect, metamaskSetUp, setupNewFork } from 'utils/setup';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as metamask from '@synthetixio/synpress/commands/metamask';
import * as tenderly from 'utils/tenderly';
Expand Down Expand Up @@ -178,6 +178,158 @@ test.describe('Spark Borrow - Wallet connected', async () => {
await app.position.manage.shouldBeVisible('Manage ');
});

test('It should deposit extra collateral on an existent Spark Borrow position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '11406',
});

test.setTimeout(extremelyLongTestTimeout);

// New fork needed
await test.step('Test setup - New fork', async () => {
({ forkId } = await setupNewFork({ app, network: 'mainnet' }));
await tenderly.setEthBalance({ forkId, ethBalance: '20' });
await tenderly.setWbtcBalance({ forkId, wbtcBalance: '2' });
});

await tenderly.changeAccountOwner({
account: '0x648dd9e11414db57097903a3ed98f773af61ef09',
newOwner: walletAddress,
forkId,
});

await app.page.goto('/ethereum/spark/v3/1669#overview');
await app.position.manage.shouldBeVisible('Manage collateral');

await app.position.manage.enter({ token: 'WBTC', amount: '1' });

// Setting up allowance randomly fails - Retry until it's set.
await expect(async () => {
await app.position.setup.setupAllowance();
await app.position.setup.approveAllowance();
await test.step('Metamask: ConfirmAddToken', async () => {
await metamask.confirmAddToken();
});
await app.position.setup.continueShouldBeVisible();
}).toPass();

await app.position.setup.continue();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.overview.shouldHaveNetValue({
value: '[0-9]{2},[0-9]{3}.[0-9]{2}',
token: 'DAI',
});
await app.position.overview.shouldHaveExposure({ amount: '1.00000', token: 'WBTC' });
});

test('It should adjust risk of an existent Spark Borrow position - Up (WBTC/DAI) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13050',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.select('Adjust');

const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ value: 0.6 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.select('Adjust');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();
expect(updatedLiqPrice).toBeGreaterThan(initialLiqPrice);
expect(updatedLoanToValue).toBeGreaterThan(initialLoanToValue);
});

test('It should adjust risk of an existent Spark Borrow position - Down (WBTC/DAI) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13051',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Borrow position');
const initialLiqPrice = await app.position.manage.getLiquidationPrice();
const initialLoanToValue = await app.position.manage.getLoanToValue();

await app.position.manage.waitForSliderToBeEditable();
await app.position.manage.moveSlider({ value: 0.3 });

await app.position.manage.adjustRisk();
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.position.manage.shouldBeVisible('Manage collateral');
await app.position.manage.openManageOptions({ currentLabel: 'Manage WBTC' });
await app.position.manage.select('Adjust');
const updatedLiqPrice = await app.position.manage.getLiquidationPrice();
const updatedLoanToValue = await app.position.manage.getLoanToValue();

expect(updatedLiqPrice).toBeLessThan(initialLiqPrice);
expect(updatedLoanToValue).toBeLessThan(initialLoanToValue);
});

test('It should close an existent Spark Borrow position - Close to collateral token (WBTC) @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '13077',
});

test.setTimeout(veryLongTestTimeout);

await app.position.manage.shouldBeVisible('Manage Borrow position');
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.select('Close position');
await app.position.manage.closeTo('WBTC');
await app.position.manage.shouldHaveTokenAmountAfterClosing({
token: 'WBTC',
amount: '0.[0-9]{3,4}',
});
await app.position.manage.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});

await app.position.manage.shouldShowSuccessScreen();
await app.position.manage.ok();

await app.page.goto('/ethereum/spark/v3/1669#overview');
await app.position.overview.shouldHaveLiquidationPrice({ price: '0.00', token: 'DAI' });
await app.position.overview.shouldHaveLoanToValue('0.00');
await app.position.overview.shouldHaveBorrowCost('0.00');
await app.position.overview.shouldHaveNetValue({ value: '0.00', token: 'DAI' });
await app.position.overview.shouldHaveExposure({ amount: '0.00000', token: 'WBTC' });
await app.position.overview.shouldHaveDebt({ amount: '0.0000', token: 'DAI' });
});

test.skip('It should list an opened Spark Borrow position in portfolio', async () => {
test.info().annotations.push(
{
Expand Down
20 changes: 20 additions & 0 deletions utils/tenderly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ export const setCbEthBalance = async ({
]);
};

/**
*
* @param wbtcBalance In cbETH units
*/
export const setWbtcBalance = async ({
forkId,
wbtcBalance,
}: {
forkId: string;
wbtcBalance: string;
}) => {
const provider = new JsonRpcProvider(`https://rpc.tenderly.co/fork/${forkId}`);

await provider.send('tenderly_setErc20Balance', [
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
WALLET_ADDRESS,
ethers.toQuantity(ethers.parseUnits(wbtcBalance, 'ether')),
]);
};

/**
*
* @param account Addres of the proxy to take ownershipt of
Expand Down

0 comments on commit db00136

Please sign in to comment.