Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Adjust JS computations #78

wants to merge 1 commit into from

Conversation

jhlx
Copy link
Contributor

@jhlx jhlx commented Jun 10, 2022

Fixes #77

@@ -185,14 +185,16 @@ export const placeOrder = async (

const priceFp32 = computeFp32Price(market, limitPrice);

const formattedLimitPrice =
Copy link
Contributor Author

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(
Copy link
Contributor Author

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));
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@dr497
Copy link
Contributor

dr497 commented Jun 12, 2022

Can you resolve the conflicts please?

@jhlx
Copy link
Contributor Author

jhlx commented Jul 16, 2022

Closing as no longer relevant with AOB v2.

@jhlx jhlx closed this Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix backwards compatibility for minOrderSize and tickSize
2 participants