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: re-enable native asset joins for deep pools #3624

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function tokenOptions(address: string): string[] {
return includesAddress(
[wrappedNativeAsset.value.address, nativeAsset.address],
address
) && !isDeepPool.value
)
? [wrappedNativeAsset.value.address, nativeAsset.address]
: [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { buildJoinParams } from '@tests/unit/builders/join-exit.builders';
import {
defaultGasLimit,
defaultTransactionResponse,
defaultTxValue,
} from '@tests/unit/builders/signer';
import { GeneralisedJoinHandler } from './generalised-join.handler';
import { initContractConcernWithDefaultMocks } from '@/dependencies/contract.concern.mocks';
Expand All @@ -31,5 +32,6 @@ test('Successfully executes a generalized join transaction', async () => {
data: defaultGeneralizedJoinResponse.encodedCall,
to: defaultGeneralizedJoinResponse.to,
gasLimit: defaultGasLimit,
value: defaultTxValue,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { TransactionResponse } from '@ethersproject/abstract-provider';
import { Ref } from 'vue';
import { JoinParams, JoinPoolHandler, QueryOutput } from './join-pool.handler';
import { formatFixed, parseFixed } from '@ethersproject/bignumber';
import { bnum, selectByAddress } from '@/lib/utils';
import { bnum, isSameAddress, selectByAddress } from '@/lib/utils';
import { TransactionBuilder } from '@/services/web3/transactions/transaction.builder';
import { configService } from '@/services/config/config.service';
import { AddressZero } from '@ethersproject/constants';

type JoinResponse = Awaited<
ReturnType<BalancerSDK['pools']['generalisedJoin']>
Expand All @@ -30,9 +32,9 @@ export class GeneralisedJoinHandler implements JoinPoolHandler {
}

const txBuilder = new TransactionBuilder(params.signer);
const { to, encodedCall } = this.lastJoinRes;
const { to, encodedCall, value } = this.lastJoinRes;

return txBuilder.raw.sendTransaction({ to, data: encodedCall });
return txBuilder.raw.sendTransaction({ to, data: encodedCall, value });
}

async queryJoin({
Expand All @@ -52,7 +54,9 @@ export class GeneralisedJoinHandler implements JoinPoolHandler {
return parseFixed(value || '0', token.decimals).toString();
});

const tokenAddresses: string[] = amountsIn.map(({ address }) => address);
const tokenAddresses: string[] = amountsIn.map(({ address }) =>
this.formatTokenAddress(address)
);
const signerAddress = await signer.getAddress();
const slippage = slippageBsp.toString();
const poolId = this.pool.value.id;
Expand Down Expand Up @@ -96,4 +100,18 @@ export class GeneralisedJoinHandler implements JoinPoolHandler {
priceImpact,
};
}

/**
* If native asset addres, replaces with zero address because the vault only checks
* for the zero address when joining with native asset.
*/
private formatTokenAddress(address: string): string {
const { nativeAsset } = configService.network.tokens.Addresses;

if (isSameAddress(address, nativeAsset)) {
return AddressZero;
}

return address;
}
}
1 change: 1 addition & 0 deletions tests/unit/builders/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defaultTransactionResponse.data = 'default data';

export const defaultGasLimit = 2;
const defaultEstimatedGas = BigNumber.from(defaultGasLimit);
export const defaultTxValue = BigNumber.from(0);

export function aSigner(...options: Partial<JsonRpcSigner>[]): JsonRpcSigner {
const defaultSigner = mock<JsonRpcSigner>();
Expand Down