Skip to content

Commit

Permalink
fix: correct protocol fee calculation (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk authored Feb 4, 2025
1 parent 6b83f21 commit 91b0896
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/limit-order/extensions/fee-taker/fee-calculator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {FeeCalculator} from './fee-calculator'
import {IntegratorFee} from './integrator-fee'
import {WhitelistHalfAddress} from './whitelist-half-address'
import {Fees} from './fees'
import {Address} from '../../../address'
import {Bps} from '../../../bps'

describe('FeeCalculator', () => {
it('should calculate protocol fee amount', () => {
// https://etherscan.io/tx/0x8f95dc0e6e836ca0abdad88e20cf61b0caf7c5463d67b577740f3084d428e56e

const calculator = new FeeCalculator(
Fees.integratorFee(
new IntegratorFee(
new Address('0x8e097e5e0493de033270a01b324caf31f464dc67'),
new Address('0x90cbe4bdd538d6e9b379bff5fe72c3d67a521de5'),
new Bps(10n),
new Bps(6000n)
)
),
WhitelistHalfAddress.new([Address.fromBigInt(1n)])
)

const protocolFee = calculator.getProtocolFee(
Address.ZERO_ADDRESS,
18442227n
)

expect(protocolFee).toBe(7377n)
})
})
7 changes: 1 addition & 6 deletions src/limit-order/extensions/fee-taker/fee-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ export class FeeCalculator {
Fees.BASE_1E5 + fees.resolverFee + fees.integratorFee
)

return mulDiv(
total,
Fees.BASE_1E2 -
BigInt(this.fees.integrator.share.toFraction(Fees.BASE_1E2)),
Fees.BASE_1E2
)
return total - this.getIntegratorFee(taker, orderTakingAmount)
}

/**
Expand Down

0 comments on commit 91b0896

Please sign in to comment.