Skip to content

Commit

Permalink
Add chainId to add/remove liquidity query outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoguerios committed Mar 12, 2024
1 parent 68e783d commit ed69b5f
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export class AddLiquidityComposableStable implements AddLiquidityBase {
bptOut,
amountsIn,
tokenInIndex: amounts.tokenInIndex,
bptIndex,
chainId: input.chainId,
vaultVersion: 2,
bptIndex,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase {
poolId: poolState.id,
bptOut,
amountsIn,
chainId: input.chainId,
tokenInIndex: amounts.tokenInIndex,
vaultVersion: 2,
};
Expand Down
3 changes: 2 additions & 1 deletion src/entities/addLiquidity/addLiquidityV3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export class AddLiquidityV3 implements AddLiquidityBase {
addLiquidityKind: input.kind,
bptOut,
amountsIn,
vaultVersion: 3,
tokenInIndex,
chainId: input.chainId,
vaultVersion: 3,
};

return output;
Expand Down
2 changes: 1 addition & 1 deletion src/entities/addLiquidity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type AddLiquidityBaseQueryOutput = {
addLiquidityKind: AddLiquidityKind;
bptOut: TokenAmount;
amountsIn: TokenAmount[];
chainId: number;
tokenInIndex?: number;
vaultVersion: 2 | 3;
};
Expand All @@ -56,7 +57,6 @@ export type AddLiquidityQueryOutput =

export type AddLiquidityBaseBuildCallInput = {
slippage: Slippage;
chainId: number;
wethIsEth?: boolean;
} & AddLiquidityBaseQueryOutput;

Expand Down
1 change: 0 additions & 1 deletion src/entities/removeLiquidity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export type RemoveLiquidityQueryOutput =

export type RemoveLiquidityBaseBuildCallInput = {
slippage: Slippage;
chainId: number;
wethIsEth?: boolean;
} & RemoveLiquidityBaseQueryOutput;

Expand Down
30 changes: 21 additions & 9 deletions test/lib/utils/addLiquidityHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
AddLiquidityUnbalancedInput,
Address,
BALANCER_ROUTER,
ChainId,
NATIVE_ASSETS,
PoolState,
Slippage,
Expand Down Expand Up @@ -58,7 +57,6 @@ async function sdkAddLiquidity({
let addLiquidityBuildInput: AddLiquidityBuildCallInput = {
...addLiquidityQueryOutput,
slippage,
chainId: addLiquidityInput.chainId,
wethIsEth: !!wethIsEth,
};
if (poolState.vaultVersion === 2) {
Expand Down Expand Up @@ -162,7 +160,6 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) {
}

export function assertAddLiquidityUnbalanced(
chainId: ChainId,
poolState: PoolState,
addLiquidityInput: AddLiquidityUnbalancedInput,
addLiquidityOutput: AddLiquidityOutput,
Expand All @@ -175,7 +172,11 @@ export function assertAddLiquidityUnbalanced(

// Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList)
const expectedAmountsIn = poolState.tokens.map((t) => {
const token = new Token(chainId, t.address, t.decimals);
const token = new Token(
addLiquidityInput.chainId,
t.address,
t.decimals,
);
const input = addLiquidityInput.amountsIn.find(
(a) => a.address === t.address,
);
Expand All @@ -196,6 +197,7 @@ export function assertAddLiquidityUnbalanced(
poolType: poolState.type,
addLiquidityKind: addLiquidityInput.kind,
vaultVersion: poolState.vaultVersion,
chainId: addLiquidityInput.chainId,
};

const queryCheck = getCheck(addLiquidityQueryOutput, true);
Expand Down Expand Up @@ -226,7 +228,6 @@ export function assertAddLiquidityUnbalanced(
}

export function assertAddLiquiditySingleToken(
chainId: ChainId,
poolState: PoolState,
addLiquidityInput: AddLiquiditySingleTokenInput,
addLiquidityOutput: AddLiquidityOutput,
Expand All @@ -240,7 +241,11 @@ export function assertAddLiquiditySingleToken(
if (addLiquidityQueryOutput.tokenInIndex === undefined)
throw addLiquiditySingleTokenShouldHaveTokenInIndexError;

const bptToken = new Token(chainId, poolState.address, 18);
const bptToken = new Token(
addLiquidityInput.chainId,
poolState.address,
18,
);

const tokensWithoutBpt = poolState.tokens.filter(
(t) => t.address !== poolState.address,
Expand All @@ -263,6 +268,7 @@ export function assertAddLiquiditySingleToken(
poolType: poolState.type,
addLiquidityKind: addLiquidityInput.kind,
vaultVersion: poolState.vaultVersion,
chainId: addLiquidityInput.chainId,
};

const queryCheck = getCheck(addLiquidityQueryOutput, false);
Expand Down Expand Up @@ -300,7 +306,6 @@ export function assertAddLiquiditySingleToken(
}

export function assertAddLiquidityProportional(
chainId: ChainId,
poolState: PoolState,
addLiquidityInput: AddLiquidityProportionalInput,
addLiquidityOutput: AddLiquidityOutput,
Expand All @@ -311,7 +316,11 @@ export function assertAddLiquidityProportional(
const { txOutput, addLiquidityQueryOutput, addLiquidityBuildCallOutput } =
addLiquidityOutput;

const bptToken = new Token(chainId, poolState.address, 18);
const bptToken = new Token(
addLiquidityInput.chainId,
poolState.address,
18,
);

const expectedQueryOutput: Omit<
AddLiquidityQueryOutput,
Expand All @@ -329,6 +338,7 @@ export function assertAddLiquidityProportional(
poolType: poolState.type,
addLiquidityKind: addLiquidityInput.kind,
vaultVersion: poolState.vaultVersion,
chainId: addLiquidityInput.chainId,
};

const queryCheck = getCheck(addLiquidityQueryOutput, false);
Expand All @@ -354,7 +364,9 @@ export function assertAddLiquidityProportional(
if (wethIsEth) {
expect(
addLiquidityOutput.addLiquidityQueryOutput.amountsIn.some((t) =>
t.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped),
t.token.isSameAddress(
NATIVE_ASSETS[addLiquidityInput.chainId].wrapped,
),
),
).to.be.true;
}
Expand Down
Loading

0 comments on commit ed69b5f

Please sign in to comment.