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

Add unit tests for createPool.ts #501

Merged
merged 22 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading