Skip to content

Commit

Permalink
update balances potential issue from litepsm/makerpsm/lido-steth/liqu…
Browse files Browse the repository at this point in the history
…iditybook
  • Loading branch information
tien7668 committed Dec 18, 2024
1 parent 910aed6 commit 731c0cd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/liquidity-source/litepsm/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {

if strings.EqualFold(input.Token, DAIAddress) {
p.litePSM.updateBalanceBuyingGem(inputAmount, outputAmount)
return
}

p.litePSM.updateBalanceSellingGem(inputAmount, outputAmount)
Expand Down
6 changes: 3 additions & 3 deletions pkg/source/lido-steth/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func (p *PoolSimulator) CalcAmountOut(param pool.CalcAmountOutParams) (*pool.Cal

func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
if strings.EqualFold(params.TokenAmountIn.Token, p.Info.Tokens[0]) {
p.Info.Reserves[0] = new(big.Int).Add(p.Info.Reserves[0], params.TokenAmountIn.Amount)
p.Info.Reserves[1] = new(big.Int).Add(p.Info.Reserves[1], params.TokenAmountOut.Amount)
p.Info.Reserves[0] = new(big.Int).Sub(new(big.Int).Add(p.Info.Reserves[0], params.TokenAmountIn.Amount), params.Fee.Amount)
p.Info.Reserves[1] = new(big.Int).Sub(p.Info.Reserves[1], params.TokenAmountOut.Amount)
} else {
p.Info.Reserves[0] = new(big.Int).Add(p.Info.Reserves[0], params.TokenAmountOut.Amount)
p.Info.Reserves[0] = new(big.Int).Sub(p.Info.Reserves[0], params.TokenAmountOut.Amount)
p.Info.Reserves[1] = new(big.Int).Sub(new(big.Int).Add(p.Info.Reserves[1], params.TokenAmountIn.Amount), params.Fee.Amount)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/source/liquiditybookv20/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
p.Info.Reserves[idx] = new(big.Int).Add(reserve, params.TokenAmountIn.Amount)
}
if strings.EqualFold(p.Info.Tokens[idx], params.TokenAmountOut.Token) {
p.Info.Reserves[idx] = new(big.Int).Sub(reserve, params.TokenAmountIn.Amount)
p.Info.Reserves[idx] = new(big.Int).Sub(reserve, params.TokenAmountOut.Amount)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/source/liquiditybookv21/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
p.Info.Reserves[idx] = new(big.Int).Add(reserve, params.TokenAmountIn.Amount)
}
if strings.EqualFold(p.Info.Tokens[idx], params.TokenAmountOut.Token) {
p.Info.Reserves[idx] = new(big.Int).Sub(reserve, params.TokenAmountIn.Amount)
p.Info.Reserves[idx] = new(big.Int).Sub(reserve, params.TokenAmountOut.Amount)
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/source/makerpsm/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
input, output := params.TokenAmountIn, params.TokenAmountOut
if strings.EqualFold(input.Token, DAIAddress) {
p.PSM.updateBalanceBuyingGem(input.Amount)
return
}

p.PSM.updateBalanceSellingGem(output.Amount)
Expand Down

0 comments on commit 731c0cd

Please sign in to comment.