-
Notifications
You must be signed in to change notification settings - Fork 51
Fees Math #31
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
base: crispheaney/off-chain-orders
Are you sure you want to change the base?
Fees Math #31
Conversation
| @@ -0,0 +1,148 @@ | |||
| import { BN, ClearingHouseUser, FeeStructure, ZERO } from "@drift-labs/sdk"; | |||
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.
why do these need to be imported from @drift-labs/sdk? I think they should be imported from same package.
|
|
||
| Object.keys(feeStructure.discountTokenTiers).forEach(tier => { | ||
| const possibleDiscount = tryToCalculateTokenDiscountForTier(fee, feeStructure.discountTokenTiers[tier], discountToken); | ||
| if (possibleDiscount > discount) { |
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.
i think this needs to be gt instead of > since it is a BN
| refereeDiscount: BN | ||
| } | ||
|
|
||
| export function calculateFeeForMarketOrder(quoteAssetAmount: BN, feeStructure: FeeStructure, discountToken?: AccountInfo, referrer?: ClearingHouseUser ) : MarketOrderFee { |
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.
instead of passing in ClearingHouseUser as referrer, might just be nice to pass in a boolean so you dont need a whole ClearingHouseUser object
|
|
||
| // https://github.com/indutny/bn.js/pull/277 | ||
| // https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method | ||
| function sqrt (input: BN) { |
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.
we have a similar method here that you can use: https://github.com/drift-labs/protocol-v1/blob/master/sdk/src/math/utils.ts#L3
012a8ef to
e05a4e2
Compare
…into off-chain-orders
Port of the fees.rs