diff --git a/pkg/liquidity-source/bancor-v3/pool_simulator.go b/pkg/liquidity-source/bancor-v3/pool_simulator.go index e96d4e11d..e40c99af0 100644 --- a/pkg/liquidity-source/bancor-v3/pool_simulator.go +++ b/pkg/liquidity-source/bancor-v3/pool_simulator.go @@ -226,8 +226,8 @@ func (s *PoolSimulator) verifyTokens(sourceToken, targetToken string) error { } func (s *PoolSimulator) transformTokens(tokenIn, tokenOut string) (string, string, bool, bool, error) { - weth := strings.ToLower(valueobject.WETHByChainID[s.chainID]) - if tokenIn != weth && tokenOut != weth { + native := strings.ToLower(valueobject.WrappedNativeMap[s.chainID]) + if tokenIn != native && tokenOut != native { return tokenIn, tokenOut, false, false, nil } @@ -239,7 +239,7 @@ func (s *PoolSimulator) transformTokens(tokenIn, tokenOut string) (string, strin ) var ( - eth = strings.ToLower(valueobject.EtherAddress) + eth = strings.ToLower(valueobject.NativeAddress) ethReserve *uint256.Int wethReserve *uint256.Int @@ -252,21 +252,21 @@ func (s *PoolSimulator) transformTokens(tokenIn, tokenOut string) (string, strin ethReserve = ethPoolData.Liquidity.StakedBalance } - wethPoolData, err := s.getPoolData(weth) + wethPoolData, err := s.getPoolData(native) if err != nil { wethReserve = number.Zero } else { wethReserve = wethPoolData.Liquidity.StakedBalance } - if tokenIn == weth && ethReserve.Cmp(wethReserve) > 0 { + if tokenIn == native && ethReserve.Cmp(wethReserve) > 0 { sourceToken = eth isSourceNative = true } - if (tokenOut == weth) && - ((tokenIn != weth && ethReserve.Cmp(wethReserve) > 0) || - (tokenIn == weth && !isSourceNative)) { + if (tokenOut == native) && + ((tokenIn != native && ethReserve.Cmp(wethReserve) > 0) || + (tokenIn == native && !isSourceNative)) { targetToken = eth isTargetNative = true } diff --git a/pkg/liquidity-source/bancor-v3/pool_tracker.go b/pkg/liquidity-source/bancor-v3/pool_tracker.go index d7a9a31ae..b7e0e23e7 100644 --- a/pkg/liquidity-source/bancor-v3/pool_tracker.go +++ b/pkg/liquidity-source/bancor-v3/pool_tracker.go @@ -177,10 +177,10 @@ func (t *PoolTracker) updatePool( } colByPool[pool] = col reserves = append(reserves, poolData.Liquidity.StakedBalance.String()) - if strings.EqualFold(pool, valueobject.EtherAddress) { + if strings.EqualFold(pool, valueobject.NativeAddress) { nativeIdx = len(tokens) tokens = append(tokens, &entity.PoolToken{ - Address: strings.ToLower(valueobject.WETHByChainID[t.config.ChainID]), + Address: strings.ToLower(valueobject.WrappedNativeMap[t.config.ChainID]), Swappable: true, }) diff --git a/pkg/liquidity-source/bancor-v3/pools_list_updater.go b/pkg/liquidity-source/bancor-v3/pools_list_updater.go index 04ef837b2..d5971a252 100644 --- a/pkg/liquidity-source/bancor-v3/pools_list_updater.go +++ b/pkg/liquidity-source/bancor-v3/pools_list_updater.go @@ -62,7 +62,7 @@ func (u *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte ) for _, tokenAddress := range tokenAddresses { - addr := valueobject.WrapETHLower(tokenAddress, u.config.ChainID) + addr := valueobject.WrapNativeLower(tokenAddress, u.config.ChainID) poolTokens = append(poolTokens, &entity.PoolToken{Address: addr, Swappable: true}) reserves = append(reserves, "0") } diff --git a/pkg/liquidity-source/curve/shared/pools_list_updater.go b/pkg/liquidity-source/curve/shared/pools_list_updater.go index 96fe850e1..013acd372 100644 --- a/pkg/liquidity-source/curve/shared/pools_list_updater.go +++ b/pkg/liquidity-source/curve/shared/pools_list_updater.go @@ -132,8 +132,8 @@ func (u *PoolsListUpdater) GetNewPoolsFromDataSource(ctx context.Context, dataSo for i := range result.Data.PoolData { result.Data.PoolData[i].Address = strings.ToLower(result.Data.PoolData[i].Address) for j := range result.Data.PoolData[i].Coins { - if strings.EqualFold(result.Data.PoolData[i].Coins[j].Address, valueobject.EtherAddress) { - result.Data.PoolData[i].Coins[j].Address = strings.ToLower(valueobject.WETHByChainID[u.config.ChainID]) + if strings.EqualFold(result.Data.PoolData[i].Coins[j].Address, valueobject.NativeAddress) { + result.Data.PoolData[i].Coins[j].Address = strings.ToLower(valueobject.WrappedNativeMap[u.config.ChainID]) result.Data.PoolData[i].Coins[j].IsOrgNative = true } } diff --git a/pkg/liquidity-source/ether-vista/pool_simulator.go b/pkg/liquidity-source/ether-vista/pool_simulator.go index 840331b88..a0add809d 100644 --- a/pkg/liquidity-source/ether-vista/pool_simulator.go +++ b/pkg/liquidity-source/ether-vista/pool_simulator.go @@ -79,7 +79,7 @@ func (s *PoolSimulator) CalcAmountOut(param poolpkg.CalcAmountOutParams) (*poolp } // Take Router fee if swap from ETH -> Token - if valueobject.IsWETH(param.TokenAmountIn.Token, s.chainID) { + if valueobject.IsWrappedNative(param.TokenAmountIn.Token, s.chainID) { fee, _ := uint256.FromBig(s.extra.USDCToETHBuyTotalFee) amountIn.Sub(amountIn, fee) } @@ -103,7 +103,7 @@ func (s *PoolSimulator) CalcAmountOut(param poolpkg.CalcAmountOutParams) (*poolp } amountOut := s.getAmountOut(amountIn, reserveIn, reserveOut) - if valueobject.IsWETH(param.TokenOut, s.chainID) { + if valueobject.IsWrappedNative(param.TokenOut, s.chainID) { fee, _ := uint256.FromBig(s.extra.USDCToETHSellTotalFee) amountOut.Sub(amountOut, fee) } diff --git a/pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go b/pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go index d29882f4e..e7acabdf9 100644 --- a/pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go +++ b/pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go @@ -73,8 +73,8 @@ func (u *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte staticExtraBytes, err := json.Marshal(&StaticExtra{ DexReservesResolver: u.config.DexReservesResolver, - HasNative: strings.EqualFold(curPool.Token0Address.Hex(), valueobject.EtherAddress) || - strings.EqualFold(curPool.Token1Address.Hex(), valueobject.EtherAddress), + HasNative: strings.EqualFold(curPool.Token0Address.Hex(), valueobject.NativeAddress) || + strings.EqualFold(curPool.Token1Address.Hex(), valueobject.NativeAddress), }) if err != nil { return nil, nil, err @@ -112,13 +112,13 @@ func (u *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte }, Tokens: []*entity.PoolToken{ { - Address: valueobject.WrapETHLower(curPool.Token0Address.Hex(), u.config.ChainID), + Address: valueobject.WrapNativeLower(curPool.Token0Address.Hex(), u.config.ChainID), Weight: 1, Swappable: true, Decimals: token0Decimals, }, { - Address: valueobject.WrapETHLower(curPool.Token1Address.Hex(), u.config.ChainID), + Address: valueobject.WrapNativeLower(curPool.Token1Address.Hex(), u.config.ChainID), Weight: 1, Swappable: true, Decimals: token1Decimals, @@ -162,7 +162,7 @@ func (u *PoolsListUpdater) readTokensDecimals(ctx context.Context, token0 common req := u.ethrpcClient.R().SetContext(ctx) - if strings.EqualFold(valueobject.EtherAddress, token0.String()) { + if strings.EqualFold(valueobject.NativeAddress, token0.String()) { decimals0 = 18 } else { req.AddCall(ðrpc.Call{ @@ -173,7 +173,7 @@ func (u *PoolsListUpdater) readTokensDecimals(ctx context.Context, token0 common }, []interface{}{&decimals0}) } - if strings.EqualFold(valueobject.EtherAddress, token1.String()) { + if strings.EqualFold(valueobject.NativeAddress, token1.String()) { decimals1 = 18 } else { req.AddCall(ðrpc.Call{ diff --git a/pkg/liquidity-source/fluid/vault-t1/pool_list_updater.go b/pkg/liquidity-source/fluid/vault-t1/pool_list_updater.go index da045f41d..50dad1b43 100644 --- a/pkg/liquidity-source/fluid/vault-t1/pool_list_updater.go +++ b/pkg/liquidity-source/fluid/vault-t1/pool_list_updater.go @@ -44,8 +44,8 @@ func (u *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte for _, swapPath := range paths { staticExtraBytes, err := json.Marshal(&StaticExtra{ VaultLiquidationResolver: u.config.VaultLiquidationResolver, - HasNative: strings.EqualFold(swapPath.TokenIn.Hex(), valueobject.EtherAddress) || - strings.EqualFold(swapPath.TokenOut.Hex(), valueobject.EtherAddress), + HasNative: strings.EqualFold(swapPath.TokenIn.Hex(), valueobject.NativeAddress) || + strings.EqualFold(swapPath.TokenOut.Hex(), valueobject.NativeAddress), }) if err != nil { return nil, nil, err @@ -57,12 +57,12 @@ func (u *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte Reserves: entity.PoolReserves{"0", "0"}, Tokens: []*entity.PoolToken{ { - Address: valueobject.WrapETHLower(swapPath.TokenIn.Hex(), u.config.ChainID), + Address: valueobject.WrapNativeLower(swapPath.TokenIn.Hex(), u.config.ChainID), Weight: 1, Swappable: true, }, { - Address: valueobject.WrapETHLower(swapPath.TokenOut.Hex(), u.config.ChainID), + Address: valueobject.WrapNativeLower(swapPath.TokenOut.Hex(), u.config.ChainID), Weight: 1, Swappable: true, }, diff --git a/pkg/liquidity-source/frax/sfrxeth/pool_list_updater.go b/pkg/liquidity-source/frax/sfrxeth/pool_list_updater.go index 55195e4f5..71e4ef704 100644 --- a/pkg/liquidity-source/frax/sfrxeth/pool_list_updater.go +++ b/pkg/liquidity-source/frax/sfrxeth/pool_list_updater.go @@ -92,7 +92,7 @@ func (u *PoolsListUpdater) GetNewPools(ctx context.Context, _ []byte) ([]entity. Timestamp: time.Now().Unix(), Tokens: []*entity.PoolToken{ { - Address: valueobject.WrapETHLower(valueobject.EtherAddress, u.config.ChainID), + Address: valueobject.WrapNativeLower(valueobject.NativeAddress, u.config.ChainID), Swappable: true, }, { diff --git a/pkg/liquidity-source/uniswap-v1/pool_list_updater.go b/pkg/liquidity-source/uniswap-v1/pool_list_updater.go index f38a359dc..1b9a24df3 100644 --- a/pkg/liquidity-source/uniswap-v1/pool_list_updater.go +++ b/pkg/liquidity-source/uniswap-v1/pool_list_updater.go @@ -198,7 +198,7 @@ func (u *PoolsListUpdater) initPools(exchanges []ExchangeInfo) ([]entity.Pool, e for _, exchange := range exchanges { token0 := &entity.PoolToken{ - Address: strings.ToLower(valueobject.WETHByChainID[u.config.ChainID]), + Address: strings.ToLower(valueobject.WrappedNativeMap[u.config.ChainID]), Swappable: true, } diff --git a/pkg/liquidity-source/uniswap-v1/pool_tracker.go b/pkg/liquidity-source/uniswap-v1/pool_tracker.go index 28b5c0f61..da1731e9f 100644 --- a/pkg/liquidity-source/uniswap-v1/pool_tracker.go +++ b/pkg/liquidity-source/uniswap-v1/pool_tracker.go @@ -119,7 +119,7 @@ func (d *PoolTracker) getReserves( } for i, token := range tokens { - if valueobject.IsWETH(token.Address, d.config.ChainID) { + if valueobject.IsWrappedNative(token.Address, d.config.ChainID) { req.AddCall(ðrpc.Call{ ABI: multicallABI, Target: d.config.MulticallContractAddress, diff --git a/pkg/liquidity-source/velocore-v2/cpmm/pools_list_updater.go b/pkg/liquidity-source/velocore-v2/cpmm/pools_list_updater.go index 7069e4d03..e61510f14 100644 --- a/pkg/liquidity-source/velocore-v2/cpmm/pools_list_updater.go +++ b/pkg/liquidity-source/velocore-v2/cpmm/pools_list_updater.go @@ -17,7 +17,7 @@ import ( "github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject" ) -var ErrWETHNotFound = errors.New("WETH not found") +var ErrWrappedNativeNotFound = errors.New("wrapped native not found") type PoolsListUpdater struct { config *Config @@ -143,13 +143,13 @@ func (d *PoolsListUpdater) processBatch(ctx context.Context, poolAddresses []com break } - if strings.EqualFold(t, valueobject.EtherAddress) { + if strings.EqualFold(t, valueobject.NativeAddress) { nativeTokenIndex = j - weth, ok := valueobject.WETHByChainID[d.config.ChainID] + native, ok := valueobject.WrappedNativeMap[d.config.ChainID] if !ok { - return nil, ErrWETHNotFound + return nil, ErrWrappedNativeNotFound } - t = strings.ToLower(weth) + t = strings.ToLower(native) } poolTokens = append(poolTokens, &entity.PoolToken{ diff --git a/pkg/source/lido-steth/pool_simulator.go b/pkg/source/lido-steth/pool_simulator.go index 56ccddb8e..d77792cd3 100644 --- a/pkg/source/lido-steth/pool_simulator.go +++ b/pkg/source/lido-steth/pool_simulator.go @@ -19,7 +19,7 @@ type PoolSimulator struct { func NewPoolSimulator(entityPool entity.Pool, chainID valueobject.ChainID) (*PoolSimulator, error) { numTokens := len(entityPool.Tokens) - if numTokens != 2 || !valueobject.IsWETH(entityPool.Tokens[0].Address, chainID) { + if numTokens != 2 || !valueobject.IsWrappedNative(entityPool.Tokens[0].Address, chainID) { return nil, fmt.Errorf("invalid pool tokens %v, %v", entityPool, numTokens) } if numTokens != len(entityPool.Reserves) { @@ -53,7 +53,7 @@ func (p *PoolSimulator) CalcAmountOut(param pool.CalcAmountOutParams) (*pool.Cal tokenOut := param.TokenOut stEth := p.Info.Tokens[1] // can only swap from ETH to stETH - if !valueobject.IsWETH(tokenAmountIn.Token, p.chainID) || !strings.EqualFold(tokenOut, stEth) { + if !valueobject.IsWrappedNative(tokenAmountIn.Token, p.chainID) || !strings.EqualFold(tokenOut, stEth) { return nil, fmt.Errorf("Invalid tokenIn/Out %v %v", tokenAmountIn.Token, tokenOut) } diff --git a/pkg/source/platypus/errors.go b/pkg/source/platypus/errors.go index 532d6d77c..37816e987 100644 --- a/pkg/source/platypus/errors.go +++ b/pkg/source/platypus/errors.go @@ -3,10 +3,10 @@ package platypus import "errors" var ( - ErrInvalidOracleType = errors.New("invalid oracle type") - ErrDivisionByZero = errors.New("division by zero") - ErrPoolPaused = errors.New("pool is paused") - ErrWETHNotFound = errors.New("weth not found") + ErrInvalidOracleType = errors.New("invalid oracle type") + ErrDivisionByZero = errors.New("division by zero") + ErrPoolPaused = errors.New("pool is paused") + ErrWrappedNativeNotFound = errors.New("wrapped native not found") // ErrSameAddress swapping with tokenIn = tokenOut ErrSameAddress = errors.New("SAME_ADDRESS") diff --git a/pkg/source/platypus/pool_simulator.go b/pkg/source/platypus/pool_simulator.go index e49ffb486..b0e8e6208 100644 --- a/pkg/source/platypus/pool_simulator.go +++ b/pkg/source/platypus/pool_simulator.go @@ -262,19 +262,19 @@ func (p *PoolSimulator) _quoteIdealToAmountSAvax( toAsset Asset, fromAmount *big.Int, ) (*big.Int, error) { - weth, ok := valueobject.WETHByChainID[p.ChainID] + native, ok := valueobject.WrappedNativeMap[p.ChainID] if !ok { - return nil, ErrWETHNotFound + return nil, ErrWrappedNativeNotFound } fromToken := fromAsset.UnderlyingToken toToken := toAsset.UnderlyingToken - if strings.EqualFold(toToken, weth) { + if strings.EqualFold(toToken, native) { return wmul(fromAmount, p.SAvaxRate), nil } - if strings.EqualFold(fromToken, weth) { + if strings.EqualFold(fromToken, native) { return wdiv(fromAmount, p.SAvaxRate) } diff --git a/pkg/valueobject/address.go b/pkg/valueobject/address.go index 1b629fa38..23d2fb716 100644 --- a/pkg/valueobject/address.go +++ b/pkg/valueobject/address.go @@ -1,7 +1,8 @@ package valueobject const ( - EtherAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" + EtherAddress = NativeAddress // deprecated: use the correctly named NativeAddress + NativeAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" ZeroAddress = "0x0000000000000000000000000000000000000000" MKRTokenAddress = "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2" DAITokenAddress = "0x6b175474e89094c44da98b954eedeac495271d0f" diff --git a/pkg/valueobject/weth.go b/pkg/valueobject/wrapped_native.go similarity index 73% rename from pkg/valueobject/weth.go rename to pkg/valueobject/wrapped_native.go index def179482..9ebb5c3d7 100644 --- a/pkg/valueobject/weth.go +++ b/pkg/valueobject/wrapped_native.go @@ -4,7 +4,13 @@ import ( "strings" ) -var WETHByChainID = map[ChainID]string{ +var ( + WETHByChainID = WrappedNativeMap // deprecated: use the correctly named WrappedNativeMap + WrapETHLower = WrapNativeLower // deprecated: use the correctly named WrapNativeLower + IsWETH = IsWrappedNative // deprecated: use the correctly named IsWrappedNative +) + +var WrappedNativeMap = map[ChainID]string{ ChainIDEthereum: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", ChainIDEthereumW: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", ChainIDRopsten: "0xc778417E063141139Fce010982780140Aa0cD5Ab", @@ -33,17 +39,17 @@ var WETHByChainID = map[ChainID]string{ ChainIDScroll: "0x5300000000000000000000000000000000000004", ChainIDBlast: "0x4300000000000000000000000000000000000004", ChainIDMantle: "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8", - ChainIDSonic: "0x309C92261178fA0CF748A855e90Ae73FDb79EBc7", + ChainIDSonic: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38", } -// WrapETHLower wraps, if applicable, native token to wrapped token; and then lowercase it. -func WrapETHLower(token string, chainID ChainID) string { - if strings.EqualFold(token, EtherAddress) { - token = WETHByChainID[chainID] +// WrapNativeLower wraps, if applicable, native token to wrapped token; and then lowercase it. +func WrapNativeLower(token string, chainID ChainID) string { + if strings.EqualFold(token, NativeAddress) { + token = WrappedNativeMap[chainID] } return strings.ToLower(token) } -func IsWETH(address string, chainID ChainID) bool { - return strings.EqualFold(address, WETHByChainID[chainID]) +func IsWrappedNative(address string, chainID ChainID) bool { + return strings.EqualFold(address, WrappedNativeMap[chainID]) }