Skip to content

Commit

Permalink
Merge pull request #327 from berachain/feature/bex/generate-pool-name…
Browse files Browse the repository at this point in the history
…s-in-creation-order

BFE-373 Generate Pool Names and Symbols in Creation Order
  • Loading branch information
bearpong authored Jan 11, 2025
2 parents 5e25d6d + 6a73133 commit 9c7b8e0
Showing 1 changed file with 14 additions and 3 deletions.
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}`;
};

0 comments on commit 9c7b8e0

Please sign in to comment.