Skip to content

Commit

Permalink
feat(worker/swap): support Uniswap Universal Router for Base network
Browse files Browse the repository at this point in the history
  • Loading branch information
kallydev committed Sep 10, 2023
1 parent b4bbe37 commit 3f69980
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/datasource/ethereum/contract/uniswap/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
AddressUniversalRouterCelo = common.HexToAddress("0xC73d61d192FB994157168Fb56730FdEc64C9Cb8F")
AddressUniversalRouterOptimism = common.HexToAddress("0xb555edF5dcF85f42cEeF1f3630a52A108E55A654")
AddressUniversalRouterPolygon = common.HexToAddress("0x4C60051384bd2d3C01bfc845Cf5F4b44bcbE9de5")
AddressUniversalRouterBase = common.HexToAddress("0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC")

EventHashTransfer = common.BytesToHash(crypto.Keccak256([]byte("Transfer(address,address,uint256)")))
EventHashSwapV2 = common.BytesToHash(crypto.Keccak256([]byte("Swap(address,uint256,uint256,uint256,uint256,address)")))
Expand Down
1 change: 1 addition & 0 deletions service/indexer/internal/worker/exchange/swap/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ var (
strings.ToLower(uniswap.AddressUniversalRouterCelo.String()): routerUniswapV3, // Celo
strings.ToLower(uniswap.AddressUniversalRouterOptimism.String()): routerUniswapV3, // Optimism
strings.ToLower(uniswap.AddressUniversalRouterPolygon.String()): routerUniswapV3, // Polygon
strings.ToLower(uniswap.AddressUniversalRouterBase.String()): routerUniswapV3, // Base
// SushiSwap
// https://docs.sushi.com/docs/Developers/Deployment%20Addresses
strings.ToLower("0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"): routerSushiSwap, // SushiSwap Ethereum
Expand Down
48 changes: 46 additions & 2 deletions service/indexer/internal/worker/exchange/swap/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func Test_service_Handle(t *testing.T) {
wantErr: assert.NoError,
},
// There is currently no way to address the issue of dApp handling fees and native token transfer events.
//{
// {
// name: "curve swap of aave pool",
// fields: fields{
// employer: shedlock.New(),
Expand Down Expand Up @@ -804,7 +804,7 @@ func Test_service_Handle(t *testing.T) {
// return false
// },
// wantErr: assert.NoError,
//},
// },
{
name: "paraswap of curve pool",
fields: fields{
Expand Down Expand Up @@ -1025,6 +1025,50 @@ func Test_service_Handle(t *testing.T) {
},
wantErr: assert.NoError,
},
{
name: "Swap ETH for WETH at Uniswap on Base",
fields: fields{
employer: shedlock.New(),
},
arguments: arguments{
ctx: context.Background(),
message: &protocol.Message{
Address: "0x4802c2c5dae6252e7b3e4b619bbde55e956b2cfd", // Unknown
Network: protocol.NetworkBase,
},
transactions: []model.Transaction{
{
// https://basescan.org/tx/0x0476148000a8ecaaef7b9d857c236de5c3afc0f4d237cbd541e8fd38d65a3412
Hash: "0x0476148000a8ecaaef7b9d857c236de5c3afc0f4d237cbd541e8fd38d65a3412",
BlockNumber: 3782400,
Network: protocol.NetworkBase,
},
},
},
want: func(t assert.TestingT, i interface{}, i2 ...interface{}) bool {
transactions, ok := i.([]model.Transaction)
if !ok {
return false
}

assert.Equal(t, len(transactions), 1)

for _, transaction := range transactions {
assert.Equal(t, len(transaction.Transfers), 1)

var swap metadata.Swap
assert.NoError(t, json.Unmarshal(transaction.Transfers[0].Metadata, &swap))

assert.Equal(t, swap.TokenFrom.Symbol, "WETH")
assert.Equal(t, swap.TokenTo.Symbol, "USDbC")

assert.Equal(t, transaction.Platform, protocol.PlatformUniswap)
}

return false
},
wantErr: assert.NoError,
},
}

for _, testcase := range testcases {
Expand Down

0 comments on commit 3f69980

Please sign in to comment.