Skip to content

Commit

Permalink
Use index provided by the api to sort pool tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoguerios committed Sep 13, 2023
1 parent 2ece720 commit 4d49b3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/entities/join/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type PoolState = {
tokens: {
address: Address;
decimals: number;
}[]; // already properly sorted in case different versions sort them differently
index: number;
}[];
};

// This will be extended for each pools specific input requirements
Expand Down
6 changes: 3 additions & 3 deletions src/entities/join/weighted/weightedJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class WeightedJoin implements BaseJoin {
// TODO: Extend input validation for cases we'd like to check
checkInputs(input, poolState);

const poolTokens = poolState.tokens.map(
(t) => new Token(input.chainId, t.address, t.decimals),
);
const poolTokens = poolState.tokens
.sort((a, b) => a.index - b.index)
.map((t) => new Token(input.chainId, t.address, t.decimals));
let maxAmountsIn = Array(poolTokens.length).fill(MAX_UINT256);
let userData: Address;

Expand Down
7 changes: 6 additions & 1 deletion test/weightedJoin.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ describe('weighted join test', () => {

export class MockApi {
public async getPool(id: Address): Promise<PoolState> {
let tokens: { address: Address; decimals: number }[] = [];
let tokens: { address: Address; decimals: number; index: number }[] =
[];
if (
id ===
'0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'
Expand All @@ -337,10 +338,12 @@ export class MockApi {
{
address: '0xba100000625a3754423978a60c9317c58a424e3d', // BAL
decimals: 18,
index: 0,
},
{
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // wETH
decimals: 18,
index: 1,
},
];
} else if (
Expand All @@ -351,10 +354,12 @@ export class MockApi {
{
address: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', // wstETH slot 0
decimals: 18,
index: 0,
},
{
address: '0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP slot 1
decimals: 18,
index: 1,
},
];
}
Expand Down

0 comments on commit 4d49b3f

Please sign in to comment.