Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix partner fee amount calculation #212

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/cow-sdk",
"version": "5.3.1",
"version": "5.3.2",
"license": "(MIT OR Apache-2.0)",
"files": [
"/dist"
Expand Down
6 changes: 4 additions & 2 deletions src/order-book/quoteAmountsAndCostsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface Params {
partnerFeeBps: number | undefined
}

const ONE_HUNDRED_BPS = BigInt(100 * 100)

export function getQuoteAmountsAndCosts(params: Params): QuoteAmountsAndCosts {
const { orderParams, sellDecimals, buyDecimals, slippagePercentBps } = params
const partnerFeeBps = params.partnerFeeBps ?? 0
Expand Down Expand Up @@ -44,7 +46,7 @@ export function getQuoteAmountsAndCosts(params: Params): QuoteAmountsAndCosts {
* Partner fee is always added on the surplus amount, for sell-orders it's buy amount, for buy-orders it's sell amount
*/
const surplusAmount = isSell ? buyAmountBeforeNetworkCosts.big : sellAmountBeforeNetworkCosts.big
const partnerFeeAmount = partnerFeeBps > 0 ? surplusAmount / BigInt(partnerFeeBps) : BigInt(0)
const partnerFeeAmount = partnerFeeBps > 0 ? (surplusAmount * BigInt(partnerFeeBps)) / ONE_HUNDRED_BPS : BigInt(0)

/**
* Partner fee is always added on the surplus token, for sell-orders it's buy token, for buy-orders it's sell token
Expand All @@ -59,7 +61,7 @@ export function getQuoteAmountsAndCosts(params: Params): QuoteAmountsAndCosts {
buyAmount: buyAmountAfterNetworkCosts.big,
}

const getSlippageAmount = (amount: bigint) => (amount * BigInt(slippagePercentBps)) / BigInt(100 * 100)
const getSlippageAmount = (amount: bigint) => (amount * BigInt(slippagePercentBps)) / ONE_HUNDRED_BPS

/**
* Same rules apply for slippage as for partner fees
Expand Down
Loading