Skip to content

Commit

Permalink
chore: Ensure zero addrress is passed for native asset joins
Browse files Browse the repository at this point in the history
  • Loading branch information
garethfuller committed Jul 5, 2023
1 parent efbc3d7 commit 6e1c7b3
Showing 1 changed file with 21 additions and 12 deletions.
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 Down Expand Up @@ -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 All @@ -67,16 +71,7 @@ export class GeneralisedJoinHandler implements JoinPoolHandler {

console.log({ simulationType });

console.log('inputs', {
poolId,
tokenAddresses,
evmAmountsIn,
signerAddress,
slippage,
simulationType,
relayerSignature,
});

console.log('tokenAddresses', tokenAddresses);
this.lastJoinRes = await this.sdk.pools.generalisedJoin(
poolId,
tokenAddresses,
Expand Down Expand Up @@ -106,4 +101,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;
}
}

0 comments on commit 6e1c7b3

Please sign in to comment.