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

Enforce join and exit swap to happen only with weighted pools #483

Merged
merged 1 commit into from
Jul 6, 2023
Merged
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
19 changes: 15 additions & 4 deletions balancer-js/src/modules/swaps/joinExit/joinAndExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export function hasJoinExit(
* @param assets
* @returns
*/
export function isJoin(swap: SwapV2, assets: string[]): boolean {
export function isJoin(
swap: SwapV2,
assets: string[],
poolType: string | undefined
): boolean {
if (poolType !== 'Weighted') return false;
// token[join]bpt
const tokenOut = assets[swap.assetOutIndex];
const poolAddress = getPoolAddress(swap.poolId);
Expand All @@ -87,7 +92,12 @@ export function isJoin(swap: SwapV2, assets: string[]): boolean {
* @param assets
* @returns
*/
export function isExit(swap: SwapV2, assets: string[]): boolean {
export function isExit(
swap: SwapV2,
assets: string[],
poolType: string | undefined
): boolean {
if (poolType !== 'Weighted') return false;
// bpt[exit]token
const tokenIn = assets[swap.assetInIndex];
const poolAddress = getPoolAddress(swap.poolId);
Expand Down Expand Up @@ -143,7 +153,8 @@ export function getActions(
const actions: Actions[] = [];
let opRefKey = 0;
for (const swap of swaps) {
if (isJoin(swap, assets)) {
const poolType = pools.find((p) => p.id === swap.poolId)?.poolType;
if (isJoin(swap, assets, poolType)) {
const newJoin = new Join(
swap,
tokenInIndex,
Expand All @@ -157,7 +168,7 @@ export function getActions(
opRefKey = newJoin.nextOpRefKey;
actions.push(newJoin);
continue;
} else if (isExit(swap, assets)) {
} else if (isExit(swap, assets, poolType)) {
const newExit = new Exit(
swap,
tokenInIndex,
Expand Down