Skip to content

Commit

Permalink
feat(worker/uniswap): add more uniswap networks (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu authored Jan 9, 2025
1 parent 7a46ba1 commit 4397a02
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 26 deletions.
56 changes: 53 additions & 3 deletions internal/engine/worker/decentralized/contract/uniswap/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func (w *worker) Platform() string {
func (w *worker) Network() []network.Network {
return []network.Network{
network.Ethereum,
network.Arbitrum,
network.Optimism,
network.Polygon,
network.Base,
network.BinanceSmartChain,
network.Avalanche,
network.Linea,
network.SatoshiVM,
}
Expand Down Expand Up @@ -142,12 +148,21 @@ func (w *worker) matchSwapTransaction(task *source.Task, transaction *ethereum.T
switch *transaction.To {
case // Uniswap V3
uniswap.AddressV3SwapRouter,
uniswap.AddressV3SwapRouterCelo,
uniswap.AddressV3SwapRouter02,
uniswap.AddressV3SwapRouter02Celo,
uniswap.AddressV3SwapRouter02Arbitrum,
uniswap.AddressV3SwapRouter02Optimism,
uniswap.AddressV3SwapRouter02Polygon,
uniswap.AddressV3SwapRouter02Base,
uniswap.AddressV3SwapRouter02BinanceSmartChain,
uniswap.AddressV3SwapRouter02Avalanche,
uniswap.AddressV3SwapRouter02Linea,
uniswap.AddressUniversalRouter01,
uniswap.AddressUniversalRouter01Arbitrum,
uniswap.AddressUniversalRouter01Optimism,
uniswap.AddressUniversalRouter01Polygon,
uniswap.AddressUniversalRouter01Base,
uniswap.AddressUniversalRouter01BinanceSmartChain,
uniswap.AddressUniversalRouter01Avalanche,
uniswap.AddressUniversalRouter02:
return true
case // Uniswap V2
Expand Down Expand Up @@ -183,9 +198,20 @@ func (w *worker) matchLiquidityTransaction(task *source.Task, transaction *ether

switch *task.Transaction.To {
case // Uniswap V3
uniswap.AddressNonfungiblePositionManager,
uniswap.AddressV3Migrator,
uniswap.AddressV3MigratorArbitrum,
uniswap.AddressV3MigratorPolygon,
uniswap.AddressV3MigratorBase,
uniswap.AddressV3MigratorBinanceSmartChain,
uniswap.AddressV3MigratorAvalanche,
uniswap.AddressV3MigratorLinea,
uniswap.AddressNonfungiblePositionManager,
uniswap.AddressNonfungiblePositionManagerArbitrum,
uniswap.AddressNonfungiblePositionManagerPolygon,
uniswap.AddressNonfungiblePositionManagerOptimism,
uniswap.AddressNonfungiblePositionManagerBase,
uniswap.AddressNonfungiblePositionManagerBinanceSmartChain,
uniswap.AddressNonfungiblePositionManagerAvalanche,
uniswap.AddressNonfungiblePositionManagerLinea:
return true
case // Uniswap V2
Expand Down Expand Up @@ -1018,6 +1044,18 @@ func (w *worker) getV3NonfungiblePositionManagerAddress(n network.Network) (comm
switch n {
case network.Ethereum:
return uniswap.AddressNonfungiblePositionManager, nil
case network.Arbitrum:
return uniswap.AddressNonfungiblePositionManagerArbitrum, nil
case network.Optimism:
return uniswap.AddressNonfungiblePositionManagerOptimism, nil
case network.Polygon:
return uniswap.AddressNonfungiblePositionManagerPolygon, nil
case network.Base:
return uniswap.AddressNonfungiblePositionManagerBase, nil
case network.BinanceSmartChain:
return uniswap.AddressNonfungiblePositionManagerBinanceSmartChain, nil
case network.Avalanche:
return uniswap.AddressNonfungiblePositionManagerAvalanche, nil
case network.Linea:
return uniswap.AddressNonfungiblePositionManagerLinea, nil
default:
Expand All @@ -1029,6 +1067,18 @@ func (w *worker) getV3FactoryAddress(n network.Network) (common.Address, error)
switch n {
case network.Ethereum:
return uniswap.AddressV3Factory, nil
case network.Arbitrum:
return uniswap.AddressV3FactoryArbitrum, nil
case network.Optimism:
return uniswap.AddressV3FactoryOptimism, nil
case network.Polygon:
return uniswap.AddressV3FactoryPolygon, nil
case network.Base:
return uniswap.AddressV3FactoryBase, nil
case network.BinanceSmartChain:
return uniswap.AddressV3FactoryBinanceSmartChain, nil
case network.Avalanche:
return uniswap.AddressV3FactoryAvalanche, nil
case network.Linea:
return uniswap.AddressV3FactoryLinea, nil
default:
Expand Down
6 changes: 6 additions & 0 deletions internal/node/component/info/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ var NetworkToWorkersMap = map[network.Network][]worker.Worker{
decentralized.Highlight,
decentralized.Rainbow,
decentralized.Stargate,
decentralized.Uniswap,
decentralized.Zerion,
},
network.Arweave: {
Expand All @@ -339,6 +340,7 @@ var NetworkToWorkersMap = map[network.Network][]worker.Worker{
decentralized.Curve,
decentralized.Rainbow,
decentralized.Stargate,
decentralized.Uniswap,
decentralized.Zerion,
},
network.Base: {
Expand All @@ -347,12 +349,14 @@ var NetworkToWorkersMap = map[network.Network][]worker.Worker{
decentralized.Core,
decentralized.Rainbow,
decentralized.Stargate,
decentralized.Uniswap,
decentralized.Zerion,
},
network.BinanceSmartChain: {
decentralized.Core,
decentralized.Rainbow,
decentralized.Stargate,
decentralized.Uniswap,
decentralized.Zerion,
},
network.Crossbell: {
Expand Down Expand Up @@ -416,6 +420,7 @@ var NetworkToWorkersMap = map[network.Network][]worker.Worker{
decentralized.Optimism,
decentralized.Rainbow,
decentralized.Stargate,
decentralized.Uniswap,
decentralized.Zerion,
},
network.Polygon: {
Expand All @@ -429,6 +434,7 @@ var NetworkToWorkersMap = map[network.Network][]worker.Worker{
decentralized.Polymarket,
decentralized.Rainbow,
decentralized.Stargate,
decentralized.Uniswap,
decentralized.Zerion,
},
network.RSSHub: {
Expand Down
71 changes: 48 additions & 23 deletions provider/ethereum/contract/uniswap/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,55 @@ import (

// https://docs.uniswap.org/
// https://github.com/Uniswap/universal-router/blob/main/deploy-addresses/mainnet.json
// https://docs.uniswap.org/contracts/v3/reference/deployments/
var (
AddressV1Factory = common.HexToAddress("0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95")
AddressV2Migrator = common.HexToAddress("0x16D4F26C15f3658ec65B1126ff27DD3dF2a2996b")
AddressV3MigratorLinea = common.HexToAddress("0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1")
AddressV2SwapRouter01 = common.HexToAddress("0xf164fC0Ec4E93095b804a4795bBe1e041497b92a")
AddressV2SwapRouter02 = common.HexToAddress("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")
AddressV3Migrator = common.HexToAddress("0xa5644e29708357803b5a882d272c41cc0df92b34")
AddressV3SwapRouter = common.HexToAddress("0xE592427A0AEce92De3Edee1F18E0157C05861564")
AddressV3SwapRouterCelo = common.HexToAddress("0x5615CDAb10dc425a742d643d949a7F474C01abc4")
AddressV3SwapRouter02Linea = common.HexToAddress("0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a")
AddressV3SwapRouter02 = common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45")
AddressV3SwapRouter02Celo = common.HexToAddress("0x5615CDAb10dc425a742d643d949a7F474C01abc4")
AddressV3SwapRouter02BinanceSmartChain = common.HexToAddress("0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2")
AddressV2Factory = common.HexToAddress("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f")
AddressV2FactorySAVM = common.HexToAddress("0x1842c9bD09bCba88b58776c7995A9A9bD220A925")
AddressV3Factory = common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
AddressV3FactoryLinea = common.HexToAddress("0x31FAfd4889FA1269F7a13A66eE0fB458f27D72A9")
AddressV3FactoryCelo = common.HexToAddress("0xAfE208a311B21f13EF87E33A90049fC17A7acDEc")
AddressV3FactoryBinanceSmartChain = common.HexToAddress("0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7")
AddressUniversalRouter01 = common.HexToAddress("0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD")
AddressUniversalRouter02 = common.HexToAddress("0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B")
AddressNonfungiblePositionManager = common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")
AddressNonfungiblePositionManagerLinea = common.HexToAddress("0x4615C383F85D0a2BbED973d83ccecf5CB7121463")
AddressV2SwapRouterSAVM = common.HexToAddress("0xC7c934E224e8567df50058A907904b451bD1c57D")
AddressV1Factory = common.HexToAddress("0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95")
AddressV2Migrator = common.HexToAddress("0x16D4F26C15f3658ec65B1126ff27DD3dF2a2996b")
AddressV3Migrator = common.HexToAddress("0xa5644e29708357803b5a882d272c41cc0df92b34")
AddressV3MigratorArbitrum = common.HexToAddress("0xA5644E29708357803b5A882D272c41cC0dF92B34")
AddressV3MigratorPolygon = common.HexToAddress("0xA5644E29708357803b5A882D272c41cC0dF92B34")
AddressV3MigratorBase = common.HexToAddress("0x23cF10b1ee3AdfCA73B0eF17C07F7577e7ACd2d7")
AddressV3MigratorBinanceSmartChain = common.HexToAddress("0x32681814957e0C13117ddc0c2aba232b5c9e760f")
AddressV3MigratorAvalanche = common.HexToAddress("0x44f5f1f5E452ea8d29C890E8F6e893fC0f1f0f97")
AddressV3MigratorLinea = common.HexToAddress("0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1")
AddressV2SwapRouter01 = common.HexToAddress("0xf164fC0Ec4E93095b804a4795bBe1e041497b92a")
AddressV2SwapRouter02 = common.HexToAddress("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")
AddressV3SwapRouter = common.HexToAddress("0xE592427A0AEce92De3Edee1F18E0157C05861564")
AddressV3SwapRouter02 = common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45")
AddressV3SwapRouter02Arbitrum = common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45")
AddressV3SwapRouter02Optimism = common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45")
AddressV3SwapRouter02Polygon = common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45")
AddressV3SwapRouter02Base = common.HexToAddress("0x2626664c2603336E57B271c5C0b26F421741e481")
AddressV3SwapRouter02BinanceSmartChain = common.HexToAddress("0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2")
AddressV3SwapRouter02Avalanche = common.HexToAddress("0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE")
AddressV3SwapRouter02Linea = common.HexToAddress("0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a")
AddressV2Factory = common.HexToAddress("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f")
AddressV2FactorySAVM = common.HexToAddress("0x1842c9bD09bCba88b58776c7995A9A9bD220A925")
AddressV3Factory = common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
AddressV3FactoryArbitrum = common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
AddressV3FactoryOptimism = common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
AddressV3FactoryPolygon = common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984")
AddressV3FactoryBase = common.HexToAddress("0x33128a8fC17869897dcE68Ed026d694621f6FDfD")
AddressV3FactoryBinanceSmartChain = common.HexToAddress("0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7")
AddressV3FactoryAvalanche = common.HexToAddress("0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD")
AddressV3FactoryLinea = common.HexToAddress("0x31FAfd4889FA1269F7a13A66eE0fB458f27D72A9")
AddressUniversalRouter01 = common.HexToAddress("0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD")
AddressUniversalRouter01Arbitrum = common.HexToAddress("0x5E325eDA8064b456f4781070C0738d849c824258")
AddressUniversalRouter01Optimism = common.HexToAddress("0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8")
AddressUniversalRouter01Polygon = common.HexToAddress("0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2")
AddressUniversalRouter01Base = common.HexToAddress("0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD")
AddressUniversalRouter01BinanceSmartChain = common.HexToAddress("0x4Dae2f939ACf50408e13d58534Ff8c2776d45265")
AddressUniversalRouter01Avalanche = common.HexToAddress("0x4Dae2f939ACf50408e13d58534Ff8c2776d45265")
AddressUniversalRouter02 = common.HexToAddress("0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B")
AddressNonfungiblePositionManager = common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")
AddressNonfungiblePositionManagerArbitrum = common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")
AddressNonfungiblePositionManagerOptimism = common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")
AddressNonfungiblePositionManagerPolygon = common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")
AddressNonfungiblePositionManagerBase = common.HexToAddress("0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1")
AddressNonfungiblePositionManagerBinanceSmartChain = common.HexToAddress("0x7b8A01B39D58278b5DE7e48c8449c9f4F5170613")
AddressNonfungiblePositionManagerAvalanche = common.HexToAddress("0x655C406EBFa14EE2006250925e54ec43AD184f8B")
AddressNonfungiblePositionManagerLinea = common.HexToAddress("0x4615C383F85D0a2BbED973d83ccecf5CB7121463")
AddressV2SwapRouterSAVM = common.HexToAddress("0xC7c934E224e8567df50058A907904b451bD1c57D")

EventHashV1ExchangeTokenPurchase = contract.EventHash("TokenPurchase(address,uint256,uint256)")
EventHashV1ExchangeEthPurchase = contract.EventHash("EthPurchase(address,uint256,uint256)")
Expand Down

0 comments on commit 4397a02

Please sign in to comment.