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

BFE-373 Generate Pool Names and Symbols in Creation Order #327

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
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: 14 additions & 3 deletions packages/berajs/src/utils/poolNamings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ import { formatUnits } from "viem";

import { Token } from "~/types";

// Utility function to sort tokens by their address without modifying the original array
const sortTokensByAddress = (tokens: Token[]): Token[] => {
return [...tokens].sort((a, b) =>
a.address.toLowerCase().localeCompare(b.address.toLowerCase()),
);
};

export const generatePoolName = (tokens: Token[]): string => {
if (tokens.length === 0) {
return "";
}
return tokens.map((token) => token.symbol).join(" | ");
return sortTokensByAddress(tokens)
.map((token) => token.symbol)
.join(" | ");
};

export const generatePoolSymbol = (
Expand All @@ -20,13 +29,15 @@ export const generatePoolSymbol = (
if (weights.length === 0) {
return "";
}
return `${tokens
return `${sortTokensByAddress(tokens)
.map((token, index) => {
const weight = weights[index];
const weightPercentage = parseFloat(formatUnits(weight, 18)) * 100;
return `${weightPercentage.toFixed(0)}${token.symbol}`;
})
.join("-")}-${poolTypeString}`;
}
return `${tokens.map((token) => token.symbol).join("-")}-${poolTypeString}`;
return `${sortTokensByAddress(tokens)
.map((token) => token.symbol)
.join("-")}-${poolTypeString}`;
};
Loading