-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #878 from bancorprotocol/issue-#702
Undercut option to duplicate strategy flow
- Loading branch information
Showing
14 changed files
with
393 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { | ||
CreateStrategyTestCase, | ||
MyStrategyDriver, | ||
assertRecurringTestCase, | ||
} from './../../../utils/strategy'; | ||
import { NotificationDriver } from './../../../utils/NotificationDriver'; | ||
import { ManageStrategyDriver } from './../../../utils/strategy/ManageStrategyDriver'; | ||
import { waitModalOpen } from '../../../utils/modal'; | ||
|
||
export const undercutStrategyTest = (testCase: CreateStrategyTestCase) => { | ||
assertRecurringTestCase(testCase); | ||
const { base, quote } = testCase.input; | ||
const output = testCase.output.undercut; | ||
return test('Undercut', async ({ page }) => { | ||
const manage = new ManageStrategyDriver(page); | ||
const strategy = await manage.createStrategy(testCase.input); | ||
await strategy.clickManageEntry('manage-strategy-duplicateStrategy'); | ||
|
||
const modal = await waitModalOpen(page); | ||
await modal.getByTestId('undercut-strategy-btn').click(); | ||
|
||
await page.waitForURL('/strategies/create?strategy=*', { | ||
timeout: 10_000, | ||
}); | ||
|
||
await page.getByText('Create Strategy').click(); | ||
await page.waitForURL('/', { timeout: 10_000 }); | ||
|
||
const notif = new NotificationDriver(page, 'create-strategy'); | ||
await expect(notif.getTitle()).toHaveText('Success'); | ||
await expect(notif.getDescription()).toHaveText( | ||
'New strategy was successfully created.' | ||
); | ||
|
||
const myStrategies = new MyStrategyDriver(page); | ||
const strategies = await myStrategies.getAllStrategies(); | ||
await expect(strategies).toHaveCount(2); | ||
|
||
const strategyUndercut = await myStrategies.getStrategy(2); | ||
await expect(strategyUndercut.pair()).toHaveText(`${base}/${quote}`); | ||
await expect(strategyUndercut.status()).toHaveText('Active'); | ||
await expect(strategyUndercut.totalBudget()).toHaveText(output.totalFiat); | ||
await expect(strategyUndercut.buyBudget()).toHaveText(output.buy.budget); | ||
await expect(strategyUndercut.buyBudgetFiat()).toHaveText(output.buy.fiat); | ||
await expect(strategyUndercut.sellBudget()).toHaveText(output.sell.budget); | ||
await expect(strategyUndercut.sellBudgetFiat()).toHaveText( | ||
output.sell.fiat | ||
); | ||
|
||
const buyTooltip = await strategyUndercut.priceTooltip('buy'); | ||
await expect(buyTooltip.startPrice()).toHaveText(output.buy.min); | ||
await buyTooltip.waitForDetached(); | ||
|
||
const sellTooltip = await strategyUndercut.priceTooltip('sell'); | ||
await expect(sellTooltip.startPrice()).toHaveText(output.sell.min); | ||
await sellTooltip.waitForDetached(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/libs/modals/modals/ModalDuplicateStrategy/ModalDuplicateStrategy.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
import { SafeDecimal } from 'libs/safedecimal'; | ||
import { deepCopy, getUndercutStrategy } from './utils'; | ||
|
||
type StrategyStatus = 'active' | 'noBudget' | 'paused' | 'inactive'; | ||
|
||
const baseStrategy = { | ||
id: '', | ||
idDisplay: '', | ||
base: { | ||
address: '', | ||
decimals: 18, | ||
symbol: 'ETH', | ||
}, | ||
quote: { | ||
address: '', | ||
decimals: 6, | ||
symbol: 'USDC', | ||
}, | ||
order0: { | ||
balance: '', | ||
startRate: '', | ||
endRate: '', | ||
marginalRate: '', | ||
}, | ||
order1: { | ||
balance: '', | ||
startRate: '', | ||
endRate: '', | ||
marginalRate: '', | ||
}, | ||
status: 'active' as StrategyStatus, | ||
encoded: { | ||
id: '', | ||
token0: '', | ||
token1: '', | ||
order0: { | ||
y: '', | ||
z: '', | ||
A: '', | ||
B: '', | ||
}, | ||
order1: { | ||
y: '', | ||
z: '', | ||
A: '', | ||
B: '', | ||
}, | ||
}, | ||
roi: new SafeDecimal('0'), | ||
}; | ||
|
||
let undercutStrategy = deepCopy(baseStrategy); | ||
|
||
describe('Test undercut strategy', () => { | ||
test('getUndercutStrategy with 0.1% rate', () => { | ||
const undercutDifference = 0.001; | ||
|
||
baseStrategy.order0.startRate = '0'; | ||
baseStrategy.order0.endRate = '1700'; | ||
baseStrategy.order1.startRate = '1800'; | ||
baseStrategy.order1.endRate = '1900'; | ||
undercutStrategy.order0.startRate = '0'; | ||
undercutStrategy.order0.endRate = '1701.7'; | ||
undercutStrategy.order1.startRate = '1798.2'; | ||
undercutStrategy.order1.endRate = '1898.1'; | ||
|
||
expect(getUndercutStrategy(baseStrategy, undercutDifference)).toStrictEqual( | ||
undercutStrategy | ||
); | ||
}); | ||
|
||
test('getUndercutStrategy with 0.1% rate and a strategy with one limit order', () => { | ||
const undercutDifference = 0.001; | ||
|
||
baseStrategy.order0.startRate = '0'; | ||
baseStrategy.order0.endRate = '0'; | ||
baseStrategy.order1.startRate = '1900'; | ||
baseStrategy.order1.endRate = '1900'; | ||
undercutStrategy.order0.startRate = '0'; | ||
undercutStrategy.order0.endRate = '0'; | ||
undercutStrategy.order1.startRate = '1898.1'; | ||
undercutStrategy.order1.endRate = '1898.1'; | ||
|
||
expect(getUndercutStrategy(baseStrategy, undercutDifference)).toStrictEqual( | ||
undercutStrategy | ||
); | ||
}); | ||
|
||
test('getUndercutStrategy with 1% rate', () => { | ||
const undercutDifference = 0.01; | ||
|
||
baseStrategy.order0.startRate = '1600'; | ||
baseStrategy.order0.endRate = '1700'; | ||
baseStrategy.order1.startRate = '1800'; | ||
baseStrategy.order1.endRate = '1900'; | ||
undercutStrategy.order0.startRate = '1616'; | ||
undercutStrategy.order0.endRate = '1717'; | ||
undercutStrategy.order1.startRate = '1782'; | ||
undercutStrategy.order1.endRate = '1881'; | ||
|
||
expect(getUndercutStrategy(baseStrategy, undercutDifference)).toStrictEqual( | ||
undercutStrategy | ||
); | ||
}); | ||
|
||
test('getUndercutStrategy with negative rate', () => { | ||
const undercutDifference = -1; | ||
|
||
baseStrategy.order0.startRate = '1600'; | ||
baseStrategy.order0.endRate = '1700'; | ||
baseStrategy.order1.startRate = '1800'; | ||
baseStrategy.order1.endRate = '1900'; | ||
undercutStrategy.order0.startRate = '1616'; | ||
undercutStrategy.order0.endRate = '1717'; | ||
undercutStrategy.order1.startRate = '1782'; | ||
undercutStrategy.order1.endRate = '1881'; | ||
|
||
expect(() => | ||
getUndercutStrategy(baseStrategy, undercutDifference) | ||
).toThrow(); | ||
}); | ||
|
||
test('getUndercutStrategy with rate higher than 100%', () => { | ||
const undercutDifference = 1.01; | ||
|
||
baseStrategy.order0.startRate = '1600'; | ||
baseStrategy.order0.endRate = '1700'; | ||
baseStrategy.order1.startRate = '1800'; | ||
baseStrategy.order1.endRate = '1900'; | ||
undercutStrategy.order0.startRate = '1616'; | ||
undercutStrategy.order0.endRate = '1717'; | ||
undercutStrategy.order1.startRate = '1782'; | ||
undercutStrategy.order1.endRate = '1881'; | ||
|
||
expect(() => | ||
getUndercutStrategy(baseStrategy, undercutDifference) | ||
).toThrow(); | ||
}); | ||
}); |
Oops, something went wrong.