Skip to content

Added "transfer()" commands to token cost analysis #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/internal/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"math"
"strconv"
"strings"

libcommon "github.com/String-xyz/go-lib/v2/common"
"github.com/ethereum/go-ethereum/accounts"
Expand Down Expand Up @@ -70,3 +71,14 @@ func SliceContains(elems []string, v string) bool {
}
return false
}

func StringContainsAny(target string, substrs []string) bool {
// convert target to lowercase
noSpaceLowerCase := strings.ReplaceAll(strings.ToLower(target), " ", "")
for _, substr := range substrs {
if strings.Contains(noSpaceLowerCase, strings.ReplaceAll(strings.ToLower(substr), " ", "")) {
return true
}
}
return false
}
2 changes: 1 addition & 1 deletion pkg/service/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (t transaction) testTransaction(executor Executor, request model.Transactio
tokenAddresses := []string{}
tokenAmounts := []big.Int{}
for _, action := range request.Actions {
if strings.ToLower(strings.ReplaceAll(action.CxFunc, " ", "")) == "approve(address,uint256)" {
if common.StringContainsAny(action.CxFunc, []string{"approve", "transfer"}) {
tokenAddresses = append(tokenAddresses, action.CxAddr)
// It should be safe at this point to w3.I without panic
tokenAmounts = append(tokenAmounts, *w3.I(action.CxParams[1]))
Expand Down