Skip to content

Commit

Permalink
fix(sdk/across): scope query events to user (UMAprotocol#3906)
Browse files Browse the repository at this point in the history
Signed-off-by: David <[email protected]>
  • Loading branch information
daywiss authored May 13, 2022
1 parent 80fc102 commit b0c3ad2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/sdk/src/across/clients/bridgePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,20 @@ export class PoolEventState {
if (!seen) this.addEvent(params);
return !seen;
};
public async read(endBlock: number) {
public async read(endBlock: number, userAddress?: string) {
if (endBlock <= this.startBlock) return this.state;
const events = (
await Promise.all([
...(await this.contract.queryFilter(this.contract.filters.LiquidityAdded(), this.startBlock, endBlock)),
...(await this.contract.queryFilter(this.contract.filters.LiquidityRemoved(), this.startBlock, endBlock)),
...(await this.contract.queryFilter(
this.contract.filters.LiquidityAdded(undefined, undefined, userAddress),
this.startBlock,
endBlock
)),
...(await this.contract.queryFilter(
this.contract.filters.LiquidityRemoved(undefined, undefined, userAddress),
this.startBlock,
endBlock
)),
])
)
.filter(this.filterSeen)
Expand Down Expand Up @@ -517,7 +525,7 @@ export class Client {
const getUserState = new UserState(contract);
const getPoolEventState = this.getOrCreatePoolEvents(poolAddress);
const userState = await getUserState.read(userAddress);
const eventState = await getPoolEventState.read(latestBlock);
const eventState = await getPoolEventState.read(latestBlock, userAddress);
set(this.state, ["users", userAddress, poolAddress], joinUserState(poolState, eventState, userState));
this.emit(["users", userAddress, poolAddress], this.state.users[userAddress][poolAddress]);
}
Expand Down

0 comments on commit b0c3ad2

Please sign in to comment.