Skip to content

Commit

Permalink
fix: check for stake event
Browse files Browse the repository at this point in the history
  • Loading branch information
bennettyong committed Aug 18, 2024
1 parent 71135c6 commit 47d22c0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion adapters/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TransferLogsIndexer interface {
}

type LPLogsIndexer interface {
Address() common.Address
Address() []common.Address
IndexLogs(ctx context.Context, chainID *big.Int, client *ethclient.Client, logs []types.Log) ([]LPTransfer, error)
ProcessLog(ctx context.Context, chainID *big.Int, client *ethclient.Client, vLog types.Log) (*LPTransfer, error)
}
12 changes: 6 additions & 6 deletions adapters/projects/izumi/transfer_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ var (

// TransferIndexer is an implementation of LogsIndexer for ERC20 transfer logs.
type TransferIndexer struct {
token common.Address
tokens []common.Address
whitelist map[string]struct{}
}

// NewTransferIndexer creates a new TransferIndexer.
func NewTransferIndexer(token common.Address, whitelist map[string]struct{}) *TransferIndexer {
func NewTransferIndexer(tokens []common.Address, whitelist map[string]struct{}) *TransferIndexer {
return &TransferIndexer{
token: token,
tokens: tokens,
whitelist: whitelist,
}
}

func (indexer *TransferIndexer) Address() common.Address {
return indexer.token
func (indexer *TransferIndexer) Address() []common.Address {
return indexer.tokens
}

// IndexLogs processes logs for ERC20 transfers.
Expand Down Expand Up @@ -78,7 +78,7 @@ func (indexer *TransferIndexer) ProcessLog(ctx context.Context, chainID *big.Int
}

// Initialize the LiquidityManager contract caller
liquidityManager, err := izumi.NewIzumiCaller(indexer.token, client)
liquidityManager, err := izumi.NewIzumiCaller(vLog.Address, client)
if err != nil {
return nil, err
}
Expand Down
24 changes: 17 additions & 7 deletions adapters/projects/ritsu/transfer_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ import (

var (
logTransferSigHash = crypto.Keccak256Hash([]byte("Transfer(address,address,uint256)"))
logStakeSigHash = crypto.Keccak256Hash([]byte("Stake(address,uint256,address)"))
)

// TransferIndexer is an implementation of LogsIndexer for ERC20 transfer logs.
type TransferIndexer struct {
token common.Address
tokens []common.Address
whitelist map[string]struct{}
}

// NewTransferIndexer creates a new TransferIndexer.
func NewTransferIndexer(token common.Address, whitelist map[string]struct{}) *TransferIndexer {
func NewTransferIndexer(tokens []common.Address, whitelist map[string]struct{}) *TransferIndexer {
return &TransferIndexer{
token: token,
tokens: tokens,
whitelist: whitelist,
}
}

func (indexer *TransferIndexer) Address() common.Address {
return indexer.token
func (indexer *TransferIndexer) Address() []common.Address {
return indexer.tokens
}

// IndexLogs processes logs for ERC20 transfers.
Expand Down Expand Up @@ -67,7 +68,16 @@ func (indexer *TransferIndexer) ProcessLog(ctx context.Context, chainID *big.Int
if !exists {
return nil, nil
}
from := common.BytesToAddress(vLog.Topics[1].Bytes()[12:])
txReceipt, err := client.TransactionReceipt(ctx, vLog.TxHash)
if err != nil {
return nil, err
}
from := adapters.ZeroAddress
for _, log := range txReceipt.Logs {
if log.Topics[0].Hex() == logStakeSigHash.Hex() {
from = common.BytesToAddress(log.Topics[2].Bytes()[12:])
}
}

// Unpack the transfer event
var transferEvent struct {
Expand All @@ -84,7 +94,7 @@ func (indexer *TransferIndexer) ProcessLog(ctx context.Context, chainID *big.Int
}

// Initialize the LP token caller
token, err := ritsu.NewRitsuCaller(indexer.token, client)
token, err := ritsu.NewRitsuCaller(vLog.Address, client)
if err != nil {
return nil, err
}
Expand Down
16 changes: 12 additions & 4 deletions cmd/lp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ import (

func processRitsuLPIndexer(client *ethclient.Client, blockNumber int64) error {
whitelist := map[string]struct{}{
common.HexToAddress("0x67Cab37067309B664CFB12769FffA2bdc41D8EDe").Hex(): {},
common.HexToAddress("0xaE7850cBbA0d7303eD06661c9B06f4A5127Ca75D").Hex(): {},
common.HexToAddress("0xd7506E9Ebac0Ff14Ce3C600DC6Fd94240e5612D4").Hex(): {},
}
processor := ritsu.NewTransferIndexer(common.HexToAddress("0x7c38E9389B27668280E5aaAc372eBCb2ECc1c5E0"), whitelist)
tokens := []common.Address{
common.HexToAddress("0x7c38E9389B27668280E5aaAc372eBCb2ECc1c5E0"),
common.HexToAddress("0x6c7839E0CE8AdA360a865E18a111A462d08DC15a"),
}
processor := ritsu.NewTransferIndexer(tokens, whitelist)
return processLPLogIndexer(client, processor, blockNumber)
}

func processIziLPIndexer(client *ethclient.Client, blockNumber int64) error {
whitelist := map[string]struct{}{
common.HexToAddress("0x67Cab37067309B664CFB12769FffA2bdc41D8EDe").Hex(): {},
common.HexToAddress("0x88867BF3bB3321d8c7Da71a8eAb70680037068E4").Hex(): {},
}
tokens := []common.Address{
common.HexToAddress("0x33531bDBFE34fa6Fd5963D0423f7699775AacaaF"),
}
processor := izumi.NewTransferIndexer(common.HexToAddress("0x33531bDBFE34fa6Fd5963D0423f7699775AacaaF"), whitelist)
processor := izumi.NewTransferIndexer(tokens, whitelist)
return processLPLogIndexer(client, processor, blockNumber)
}
3 changes: 1 addition & 2 deletions cmd/process_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/taikoxyz/trailblazer-adapters/adapters"
)
Expand Down Expand Up @@ -45,7 +44,7 @@ func processLPLogIndexer(client *ethclient.Client, processor adapters.LPLogsInde
return err
}
query := ethereum.FilterQuery{
Addresses: []common.Address{processor.Address()},
Addresses: processor.Address(),
FromBlock: big.NewInt(blockNumber),
ToBlock: big.NewInt(blockNumber),
}
Expand Down

0 comments on commit 47d22c0

Please sign in to comment.