Skip to content

Commit

Permalink
feat: replace executedSurplusFee with executedFee
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Dec 30, 2024
1 parent b86a2eb commit cdd4bd0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OrderMetaData {
+ fullFeeAmount?: TokenAmount;
+ isLiquidityOrder?: boolean;
+ onchainUser?: Address;
+ executedSurplusFee?: BigUint | null;
+ executedFee?: BigUint | null;
}
class OrderStatus {
Expand Down
16 changes: 8 additions & 8 deletions src/order-book/transformOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ const ORDER: Order = {

describe('transformOrder', () => {
describe('addTotalFeeToOrder', () => {
test('should use executedFeeAmount when executedSurplusFee is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedSurplusFee: '0' }
test('should use executedFeeAmount when executedFee is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedFee: '0' }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('1')
})

test('should use executedSurplusFee when executedFeeAmount is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '0', executedSurplusFee: '1' }
test('should use executedFee when executedFeeAmount is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '0', executedFee: '1' }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('1')
})

test('should use sum of executedFeeAmount and executedSurplusFee', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedSurplusFee: '1' }
test('should use sum of executedFeeAmount and executedFee', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedFee: '1' }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('2')
})

test('should not fail when executedSurplusFee is falsy', () => {
const rawOrder = { ...ORDER, executedSurplusFee: null }
test('should not fail when executedFee is falsy', () => {
const rawOrder = { ...ORDER, executedFee: undefined }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('1234567890')
Expand Down
10 changes: 5 additions & 5 deletions src/order-book/transformOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ export function transformOrder(order: Order): EnrichedOrder {
/**
* Add the total fee to the order.
*
* The total fee of the order will be represented by the `totalFee` field, which is the sum of `executedSurplusFee`
* The total fee of the order will be represented by the `totalFee` field, which is the sum of `executedFee`
* and `executedFeeAmount`.
*
* Note that either `executedSurplusFee` or `executedFeeAmount` may be `0`, or both might have a non `0` value.
* Note that either `executedFee` or `executedFeeAmount` may be `0`, or both might have a non `0` value.
*
* See https://cowservices.slack.com/archives/C036G0J90BU/p1705322037866779?thread_ts=1705083817.684659&cid=C036G0J90BU
*
* @param dto The order to add the total fee to.
* @returns The order with the total fee added.
*/
function addTotalFeeToOrder(dto: Order): EnrichedOrder {
const { executedFeeAmount, executedSurplusFee } = dto
const { executedFeeAmount, executedFee } = dto

const _executedFeeAmount = BigInt(executedFeeAmount || '0')
const _executedSurplusFee = BigInt(executedSurplusFee || '0')
const _executedFee = BigInt(executedFee || '0')

const totalFee = String(_executedFeeAmount + _executedSurplusFee)
const totalFee = String(_executedFeeAmount + _executedFee)

return {
...dto,
Expand Down

0 comments on commit cdd4bd0

Please sign in to comment.