From 731c0cdb716a071d5b491247e846f406059073cb Mon Sep 17 00:00:00 2001 From: Vu Tien Date: Wed, 18 Dec 2024 09:19:02 +0700 Subject: [PATCH 1/2] update balances potential issue from litepsm/makerpsm/lido-steth/liquiditybook --- pkg/liquidity-source/litepsm/pool_simulator.go | 1 + pkg/source/lido-steth/pool_simulator.go | 6 +++--- pkg/source/liquiditybookv20/pool_simulator.go | 2 +- pkg/source/liquiditybookv21/pool_simulator.go | 2 +- pkg/source/makerpsm/pool_simulator.go | 1 + 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/liquidity-source/litepsm/pool_simulator.go b/pkg/liquidity-source/litepsm/pool_simulator.go index 7e6c0fa09..d84684b5d 100644 --- a/pkg/liquidity-source/litepsm/pool_simulator.go +++ b/pkg/liquidity-source/litepsm/pool_simulator.go @@ -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) diff --git a/pkg/source/lido-steth/pool_simulator.go b/pkg/source/lido-steth/pool_simulator.go index 56ccddb8e..e927e2044 100644 --- a/pkg/source/lido-steth/pool_simulator.go +++ b/pkg/source/lido-steth/pool_simulator.go @@ -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) } } diff --git a/pkg/source/liquiditybookv20/pool_simulator.go b/pkg/source/liquiditybookv20/pool_simulator.go index 3d7cf87ce..ce67d5c1c 100644 --- a/pkg/source/liquiditybookv20/pool_simulator.go +++ b/pkg/source/liquiditybookv20/pool_simulator.go @@ -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) } } diff --git a/pkg/source/liquiditybookv21/pool_simulator.go b/pkg/source/liquiditybookv21/pool_simulator.go index be8e53176..f1559a581 100644 --- a/pkg/source/liquiditybookv21/pool_simulator.go +++ b/pkg/source/liquiditybookv21/pool_simulator.go @@ -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) } } diff --git a/pkg/source/makerpsm/pool_simulator.go b/pkg/source/makerpsm/pool_simulator.go index 2d4cb3e41..f110195e1 100644 --- a/pkg/source/makerpsm/pool_simulator.go +++ b/pkg/source/makerpsm/pool_simulator.go @@ -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) From e67432e51213f85ec2bea5c2aaee73768acd2324 Mon Sep 17 00:00:00 2001 From: Vu Tien Date: Fri, 20 Dec 2024 08:54:09 +0700 Subject: [PATCH 2/2] revert lido-steth since it mint shares while deposit eth --- pkg/source/lido-steth/pool_simulator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/source/lido-steth/pool_simulator.go b/pkg/source/lido-steth/pool_simulator.go index e927e2044..56ccddb8e 100644 --- a/pkg/source/lido-steth/pool_simulator.go +++ b/pkg/source/lido-steth/pool_simulator.go @@ -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).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) + 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) } else { - p.Info.Reserves[0] = new(big.Int).Sub(p.Info.Reserves[0], params.TokenAmountOut.Amount) + p.Info.Reserves[0] = new(big.Int).Add(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) } }