-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: update totalFee calculation #197
Conversation
const _executedFeeAmount = BigInt(executedFeeAmount || '0') | ||
const _executedSurplusFee = BigInt(executedSurplusFee || '0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using native BigInt to avoid adding a new dependency just for this.
Or should we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this solution looks good.
why the underscore in the consts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because those names already exist in the scope.
Could call then name+BigInt
but I didn't find it a good choice.
Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okok, not big deal. works for me. Also the BigInt works too
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedSurplusFee: '0' } | ||
const transformedOrder = transformOrder(rawOrder) | ||
|
||
expect(transformedOrder.totalFee).toEqual(rawOrder.executedFeeAmount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Why asserting the transformedOrder
totalFee matches the rawOrder executedFeeAmount
?
I would find more readable that given the above, the result is '1' (setting the actual value, instead of picking the property name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(transformedOrder.totalFee).toEqual(rawOrder.executedFeeAmount) | |
expect(transformedOrder.totalFee).toEqual('1') // 1 + 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's meant to be: it's the unaltered value coming from the original order obj.
I feel like that's a better way to ready it than using an actual value.
But sure, will update it.
const rawOrder = { ...ORDER, executedFeeAmount: '0', executedSurplusFee: '1' } | ||
const transformedOrder = transformOrder(rawOrder) | ||
|
||
expect(transformedOrder.totalFee).toEqual(rawOrder.executedSurplusFee) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
const _executedFeeAmount = BigInt(executedFeeAmount || '0') | ||
const _executedSurplusFee = BigInt(executedSurplusFee || '0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this solution looks good.
why the underscore in the consts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some nits
Summary
As per this internal discussion, the backend updated how the fees are returned by the api.
In this PR the calculation is updated to return the sum of
executedSurplusFee
andexecutedFeeAmount
.Context
Take as example this order: https://explorer.cow.fi/orders/0xdedb65b51a6f81493f8e6e1d811b56a57297dbb6fb11716d85e646a66a5d041f85cc3c8da85612013acabe9b5d954d578860b3c165a22c43?tab=overview
Currently it shows as
0
fee, even thoughexecutedFeeAmount
is set.The issue is that this order has both fields
executedSurplusFee
andexecutedFeeAmount
returned, butexecutedSurplusFee
is set to 0.In the current implementation, it takes precedence over
executedFeeAmount
.cow-sdk/src/order-book/transformOrder.ts
Line 28 in 3abfdcf
This logic was introduced over 1y ago and according to this comment from Nick:
According to Dusan:
Test
Unit tests