Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspirit99 committed Oct 17, 2024
1 parent d6f5616 commit 82a61b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 6 additions & 6 deletions pkg/liquidity-source/ringswap/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (s *PoolSimulator) CalcAmountOut(param poolpkg.CalcAmountOutParams) (*poolp
Gas: s.gas.Swap,
SwapInfo: SwapInfo{
IsToken0To1: indexIn%2 == 0,
IsWrapIn: true, // temporary
IsUnwrapOut: true, // temporary
IsWrapIn: indexIn < 2,
IsUnwrapOut: indexOut < 2,
},
}, nil
}
Expand Down Expand Up @@ -174,8 +174,8 @@ func (s *PoolSimulator) CalcAmountIn(param poolpkg.CalcAmountInParams) (*poolpkg
Gas: s.gas.Swap,
SwapInfo: SwapInfo{
IsToken0To1: indexIn%2 == 0,
IsWrapIn: true, // temporary
IsUnwrapOut: true, // temporary
IsWrapIn: indexIn < 2,
IsUnwrapOut: indexOut < 2,
},
}, nil
}
Expand All @@ -186,8 +186,8 @@ func (s *PoolSimulator) UpdateBalance(params poolpkg.UpdateBalanceParams) {
return
}

s.Pool.Info.Reserves[indexIn] = new(big.Int).Add(s.Pool.Info.Reserves[indexIn], params.TokenAmountIn.Amount)
s.Pool.Info.Reserves[indexOut] = new(big.Int).Sub(s.Pool.Info.Reserves[indexOut], params.TokenAmountOut.Amount)
s.Pool.Info.Reserves[indexIn%2] = new(big.Int).Add(s.Pool.Info.Reserves[indexIn%2], params.TokenAmountIn.Amount)
s.Pool.Info.Reserves[indexOut%2] = new(big.Int).Sub(s.Pool.Info.Reserves[indexOut%2], params.TokenAmountOut.Amount)
}

func (s *PoolSimulator) GetMetaInfo(_ string, _ string) interface{} {
Expand Down
17 changes: 12 additions & 5 deletions pkg/liquidity-source/ringswap/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ func (d *PoolTracker) getReserves(ctx context.Context, poolAddress string, logs
}

func (d *PoolTracker) updatePool(pool entity.Pool, reserveData uniswapv2.ReserveData, blockNumber *big.Int) (entity.Pool, error) {
if len(pool.Reserves) >= 2 {
pool.Reserves[0] = reserveData.Reserve0.String()
pool.Reserves[1] = reserveData.Reserve1.String()
pool.BlockNumber = blockNumber.Uint64()
pool.Timestamp = time.Now().Unix()
pool.Reserves = entity.PoolReserves{
reserveData.Reserve0.String(),
reserveData.Reserve1.String(),
"1",
"1",
}

pool.BlockNumber = blockNumber.Uint64()
pool.Timestamp = time.Now().Unix()

return pool, nil
}

Expand All @@ -117,6 +120,10 @@ func (d *PoolTracker) getReservesFromRPCNode(ctx context.Context, poolAddress st
return uniswapv2.ReserveData{}, nil, err
}

// if strings.EqualFold(poolAddress, "0x9BE8a40C9cf00fe33fd84EAeDaA5C4fe3f04CbC3") {
// log.Fatalln(getReservesResult)
// }

return uniswapv2.ReserveData{
Reserve0: getReservesResult.Reserve0,
Reserve1: getReservesResult.Reserve1,
Expand Down

0 comments on commit 82a61b5

Please sign in to comment.