-
Notifications
You must be signed in to change notification settings - Fork 33
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
Adjust JS computations #78
Conversation
@@ -185,14 +185,16 @@ export const placeOrder = async ( | |||
|
|||
const priceFp32 = computeFp32Price(market, limitPrice); | |||
|
|||
const formattedLimitPrice = |
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.
Previously had issue with BN being zero when market.baseDecimals > market.quoteDecimals.
@@ -129,8 +138,13 @@ export class Market { | |||
this._orderbookAddress = orderbookAddress; | |||
this._baseSplTokenMultiplier = new BN(10).pow(new BN(baseDecimals)); | |||
this._quoteSplTokenMultiplier = new BN(10).pow(new BN(quoteDecimals)); | |||
this._tickSize = orderbookState.tickSize.toNumber(); | |||
this._minOrderSize = marketState.minBaseOrderSize.toNumber(); | |||
this._tickSize = roundUiAmount( |
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.
Changed tickSize and minOrderSize to uiAmounts for backwards compatibility with v3.
Adding 'BN' options.
}; | ||
|
||
export const roundUiAmount = (uiAmount: number) => | ||
Number(uiAmount.toPrecision(5)); |
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 is needed as the 2 ^ 32 division leaves weird rounding artifacts 5+ decimals out.
|
||
const scalingExponent = market.quoteDecimals - market.baseDecimals; | ||
|
||
return scalingExponent >= 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.
Needed for cases where market.baseDecimals > market.quoteDecimals, to prevent BN from rounding down to 0.
Can you resolve the conflicts please? |
Closing as no longer relevant with AOB v2. |
Fixes #77