Skip to content

Commit

Permalink
fix: update add/remove liquidity logic (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
frontier159 authored Nov 7, 2023
1 parent 762220a commit 0c0e157
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
17 changes: 13 additions & 4 deletions apps/dapp/src/components/Pages/Ramos/admin/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ export const handleBlur = (value: number | '', minValue: number, maxValue: numbe
return value;
};

export const formatJoinRequestTuple = (request?: IBalancerVault.JoinPoolRequestStruct): string => {
export const formatJoinRequestTuple = (request?: IBalancerVault.JoinPoolRequestStructOutput): string => {
if (request) {
return `[[${request.assets.map((asset) => `"${asset}"`).join(',')}],[${request.maxAmountsIn
.map((amount) => `"${amount}"`)
.join(',')}],"${request.userData}",false]`;
.join(',')}],"${request.userData}",${request.fromInternalBalance}]`;
}
return '';
};

export const formatExitRequestTuple = (request?: IBalancerVault.ExitPoolRequestStruct): string => {
export const formatExitRequestTuple = (request?: IBalancerVault.ExitPoolRequestStructOutput): string => {
if (request) {
return `[[${request?.assets.map((asset) => `"${asset}"`).join(',')}],[${request?.minAmountsOut
.map((amount) => `"${amount}"`)
.join(',')}],"${request?.userData}",false]`;
.join(',')}],"${request.userData}",${request.toInternalBalance}]`;
}
return '';
};
Expand Down Expand Up @@ -84,6 +84,15 @@ export const calculateTargetPriceUp = async (
return currentPrice.add(currentPrice.mul(adjustedBps));
};

export const decodeUserData = (userData: string) => {
const [joinType,amountsIn,bptOut] = ethers.utils.defaultAbiCoder.decode(['uint256', 'uint256[]', 'uint256'], userData);
return {
joinType,
amountsIn,
bptOut,
}
}

export const makeJoinRequest = (tokens: string[], amountsIn: BigNumber[]): IBalancerVault.JoinPoolRequestStruct => {
// 1 === WeightedJoinPoolKind.EXACT_TOKENS_IN_FOR_BPT_OUT
// https://dev.balancer.fi/resources/joins-and-exits/pool-joins
Expand Down
20 changes: 5 additions & 15 deletions apps/dapp/src/components/Pages/Ramos/admin/useRamosAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
applySlippage,
calculateTargetPriceDown,
calculateTargetPriceUp,
decodeUserData,
formatExitRequestTuple,
formatJoinRequestTuple,
getBpsPercentageFromTpf,
Expand Down Expand Up @@ -326,14 +327,10 @@ export function useRamosAdmin() {
slippageTolerance * 100
);
const reqDataQuote = proportionalAddLiquidityQuote.requestData;
const tokenAddrs = reqDataQuote.assets;

const initJoinReq = makeJoinRequest(tokenAddrs, reqDataQuote.maxAmountsIn);
const { amountsIn, bptOut } = await balancerHelpers.queryJoin(poolId, ramos.address, ramos.address, initJoinReq);
const joinPoolRequest = makeJoinRequest(tokenAddrs, amountsIn);
const { bptOut } = decodeUserData(reqDataQuote.userData);
return {
joinPoolRequest: formatJoinRequestTuple(joinPoolRequest),
minBptOut: applySlippage(bptOut, slippageTolerance).toString(),
joinPoolRequest: formatJoinRequestTuple(reqDataQuote),
minBptOut: bptOut,
};
}
};
Expand All @@ -345,14 +342,7 @@ export function useRamosAdmin() {
slippageTolerance * 100
);
const reqDataQuote = proportionalRemoveLiquidityQuote.requestData;

const exitRequest = makeExitRequest(
balPooltokensOrdered,
reqDataQuote.minAmountsOut,
exitAmountBpt,
WeightedPoolExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT
);
return formatExitRequestTuple(exitRequest);
return formatExitRequestTuple(reqDataQuote);
};

const createDepositAndStakeRequest = async (bptAmountIn: DecimalBigNumber) => {
Expand Down

0 comments on commit 0c0e157

Please sign in to comment.