From eff25d62d1d32df146f93826bdbc9f7197cf85c0 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 24 Feb 2023 13:25:11 -0300 Subject: [PATCH] Fix updateTokenBalance for Linear pools --- src/pools/linearPool/linearPool.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pools/linearPool/linearPool.ts b/src/pools/linearPool/linearPool.ts index 9823fa4e..3b5effb8 100644 --- a/src/pools/linearPool/linearPool.ts +++ b/src/pools/linearPool/linearPool.ts @@ -301,15 +301,19 @@ export class LinearPool implements PoolBase { // Updates the balance of a given token for the pool updateTokenBalanceForPool(token: string, newBalance: BigNumber): void { - // token is BPT + // token is underlying in the pool + const T = this.tokens.find((t) => isSameAddress(t.address, token)); + if (!T) throw Error('Pool does not contain this token'); + + // update total shares with BPT balance diff if (isSameAddress(this.address, token)) { - this.updateTotalShares(newBalance); - } else { - const T = this.tokens.find((t) => isSameAddress(t.address, token)); - if (!T) throw Error('Pool does not contain this token'); - // Converts to human scaled number and saves. - T.balance = formatFixed(newBalance, T.decimals); + const parsedTokenBalance = parseFixed(T.balance, T.decimals); + const diff = parsedTokenBalance.sub(newBalance); + const newTotalShares = this.totalShares.add(diff); + this.updateTotalShares(newTotalShares); } + // update token balance with new balance + T.balance = formatFixed(newBalance, T.decimals); } updateTotalShares(newTotalShares: BigNumber): void {