Skip to content

Commit

Permalink
Updating Example, using Map instead of Object;
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiz Gustavo Abou Hatem de Liz committed Jun 16, 2023
1 parent f68e4a9 commit 6a17d8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 6 additions & 7 deletions balancer-js/examples/pools/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ const {
const queryJoin = async (pool: PoolWithMethods) => {
const token = pool.tokensList[0];
const joinExactInQuery = pool.buildQueryJoinExactIn({
maxAmountsIn: pool.tokensList.map((t) =>
parseEther(t === token ? '1' : '0')
),
maxAmountsIn: [parseEther('1')],
tokensIn: [token]
});

const response = await contracts.balancerHelpers.callStatic.queryJoin(
...joinExactInQuery
);

console.log(`Joining ${pool.poolType}`);
console.log(`Joining ${ pool.poolType }`);
console.table({
tokens: pool.tokensList.map((t) => `${t.slice(0, 6)}...${t.slice(38, 42)}`),
tokens: pool.tokensList.map((t) => `${ t.slice(0, 6) }...${ t.slice(38, 42) }`),
amountsIn: response.amountsIn.map(formatEther),
bptOut: formatEther(response.bptOut),
});
Expand All @@ -50,9 +49,9 @@ const queryExit = async (pool: PoolWithMethods) => {
...exitToSingleToken
);

console.log(`Exiting ${pool.poolType}`);
console.log(`Exiting ${ pool.poolType }`);
console.table({
tokens: pool.tokensList.map((t) => `${t.slice(0, 6)}...${t.slice(38, 42)}`),
tokens: pool.tokensList.map((t) => `${ t.slice(0, 6) }...${ t.slice(38, 42) }`),
amountsOut: response.amountsOut.map(formatEther),
bptIn: formatEther(response.bptIn),
});
Expand Down
15 changes: 7 additions & 8 deletions balancer-js/src/modules/pools/queries/params_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ export class ParamsBuilder implements PoolQueries.ParamsBuilder {
this.pool.id.includes(token)
);
// Sort amounts in by token address
const tokenMaxAmountsInByAddress: { [key: string]: BigNumber } =
tokensIn.reduce((acc, tokenAddress, index) => {
return {
...acc,
[tokenAddress]: maxAmountsIn[index],
};
}, {});
const tokenMaxAmountsInByAddress: Map<string, BigNumber> = tokensIn.reduce(
(acc, tokenAddress, index) => {
return acc.set(tokenAddress, maxAmountsIn[index]);
},
new Map<string, BigNumber>()
);

const assets = [...this.pool.tokensList];

let maxInWithoutBpt = this.pool.tokensList.map(
(tokenAddress) =>
tokenMaxAmountsInByAddress[tokenAddress] ?? BigNumber.from('0')
tokenMaxAmountsInByAddress.get(tokenAddress) ?? BigNumber.from('0')
);
// Remove BPT token from amounts for user data
if (bptIndex > -1) {
Expand Down

0 comments on commit 6a17d8f

Please sign in to comment.