Skip to content

Commit

Permalink
🐛 rollover: use same value
Browse files Browse the repository at this point in the history
  • Loading branch information
jgalat committed Sep 27, 2023
1 parent 3aa0908 commit f72f6dc
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 2 deletions.
5 changes: 3 additions & 2 deletions components/DebtManager/Operation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ function Operation() {
const verifyingContract = pad(trim(marketImpl), { size: 20 });
if (!isAddress(verifyingContract)) return;

const value = await marketContract.read.previewWithdraw([maxBorrowAssets]);
const { v, r, s } = await signTypedDataAsync({
primaryType: 'Permit',
domain: {
Expand All @@ -357,7 +358,7 @@ function Operation() {
message: {
owner: walletAddress,
spender: debtManager.address,
value: await marketContract.read.previewWithdraw([maxBorrowAssets]),
value,
nonce: marketNonce,
deadline,
},
Expand All @@ -366,7 +367,7 @@ function Operation() {
const permit = {
account: walletAddress,
deadline,
value: await marketContract.read.previewWithdraw([maxBorrowAssets]),
value,
...{ v, r: r as Hex, s: s as Hex },
} as const;

Expand Down
152 changes: 152 additions & 0 deletions e2e/specs/6-rollover/op.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { expect } from '@playwright/test';

import base from '../../fixture/base';
import _balance from '../../common/balance';
import _allowance from '../../common/allowance';
import _dashboard from '../../page/dashboard';
import _app from '../../common/app';
import _rollover from '../../components/rollover';
import { getFixedPools } from '../../utils/pools';
import { debtManager } from '../../utils/contracts';

const test = base();

test.describe.configure({ mode: 'serial' });

test('OP rollover', async ({ page, web3, setup }) => {
const pools = getFixedPools();
if (pools.length < 4) throw new Error('Not enough pools');

await web3.fork.setBalance(web3.account.address, {
ETH: 1,
OP: 50_000,
});

await page.goto('/dashboard');

const app = _app({ test, page });
const balance = _balance({ test, page, publicClient: web3.publicClient });
const allowance = _allowance({ test, page, publicClient: web3.publicClient });
const dashboard = _dashboard(page);
const rollover = _rollover(page);

const spender = await debtManager();

await setup.enterMarket('OP');
await setup.deposit({ symbol: 'OP', amount: '30000', receiver: web3.account.address });
await setup.borrow({ symbol: 'OP', amount: '5000', receiver: web3.account.address });

await app.reload();

await test.step('Roll floating debt to fixed', async () => {
await dashboard.switchTab('borrow');
await dashboard.checkFloatingTableRow('borrow', 'OP');

await expect(rollover.cta('floating', 'USDC')).toBeDisabled();
await expect(rollover.cta('floating', 'OP')).not.toBeDisabled();

await rollover.open('floating', 'OP');

await rollover.checkOption('from', { type: 'floating' });
await rollover.checkOption('to', { type: 'empty' });

await rollover.openSheet('to');
await rollover.selectDebt('OP', pools[0]);

await rollover.checkOption('to', { type: 'fixed', maturity: pools[0] });

await rollover.waitForModalReady();

await rollover.submit();

await rollover.waitForTransaction();
await rollover.checkTransactionStatus('success', 'Your position has been refinanced');

await rollover.close();

await balance.check({ address: web3.account.address, symbol: 'OP', amount: '25000' });
await allowance.check({
address: web3.account.address,
type: 'market',
symbol: 'OP',
less: '5',
spender: spender.address,
});

await dashboard.checkFixedTableRow('borrow', 'OP', pools[0]);
});

await test.step('Roll fixed debt to another fixed', async () => {
await dashboard.switchTab('borrow');

await expect(rollover.cta('floating', 'OP')).toBeDisabled();
await expect(rollover.cta('fixed', 'OP', pools[0])).not.toBeDisabled();

await rollover.open('fixed', 'OP', pools[0]);

await rollover.checkOption('from', { type: 'fixed', maturity: pools[0] });
await rollover.checkOption('to', { type: 'empty' });

await rollover.openSheet('to');
await rollover.selectDebt('OP', pools[1]);

await rollover.checkOption('to', { type: 'fixed', maturity: pools[1] });

await rollover.waitForModalReady();

await rollover.submit();

await rollover.waitForTransaction();
await rollover.checkTransactionStatus('success', 'Your position has been refinanced');

await rollover.close();

await balance.check({ address: web3.account.address, symbol: 'OP', amount: '25000' });
await allowance.check({
address: web3.account.address,
type: 'market',
symbol: 'OP',
less: '5',
spender: spender.address,
});

await dashboard.checkFixedTableRow('borrow', 'OP', pools[1]);
});

await test.step('Roll fixed debt to floating', async () => {
await dashboard.switchTab('borrow');

await expect(rollover.cta('floating', 'USDC')).toBeDisabled();
await expect(rollover.cta('fixed', 'OP', pools[1])).not.toBeDisabled();

await rollover.open('fixed', 'OP', pools[1]);

await rollover.checkOption('from', { type: 'fixed', maturity: pools[1] });
await rollover.checkOption('to', { type: 'empty' });

await rollover.openSheet('to');
await rollover.selectDebt('OP');

await rollover.checkOption('to', { type: 'floating' });

await rollover.waitForModalReady();

await rollover.submit();

await rollover.waitForTransaction();
await rollover.checkTransactionStatus('success', 'Your position has been refinanced');

await rollover.close();

await balance.check({ address: web3.account.address, symbol: 'OP', amount: '25000' });
await allowance.check({
address: web3.account.address,
type: 'market',
symbol: 'OP',
less: '5',
spender: spender.address,
});

await dashboard.checkFloatingTableRow('borrow', 'OP');
});
});

0 comments on commit f72f6dc

Please sign in to comment.