Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
calintje committed Nov 15, 2024
1 parent 9a32a10 commit d54d855
Show file tree
Hide file tree
Showing 17 changed files with 356 additions and 249 deletions.
17 changes: 9 additions & 8 deletions docs/whirlpool/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { themes } from "prism-react-renderer";
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";

export default {
title: "Whirlpools",
Expand Down Expand Up @@ -30,9 +30,10 @@ export default {
docs: {
routeBasePath: "/",
sidebarPath: "./sidebars.js",
editUrl: "https://github.com/orca-so/whirlpools/tree/main/docs/whirlpool",
editUrl:
"https://github.com/orca-so/whirlpools/tree/main/docs/whirlpool",
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex]
rehypePlugins: [rehypeKatex],
},
theme: {
customCss: "./static/index.css",
Expand All @@ -43,11 +44,11 @@ export default {

stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
type: 'text/css',
href: "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css",
type: "text/css",
integrity:
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
crossorigin: 'anonymous',
"sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM",
crossorigin: "anonymous",
},
],

Expand Down
57 changes: 30 additions & 27 deletions docs/whirlpool/src/theme/DocCard/index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
import React from 'react';
import clsx from 'clsx';
import Link from '@docusaurus/Link';
import React from "react";
import clsx from "clsx";
import Link from "@docusaurus/Link";
import {
useDocById,
findFirstSidebarItemLink,
} from '@docusaurus/plugin-content-docs/client';
import {usePluralForm} from '@docusaurus/theme-common';
import isInternalUrl from '@docusaurus/isInternalUrl';
import {translate} from '@docusaurus/Translate';
import Heading from '@theme/Heading';
import styles from './styles.module.css';
} from "@docusaurus/plugin-content-docs/client";
import { usePluralForm } from "@docusaurus/theme-common";
import isInternalUrl from "@docusaurus/isInternalUrl";
import { translate } from "@docusaurus/Translate";
import Heading from "@theme/Heading";
import styles from "./styles.module.css";

function useCategoryItemsPlural() {
const {selectMessage} = usePluralForm();
const { selectMessage } = usePluralForm();
return (count) =>
selectMessage(
count,
translate(
{
message: '1 item|{count} items',
id: 'theme.docs.DocCard.categoryDescription.plurals',
message: "1 item|{count} items",
id: "theme.docs.DocCard.categoryDescription.plurals",
description:
'The default description for a category card in the generated index about how many items this category includes',
"The default description for a category card in the generated index about how many items this category includes",
},
{count},
{ count },
),
);
}
function CardContainer({href, children}) {
function CardContainer({ href, children }) {
return (
<Link
href={href}
className={clsx('card padding--lg', styles.cardContainer)}>
className={clsx("card padding--lg", styles.cardContainer)}
>
{children}
</Link>
);
}
function CardLayout({href, icon, title, description}) {
function CardLayout({ href, icon, title, description }) {
return (
<CardContainer href={href}>
<Heading
as="h2"
className={clsx('text--truncate', styles.cardTitle)}
title={title}>
className={clsx("text--truncate", styles.cardTitle)}
title={title}
>
{icon} {title}
</Heading>
{description && (
<p
className={clsx('text--truncate', styles.cardDescription)}
title={description}>
className={clsx("text--truncate", styles.cardDescription)}
title={description}
>
{description}
</p>
)}
</CardContainer>
);
}
function CardCategory({item}) {
function CardCategory({ item }) {
const href = findFirstSidebarItemLink(item);
const categoryItemsPlural = useCategoryItemsPlural();
// Unexpected: categories that don't have a link have been filtered upfront
Expand All @@ -71,8 +74,8 @@ function CardCategory({item}) {
/>
);
}
function CardLink({item}) {
const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
function CardLink({ item }) {
const icon = isInternalUrl(item.href) ? "📄️" : "🔗";
const doc = useDocById(item.docId ?? undefined);
return (
<CardLayout
Expand All @@ -83,11 +86,11 @@ function CardLink({item}) {
/>
);
}
export default function DocCard({item}) {
export default function DocCard({ item }) {
switch (item.type) {
case 'link':
case "link":
return <CardLink item={item} />;
case 'category':
case "category":
return <CardCategory item={item} />;
default:
throw new Error(`unknown item type ${JSON.stringify(item)}`);
Expand Down
2 changes: 1 addition & 1 deletion legacy-sdk/whirlpool/src/types/public/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ORCA_WHIRLPOOLS_CONFIG = new PublicKey(
* @category Constants
*/
export const ORCA_WHIRLPOOLS_CONFIG_ECLIPSE = new PublicKey(
"FVG4oDbGv16hqTUbovjyGmtYikn6UBEnazz6RVDMEFwv",
"FVG4oDbGv16hqTUbovjyGmtYikn6UBEnazz6RVDMEFwv",
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn handler(

if with_token_metadata {
let (name, symbol, uri) = build_position_token_metadata(position_mint, position, whirlpool);

initialize_token_metadata_extension(
name,
symbol,
Expand Down
29 changes: 18 additions & 11 deletions programs/whirlpool/src/math/token_math.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::errors::ErrorCode;
use crate::math::{Q64_RESOLUTION, Q64_MASK};
use crate::math::{Q64_MASK, Q64_RESOLUTION};

use super::{
div_round_up_if, div_round_up_if_u256, mul_u256,
U256Muldiv, MAX_SQRT_PRICE_X64, MIN_SQRT_PRICE_X64,
div_round_up_if, div_round_up_if_u256, mul_u256, U256Muldiv, MAX_SQRT_PRICE_X64,
MIN_SQRT_PRICE_X64,
};

// Fee rate is represented as hundredths of a basis point.
Expand Down Expand Up @@ -110,14 +110,13 @@ pub fn try_get_amount_delta_a(
if result > u64::MAX as u128 {
return Ok(AmountDeltaU64::ExceedsMax(ErrorCode::TokenMaxExceeded));
}
Ok(AmountDeltaU64::Valid(result as u64))
},

Ok(AmountDeltaU64::Valid(result as u64))
}
Err(err) => Ok(AmountDeltaU64::ExceedsMax(err)),
}
}


//
// Get change in token_b corresponding to a change in price
//
Expand Down Expand Up @@ -162,12 +161,20 @@ pub fn try_get_amount_delta_b(

let should_round = round_up && (p & Q64_MASK > 0);
if should_round && result == u64::MAX {
return Ok(AmountDeltaU64::ExceedsMax(ErrorCode::MultiplicationOverflow));
return Ok(AmountDeltaU64::ExceedsMax(
ErrorCode::MultiplicationOverflow,
));
}

Ok(AmountDeltaU64::Valid(if should_round { result + 1 } else { result }))

Ok(AmountDeltaU64::Valid(if should_round {
result + 1
} else {
result
}))
} else {
Ok(AmountDeltaU64::ExceedsMax(ErrorCode::MultiplicationShiftRightOverflow))
Ok(AmountDeltaU64::ExceedsMax(
ErrorCode::MultiplicationShiftRightOverflow,
))
}
}

Expand Down
Loading

0 comments on commit d54d855

Please sign in to comment.