Skip to content

Commit

Permalink
Merge branch 'main' into switch_chain
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jul 8, 2023
2 parents 8752fdb + 6d7f2e0 commit 9d16bd6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/eventindexer/http/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ func (srv *Server) configureRoutes() {
galaxeAPI.GET("/user-proposed-block", srv.UserProposedBlock)
galaxeAPI.GET("/user-proved-block", srv.UserProvedBlock)
galaxeAPI.GET("/user-bridged", srv.UserBridged)
galaxeAPI.GET("/user-swapped-on-taiko", srv.UserSwappedOnTaiko)
}
32 changes: 32 additions & 0 deletions packages/eventindexer/http/user_swapped_on_taiko.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package http

import (
"net/http"

"github.com/cyberhorsey/webutils"
"github.com/labstack/echo/v4"
"github.com/taikoxyz/taiko-mono/packages/eventindexer"
)

func (srv *Server) UserSwappedOnTaiko(c echo.Context) error {
event, err := srv.eventRepo.FirstByAddressAndEventName(
c.Request().Context(),
c.QueryParam("address"),
eventindexer.EventNameSwap,
)
if err != nil {
return webutils.LogAndRenderErrors(c, http.StatusUnprocessableEntity, err)
}

var found bool = false

if event != nil {
found = true
}

return c.JSON(http.StatusOK, &galaxeAPIResponse{
Data: galaxeData{
IsOK: found,
},
})
}
25 changes: 22 additions & 3 deletions packages/eventindexer/indexer/save_swap_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ package indexer
import (
"context"
"encoding/json"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/eventindexer"
"github.com/taikoxyz/taiko-mono/packages/eventindexer/contracts/swap"
)

var (
minTradeAmount = big.NewInt(10000000000000000)
)

func (svc *Service) saveSwapEvents(
ctx context.Context,
chainID *big.Int,
Expand All @@ -24,8 +30,6 @@ func (svc *Service) saveSwapEvents(
for {
event := events.Event

log.Infof("new Swap event for sender: %v", event.Sender.Hex())

if err := svc.saveSwapEvent(ctx, chainID, event); err != nil {
eventindexer.SwapEventsProcessedError.Inc()

Expand All @@ -43,6 +47,21 @@ func (svc *Service) saveSwapEvent(
chainID *big.Int,
event *swap.SwapSwap,
) error {
log.Infof("swap event for sender 0x%v, amount: %v",
common.Bytes2Hex(event.Raw.Topics[2].Bytes()[12:]),
event.Amount0In.String(),
)

// we only want events with > 0.1 ETH swap
if event.Amount0In.Cmp(minTradeAmount) <= 0 && event.Amount1Out.Cmp(minTradeAmount) <= 0 {
log.Infof("skipping skip event, min trade too low. amountIn: %v, amountOut: %v",
event.Amount0In.String(),
event.Amount1Out.String(),
)

return nil
}

marshaled, err := json.Marshal(event)
if err != nil {
return errors.Wrap(err, "json.Marshal(event)")
Expand All @@ -53,7 +72,7 @@ func (svc *Service) saveSwapEvent(
Data: string(marshaled),
ChainID: chainID,
Event: eventindexer.EventNameSwap,
Address: event.Sender.Hex(),
Address: fmt.Sprintf("0x%v", common.Bytes2Hex(event.Raw.Topics[2].Bytes()[12:])),
})
if err != nil {
return errors.Wrap(err, "svc.eventRepo.Save")
Expand Down
2 changes: 0 additions & 2 deletions packages/eventindexer/indexer/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ func (svc *Service) subscribeSwap(ctx context.Context, chainID *big.Int, errChan
errChan <- errors.Wrap(err, "sub.Err()")
case event := <-sink:
go func() {
log.Infof("swap event for sender %v", event.Sender.Hex())

if err := svc.saveSwapEvent(ctx, chainID, event); err != nil {
eventindexer.SwapEventsProcessedError.Inc()

Expand Down
30 changes: 15 additions & 15 deletions packages/website/components/BlogSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
const posts = [
{
title: "Alpha-3 testnet update: stats & future plans",
href: "https://taiko.mirror.xyz/LBukIvc5nRfNdbzk3_bDZNkBRSmavFp_D90IkBYCuFk",
description:
"Alpha-3 has been drumming along for one month now! Let's take a look at what’s happened.",
date: "Jul 07, 2023",
datetime: "2023-07-07",
imageUrl:
"https://mirror-media.imgix.net/publication-images/4vqDxKbexLf3eX3d4GtRB.jpeg?height=512&width=1024&h=512&w=1024&auto=compress",
readingTime: "2 min",
author: {
name: "d1onys1us",
imageUrl: "https://avatars.githubusercontent.com/u/13951458?v=4",
},
},
{
title: "ZK-Roller-Coaster #8",
href: "https://taiko.mirror.xyz/tOUCZgLRV9bKH24bxhahISpdhkQmqVyM-ZX-wMWtqkI",
Expand Down Expand Up @@ -29,21 +44,6 @@ const posts = [
imageUrl: "https://avatars.githubusercontent.com/u/106527861?v=4",
},
},
{
title: "L2 MEV wat",
href: "https://taiko.mirror.xyz/VjNjFws6OOVez5YCDMwjy4BUiDqZBHYDvcW4-JZGDkc",
description:
"In this article, we “map” the current landscape of L2 MEV, thinking about different MEV consequences for different L2 designs. We also briefly overview different ways of L2s decentralization and how it might impact L2 MEV.",
date: "Jun 13, 2023",
datetime: "2023-06-13",
imageUrl:
"https://mirror-media.imgix.net/publication-images/Qgm0gbwbCQnU8bm5Y1dGB.png?height=512&width=1024&h=512&w=1024&auto=compress",
readingTime: "15 min",
author: {
name: "Lisa A.",
imageUrl: "https://avatars.githubusercontent.com/u/106527861?v=4",
},
},
];

export default function BlogSection() {
Expand Down

0 comments on commit 9d16bd6

Please sign in to comment.