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

Feat boosted pool add and remove #450

Merged
merged 43 commits into from
Oct 30, 2024
Merged

Conversation

mkflow27
Copy link
Contributor

@mkflow27 mkflow27 commented Oct 28, 2024

Created a seperate issue #455 for tracking one outstanding todo.

input: AddLiquidityInput,
poolState: PoolState | PoolStateWithUnderlyings,
): Promise<AddLiquidityBaseQueryOutput> {
// Technically possible to pass singleToken adds here due to type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can change type to be
AddLiquidityUnbalancedInput | AddLiquidityProportionalInput;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the refactor to support optional userData and userAddress, i added new types, so this point has also been addressed, if I understood it correctly.

switch (input.kind) {
case AddLiquidityKind.Unbalanced: {
const bptAmountOut = await doAddLiquidityUnbalancedQuery(
input,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addLiquidity uses getAmounts to fill any missing token amounts because the contract needs values for all. E.g. if user tries to add with only USDC to a aUSDC/aDAI pool. Is this required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added this and now fill the amounts in default values in case the user did not provide all the tokenAmounts he wants to join with.

): Promise<AddLiquidityBaseQueryOutput> {
// Technically possible to pass singleToken adds here due to type
// disallow it for this class
// TODO: Use input validator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of validations I can think of:

  • Protocol version
  • Input amounts are underlying

input.poolId,
input.amountsIn.map((amount) => amount.amount),
amounts.minimumBpt,
!!input.wethIsEth,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcode to false until we can support?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

import { RemoveLiquidityProportionalInput } from 'src';

export const doRemoveLiquidityProportionalQuery = async (
{ rpcUrl, chainId, bptIn }: RemoveLiquidityProportionalInput,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to adds, can update to accept address and userData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed after your refactor ping me to let me know its good for review. I would recommend checking out the nested PR and maybe follow a similar approach which has two benefits imo: 1. Don't need to update all the existing test helpers which are convulted and hard to follow. 2. Makes the approval flow much easier to follow and confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored the tests to not use the helpers and instead do the intermediary steps as part of the tests. I did not change anything in the way how I handle approvals as I think the way they are done in the tests here are fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as add tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I utilise a helper here (which I think is ok) as a precondition for remove liq testing. Similarly I think the way I do approvals is ok. Compared to your tests, you do approvals right in the actualy tests, whereas I spread it.


// Check if userAddress and userData were provided, and assign default values if not
if (!('userAddress' in input) || input.userAddress === undefined) {
// TODO: I think using a random address might be better than using the 0 address.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johngrantuk I think defaulting to the 0 address might not be the right choice but rather a random address. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think zeroAddress is best but maybe you can explain why random is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that it is more likely for a query to return different data than what is expected as it is with a random address. This is probably an exotic scenario, so overall unlikely. So for readability / potential debugging purposes address 0 makes it easiert to work with

decimals
}
}
dynamicData {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I think I can actually remove the changes in the api, since I am not using the api in my tests, as we decided to use mock data. I'll remove it.

...data.poolGetPool,
tokens: data.poolGetPool.poolTokens,
type: mapPoolType(data.poolGetPool.type),
//underlyings: data.poolGetPool.poolTokens.map((token) => {token}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@@ -24,3 +24,5 @@ export * from './types';
export * from './utils';
export * from './swap';
export * from './swap/swaps/v2/auraBalSwaps';
export * from './addLiquidityBoosted';
export * from './removeLiquidityBoostedV3';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed one has V3 and one doesn't, lets use a consistent pattern, I'd say without V3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Renamed the folders to not have v3 anymore. For the classnames I found it easier to leave them with V3. Can also change. What do you think?

@mkflow27 mkflow27 marked this pull request as ready for review October 30, 2024 13:03
@mkflow27 mkflow27 merged commit 06be001 into main Oct 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants