Skip to content

Commit

Permalink
Merge pull request #187 from OasisDEX/ajna-borrow-improvement
Browse files Browse the repository at this point in the history
Ajna Borrowy - Improvements
  • Loading branch information
juan-langa authored Feb 26, 2024
2 parents a980463 + 01540ea commit ab5db76
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 123 deletions.
24 changes: 17 additions & 7 deletions tests/sharedTestSteps/positionManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,25 @@ export const adjustRisk = async ({
};

export const close = async ({
app,
forkId,
app,
positionType,
closeTo,
collateralToken,
debtToken,
tokenAmountAfterClosing,
}: {
app: App;
forkId: string;
app: App;
positionType?: 'Multiply' | 'Borrow' | 'Earn';
closeTo: 'collateral' | 'debt';
collateralToken: string;
debtToken: string;
tokenAmountAfterClosing: string;
}) => {
await app.position.manage.openManageOptions({ currentLabel: 'Adjust' });
await app.position.manage.openManageOptions({
currentLabel: positionType === 'Borrow' ? collateralToken : 'Adjust',
});
await app.position.manage.select('Close position');
if (closeTo === 'debt') {
await app.position.manage.closeTo(debtToken);
Expand Down Expand Up @@ -149,14 +153,21 @@ export const close = async ({
});
await app.position.overview.shouldHaveLoanToValue('0.00');
await app.position.overview.shouldHaveNetValue({ value: '0.00' });
await app.position.overview.shouldHaveBuyingPower('0.00');
await app.position.overview.shouldHaveExposure({ token: collateralToken, amount: '0.00' });
await app.position.overview.shouldHaveDebt({
amount: '0.00',
token: debtToken,
protocol: 'Ajna',
});
await app.position.overview.shouldHaveMultiple('1.00');

if (positionType === 'Borrow') {
await app.position.overview.shouldHaveCollateralDeposited({ amount: '0.00', token: 'RETH' });
await app.position.overview.shouldHaveAvailableToWithdraw({ token: 'RETH', amount: '0.00' });
await app.position.overview.shouldHaveAvailableToBorrow({ token: 'ETH', amount: '0.00' });
} else {
await app.position.overview.shouldHaveExposure({ token: collateralToken, amount: '0.00' });
await app.position.overview.shouldHaveBuyingPower('0.00');
await app.position.overview.shouldHaveMultiple('1.00');
}
};

export const depositAndBorrow = async ({
Expand Down Expand Up @@ -215,7 +226,6 @@ export const withdrawAndPayBack = async ({
expectedCollateralDeposited: { token: string; amount: string };
expectedDebt: { token: string; amount: string };
}) => {
await app.position.manage.withdrawCollateral();
await app.position.manage.withdraw(withdraw);
await app.position.manage.payback(payback);

Expand Down
160 changes: 44 additions & 116 deletions tests/withWallet/ajna/ethereum/ajnaBorrowEthereum.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { BrowserContext, test } from '@playwright/test';
import { metamaskSetUp } from 'utils/setup';
import { resetState } from '@synthetixio/synpress/commands/synpress';
import * as metamask from '@synthetixio/synpress/commands/metamask';
import * as tenderly from 'utils/tenderly';
import { setup } from 'utils/setup';
import { extremelyLongTestTimeout, positionTimeout, veryLongTestTimeout } from 'utils/config';
import { App } from 'src/app';
import { depositAndBorrow, openPosition } from 'tests/sharedTestSteps/positionManagement';
import {
close,
depositAndBorrow,
openPosition,
withdrawAndPayBack,
} from 'tests/sharedTestSteps/positionManagement';

let context: BrowserContext;
let app: App;
Expand Down Expand Up @@ -91,33 +95,17 @@ test.describe('Ajna Ethereum Borrow - Wallet connected', async () => {
test.setTimeout(veryLongTestTimeout);

await app.position.manage.withdrawCollateral();
await app.position.manage.withdraw({ token: 'RETH', amount: '10' });
await app.position.manage.payback({ token: 'ETH', amount: '5' });

await app.position.setup.confirm();

// ============================================================

// UI sometimes gets stuck after confirming position update
// - 'Reload' added to avoid flakines
await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.shouldShowUpdatingPosition();
await app.page.reload();

// ============================================================

await app.position.overview.shouldHaveCollateralDeposited({
amount: '25.00',
token: 'RETH',
timeout: positionTimeout,
});
await app.position.overview.shouldHaveDebt({
amount: '20.[0-9]{2}([0-9]{1,2})?',
token: 'ETH',
protocol: 'Ajna',
await withdrawAndPayBack({
app,
forkId,
withdraw: { token: 'RETH', amount: '10' },
payback: { token: 'ETH', amount: '5' },
expectedCollateralDeposited: {
amount: '25.00',
token: 'RETH',
},
expectedDebt: { amount: '20.[0-9]{2}([0-9]{1,2})?', token: 'ETH' },
});
});

Expand All @@ -132,33 +120,16 @@ test.describe('Ajna Ethereum Borrow - Wallet connected', async () => {
await app.position.manage.openManageOptions({ currentLabel: 'RETH' });
await app.position.manage.select('Manage debt');

await app.position.manage.borrow({ token: 'ETH', amount: '15' });
await app.position.manage.deposit({ token: 'RETH', amount: '20' });

await app.position.setup.confirm();

// ============================================================

// UI sometimes gets stuck after confirming position update
// - 'Reload' added to avoid flakines
await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.shouldShowUpdatingPosition();
await app.page.reload();

// ============================================================

await app.position.overview.shouldHaveCollateralDeposited({
amount: '45.00',
token: 'RETH',
timeout: positionTimeout,
});
await app.position.overview.shouldHaveDebt({
amount: '35.[0-9]{2}([0-9]{1,2})?',
token: 'ETH',
protocol: 'Ajna',
await depositAndBorrow({
app,
forkId,
borrow: { token: 'ETH', amount: '15' },
deposit: { token: 'RETH', amount: '20' },
expectedCollateralDeposited: {
amount: '45.00',
token: 'RETH',
},
expectedDebt: { amount: '35.[0-9]{2}([0-9]{1,2})?', token: 'ETH' },
});
});

Expand All @@ -174,33 +145,17 @@ test.describe('Ajna Ethereum Borrow - Wallet connected', async () => {
await app.position.manage.select('Manage debt');

await app.position.manage.payBackDebt();
await app.position.manage.payback({ token: 'ETH', amount: '20' });
await app.position.manage.withdraw({ token: 'RETH', amount: '15' });

await app.position.setup.confirm();

// ============================================================

// UI sometimes gets stuck after confirming position update
// - 'Reload' added to avoid flakines
await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.shouldShowUpdatingPosition();
await app.page.reload();

// ============================================================

await app.position.overview.shouldHaveCollateralDeposited({
amount: '30.00',
token: 'RETH',
timeout: positionTimeout,
});
await app.position.overview.shouldHaveDebt({
amount: '15.[0-9]{2}([0-9]{1,2})?',
token: 'ETH',
protocol: 'Ajna',
await withdrawAndPayBack({
app,
forkId,
payback: { token: 'ETH', amount: '20' },
withdraw: { token: 'RETH', amount: '15' },
expectedCollateralDeposited: {
amount: '30.00',
token: 'RETH',
},
expectedDebt: { amount: '15.[0-9]{2}([0-9]{1,2})?', token: 'ETH' },
});
});

Expand All @@ -212,42 +167,15 @@ test.describe('Ajna Ethereum Borrow - Wallet connected', async () => {

test.setTimeout(veryLongTestTimeout);

await app.position.manage.openManageOptions({ currentLabel: 'RETH' });
await app.position.manage.select('Close position');
await app.position.manage.shouldHaveTokenAmountAfterClosing({
token: 'RETH',
amount: '[0-9]{1,2}.[0-9]{1,2}',
});

await app.position.setup.confirm();

// ============================================================

// UI sometimes gets stuck after confirming position update
// - 'Reload' added to avoid flakines
await app.position.setup.confirm();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.shouldShowUpdatingPosition();
await app.page.reload();

// ============================================================

await app.position.overview.shouldHaveLiquidationPrice({
price: '0.00',
timeout: positionTimeout,
});
await app.position.overview.shouldHaveLoanToValue('0.00');
await app.position.overview.shouldHaveCollateralDeposited({ amount: '0.00', token: 'RETH' });
await app.position.overview.shouldHaveDebt({
amount: '0.00',
token: 'ETH',
protocol: 'Ajna',
await close({
app,
forkId,
positionType: 'Borrow',
closeTo: 'collateral',
collateralToken: 'RETH',
debtToken: 'ETH',
tokenAmountAfterClosing: '[0-9]{1,2}.[0-9]{1,2}',
});
await app.position.overview.shouldHaveNetValue({ value: '0.00' });
await app.position.overview.shouldHaveAvailableToWithdraw({ token: 'RETH', amount: '0.00' });
await app.position.overview.shouldHaveAvailableToBorrow({ token: 'ETH', amount: '0.00' });
});

test('It should allow to simulate an Ajna Ethereum Borrow position before opening it', async () => {
Expand Down

0 comments on commit ab5db76

Please sign in to comment.