Skip to content

Commit

Permalink
Merge pull request #483 from balancer/join-exit-hotfix
Browse files Browse the repository at this point in the history
Enforce join and exit swap to happen only with weighted pools
  • Loading branch information
brunoguerios authored Jul 6, 2023
2 parents 0dabe3d + 7678e90 commit d9a7e85
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit d9a7e85

Please sign in to comment.