-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(orders-table): adjust execution price formula (#3305)
- Loading branch information
Showing
2 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
apps/cowswap-frontend/src/legacy/state/orders/orderPrice.test.ts
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,36 @@ | ||
import { USDC_MAINNET, WETH_MAINNET } from '@cowprotocol/common-const' | ||
import { OrderClass } from '@cowprotocol/cow-sdk' | ||
import { Price } from '@uniswap/sdk-core' | ||
|
||
import { Order } from './actions' | ||
import { getEstimatedExecutionPrice } from './utils' | ||
|
||
const getOrderWithFee = (sellAmountBeforeFee: number, buyAmount: number, fee: number): Order => ({ | ||
id: '', | ||
inputToken: WETH_MAINNET, | ||
outputToken: USDC_MAINNET, | ||
sellAmountBeforeFee: sellAmountBeforeFee.toString(), | ||
sellAmount: (sellAmountBeforeFee - fee).toString(), | ||
buyAmount: buyAmount.toString(), | ||
class: OrderClass.LIMIT, | ||
}) | ||
|
||
describe('getEstimatedExecutionPrice()', () => { | ||
it('Should take the fee into account for the estimated execution price calculation', () => { | ||
const fee = 0.00021 * 10 ** WETH_MAINNET.decimals | ||
const sellAmountBeforeFee = 100 * 10 ** WETH_MAINNET.decimals | ||
const buyAmount = 182000 * 10 ** USDC_MAINNET.decimals | ||
|
||
const fillPrice = new Price(WETH_MAINNET, USDC_MAINNET, '10000000000', '1') | ||
|
||
const orderWithFee = getOrderWithFee(sellAmountBeforeFee, buyAmount, fee) | ||
const executionPriceWithFee = getEstimatedExecutionPrice(orderWithFee, fillPrice, fee.toString()) | ||
|
||
const zeroFee = 0 | ||
const orderWithoutFee = getOrderWithFee(sellAmountBeforeFee, buyAmount, zeroFee) | ||
const executionPriceWithoutFee = getEstimatedExecutionPrice(orderWithoutFee, fillPrice, zeroFee.toString()) | ||
|
||
expect(executionPriceWithFee?.toFixed(12)).toEqual('1820.007835117276') | ||
expect(executionPriceWithoutFee?.toFixed(12)).toEqual('1820.000000000000') | ||
}) | ||
}) |
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