diff --git a/v2/cmd/backfill/main.go b/v2/cmd/backfill/main.go index b711034..8eb71b0 100644 --- a/v2/cmd/backfill/main.go +++ b/v2/cmd/backfill/main.go @@ -27,7 +27,7 @@ import ( promotion1inchv2 "github.com/KyberNetwork/tradelogs/v2/pkg/promotionparser/oneinchv2" "github.com/KyberNetwork/tradelogs/v2/pkg/rpcnode" "github.com/KyberNetwork/tradelogs/v2/pkg/storage/backfill" - promoteeTypes "github.com/KyberNetwork/tradelogs/v2/pkg/storage/promotees" + promotee_storage "github.com/KyberNetwork/tradelogs/v2/pkg/storage/promotees" "github.com/KyberNetwork/tradelogs/v2/pkg/storage/state" "github.com/KyberNetwork/tradelogs/v2/pkg/storage/tradelogs" bebopStorage "github.com/KyberNetwork/tradelogs/v2/pkg/storage/tradelogs/bebop" @@ -99,7 +99,7 @@ func run(c *cli.Context) error { manager := tradelogs.NewManager(l, storages) //promotee storage - promoteeStorage := promoteeTypes.New(l, db) + promoteeStorage := promotee_storage.New(l, db) // backfill storage backfillStorage := backfill.New(l, db) @@ -132,7 +132,7 @@ func run(c *cli.Context) error { paraswap.MustNewParser(), kyberswaprfq.MustNewParser(), hashflowv3.MustNewParser(), - oneinchv6.MustNewParser(), + oneinchv6.MustNewParser(promoteeStorage), uniswapx.MustNewParser(), bebop.MustNewParser(), zxrfqv3.MustNewParserWithDeployer(l, zxv3DeployStorage, ethClients[0], common.HexToAddress(constant.Deployer0xV3)), diff --git a/v2/cmd/parse_log/main.go b/v2/cmd/parse_log/main.go index 29a4ebb..de5d553 100644 --- a/v2/cmd/parse_log/main.go +++ b/v2/cmd/parse_log/main.go @@ -27,7 +27,7 @@ import ( "github.com/KyberNetwork/tradelogs/v2/pkg/promotionparser" promotion1inchv2 "github.com/KyberNetwork/tradelogs/v2/pkg/promotionparser/oneinchv2" "github.com/KyberNetwork/tradelogs/v2/pkg/rpcnode" - promoteeTypes "github.com/KyberNetwork/tradelogs/v2/pkg/storage/promotees" + promotee_storage "github.com/KyberNetwork/tradelogs/v2/pkg/storage/promotees" "github.com/KyberNetwork/tradelogs/v2/pkg/storage/state" "github.com/KyberNetwork/tradelogs/v2/pkg/storage/tradelogs" bebopStorage "github.com/KyberNetwork/tradelogs/v2/pkg/storage/tradelogs/bebop" @@ -98,7 +98,7 @@ func run(c *cli.Context) error { }) //promotee storage - promoteeStorage := promoteeTypes.New(l, db) + promoteeStorage := promotee_storage.New(l, db) // state storage s := state.New(l, db) @@ -128,7 +128,7 @@ func run(c *cli.Context) error { paraswap.MustNewParser(), kyberswaprfq.MustNewParser(), hashflowv3.MustNewParser(), - oneinchv6.MustNewParser(), + oneinchv6.MustNewParser(promoteeStorage), uniswapx.MustNewParser(), bebop.MustNewParser(), zxrfqv3.MustNewParserWithDeployer(l, zxv3DeployStorage, ethClients[0], common.HexToAddress(constant.Deployer0xV3)), diff --git a/v2/cmd/price_filler/main.go b/v2/cmd/price_filler/main.go index e1f41f5..fd9edce 100644 --- a/v2/cmd/price_filler/main.go +++ b/v2/cmd/price_filler/main.go @@ -27,8 +27,6 @@ import ( "go.uber.org/zap" ) -// This week I will deploy the new price filler of tradelog v2, which calls my new mark to market. -// After deploying, I will have data to continue creating competition dashboard. func main() { app := libapp.NewApp() app.Name = "trade logs crawler service" @@ -80,7 +78,12 @@ func run(c *cli.Context) error { l.Errorw("Error while init price filler") return err } - priceFiller.Run() + fillPriceInterval := c.Duration(libapp.FillPriceTimeIntervalFlag.Name) + if fillPriceInterval <= 0 { + l.Errorw("invalid value of fill-price-time-interval-flag") + return fmt.Errorf("invalid value of fill-price-time-interval-flag") + } + priceFiller.Run(fillPriceInterval) return nil } diff --git a/v2/pkg/app/price_filler.go b/v2/pkg/app/price_filler.go index a5caadf..637aa49 100644 --- a/v2/pkg/app/price_filler.go +++ b/v2/pkg/app/price_filler.go @@ -1,6 +1,8 @@ package app import ( + "time" + "github.com/urfave/cli" ) @@ -13,15 +15,23 @@ var BinanceSecretKeyFlag = cli.StringFlag{ Name: "binance-secret-key", EnvVar: "BINANCE_SECRET_KEY", } + var MarkToMarketURLFlag = cli.StringFlag{ Name: "mark-to-market-url", EnvVar: "MARK_TO_MARKET_URL", } +var FillPriceTimeIntervalFlag = cli.DurationFlag{ + Name: "fill-price-time-interval", + EnvVar: "FILL_PRICE_TIME_INTERVAL", + Value: time.Minute, +} + func PriceFillerFlags() []cli.Flag { return []cli.Flag{ BinanceAPIKeyFlag, BinanceSecretKeyFlag, MarkToMarketURLFlag, + FillPriceTimeIntervalFlag, } } diff --git a/v2/pkg/handler/trade_logs.go b/v2/pkg/handler/trade_logs.go index df6ee0d..0f4735b 100644 --- a/v2/pkg/handler/trade_logs.go +++ b/v2/pkg/handler/trade_logs.go @@ -73,12 +73,12 @@ func (h *TradeLogHandler) ProcessBlockWithExclusion(blockHash string, blockNumbe return fmt.Errorf("delete blocks error: %w", err) } - err = h.processForTradelog(calls, blockHash, blockNumber, timestamp, exclusions) + err = h.processForPromotion(calls, blockHash, blockNumber, timestamp) if err != nil { return fmt.Errorf("error when process block: %d", blockNumber) } - err = h.processForPromotion(calls, blockHash, blockNumber, timestamp) + err = h.processForTradelog(calls, blockHash, blockNumber, timestamp, exclusions) if err != nil { return fmt.Errorf("error when process block: %d", blockNumber) } diff --git a/v2/pkg/mtm/client.go b/v2/pkg/mtm/client.go index d31c64e..4dbc090 100644 --- a/v2/pkg/mtm/client.go +++ b/v2/pkg/mtm/client.go @@ -2,14 +2,17 @@ package mtm import ( "context" + "encoding/json" + "errors" "fmt" "net/http" + "strconv" "strings" "time" - - "github.com/KyberNetwork/tradinglib/pkg/httpclient" ) +var ErrRateLimit = errors.New("rate limit exceeded") + type MtmClient struct { baseURL string httpClient *http.Client @@ -35,28 +38,24 @@ type TokenResponse struct { func (m *MtmClient) GetListTokens(ctx context.Context) ([]Token, error) { const path = "/tokens" - - httpReq, err := httpclient.NewRequestWithContext( - ctx, - http.MethodGet, - m.baseURL, - path, - nil, - nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, m.baseURL+path, nil) if err != nil { return nil, fmt.Errorf("new request error: %w", err) } + req.Header.Set("Accept", "application/json") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("do request error: %w", err) + } - var resp TokenResponse - if _, err := httpclient.DoHTTPRequest( - m.httpClient, - httpReq, - &resp, - httpclient.WithStatusCode(http.StatusOK)); err != nil { - return nil, fmt.Errorf("do http request error: %w", err) + var tokens TokenResponse + + if err := json.NewDecoder(resp.Body).Decode(&tokens); err != nil { + return nil, fmt.Errorf("decode error: %w", err) } - return resp.Data, nil + return tokens.Data, nil } type RateV3Response struct { @@ -71,28 +70,29 @@ func (m *MtmClient) GetHistoricalRate( ctx context.Context, base, quote string, chainId int64, ts time.Time, ) (float64, error) { const path = "/v3/historical" - httpReq, err := httpclient.NewRequestWithContext( - ctx, - http.MethodGet, - m.baseURL, - path, - httpclient.NewQuery(). - SetString("base", base). - SetString("quote", quote). - Int64("chain_id", chainId). - Int64("time", ts.Unix()), - nil) + params := "?base=" + base + + ""e=" + quote + + "&chain_id=" + strconv.FormatInt(chainId, 10) + + "&time=" + strconv.FormatInt(ts.Unix(), 10) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, m.baseURL+path+params, nil) if err != nil { return 0, fmt.Errorf("new request error: %w", err) } + req.Header.Set("Accept", "application/json") + client := &http.Client{} + resp, err := client.Do(req) + if resp.StatusCode == http.StatusTooManyRequests { // 429 + return 0, ErrRateLimit + } + if err != nil { + return 0, fmt.Errorf("do request error: %w", err) + } + defer resp.Body.Close() var rate RateV3Response - if _, err := httpclient.DoHTTPRequest( - m.httpClient, - httpReq, - &rate, - httpclient.WithStatusCode(http.StatusOK)); err != nil { - return 0, fmt.Errorf("do http request error: %w", err) + + if err := json.NewDecoder(resp.Body).Decode(&rate); err != nil { + return 0, fmt.Errorf("decode error: %w", err) } return rate.Data.Price, nil diff --git a/v2/pkg/mtm/client_test.go b/v2/pkg/mtm/client_test.go index 19e1d84..222eeee 100644 --- a/v2/pkg/mtm/client_test.go +++ b/v2/pkg/mtm/client_test.go @@ -2,7 +2,6 @@ package mtm import ( "context" - "fmt" "net/http" "testing" "time" @@ -16,10 +15,11 @@ func TestNewMtmClient(t *testing.T) { MTM_URL := "" httpClient := &http.Client{} client := NewMtmClient(MTM_URL, httpClient) - rate, err := client.GetHistoricalRate(context.Background(), "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0xdac17f958d2ee523a2206206994597c13d831ec7", 1, time.UnixMilli(1732870268000)) + rate, err := client.GetHistoricalRate(context.Background(), "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0xdac17f958d2ee523a2206206994597c13d831ec7", 1, time.Now().Add(-time.Hour)) require.NoError(t, err) - fmt.Println("historical rate", rate) + t.Log("historical rate", rate) - _, err = client.GetListTokens(context.Background()) + tokens, err := client.GetListTokens(context.Background()) require.NoError(t, err) + t.Log("tokens", tokens) } diff --git a/v2/pkg/parser/oneinchv6/oneinchv6_test.go b/v2/pkg/parser/oneinchv6/oneinchv6_test.go index 0bd0f3c..cac26cc 100644 --- a/v2/pkg/parser/oneinchv6/oneinchv6_test.go +++ b/v2/pkg/parser/oneinchv6/oneinchv6_test.go @@ -10,19 +10,45 @@ import ( "testing" "time" + "github.com/KyberNetwork/tradelogs/internal/testutil" + promoteesStorage "github.com/KyberNetwork/tradelogs/v2/pkg/storage/promotees" types2 "github.com/KyberNetwork/tradelogs/v2/pkg/types" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "github.com/stretchr/testify/require" + "github.com/test-go/testify/assert" + "go.uber.org/zap" ) var rpcURL = os.Getenv("TEST_RPC_URL") func TestFetchEvent(t *testing.T) { t.Skip("Need to add the rpc url that enables the trace call JSON-RPC") - p := MustNewParser() + db, tearDown := testutil.MustNewDevelopmentDB("../../../cmd/migrations") + l := zap.S() + defer func() { + assert.NoError(t, tearDown()) + }() + + // promotee storage + promoteeS := promoteesStorage.New(l, db) + var promotees []promoteesStorage.Promotee + promotees = append(promotees, promoteesStorage.Promotee{ + Promoter: "0xf63392356a985ead50b767a3e97a253ff870e91a", + Promotee: "0xad3b67bca8935cb510c8d18bd45f0b94f54a968f", + Timestamp: 1690946915, + TxHash: "0x3d60f68df749eb9a34b427955459d3f441c5051c6a2c202be64f696fbde1eec6", + ChainId: "1", + BlockNumber: 17800000, + }) + assert.NoError(t, promoteeS.Insert(promotees), "failed to insert promotees") + for _, promotee := range promotees { + t.Log(promotee) + } + + p := MustNewParser(promoteeS) require.Equal(t, p.abi.Events[FilledEvent].ID, common.HexToHash("0xfec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e07")) client, err := ethclient.Dial(rpcURL) require.NoError(t, err) @@ -44,18 +70,39 @@ func TestFetchEvent(t *testing.T) { } func TestParseEvent(t *testing.T) { - t.Skip("Need to add the rpc url that enables the trace call JSON-RPC") eventRaw := `[{"address":"0x111111125421ca6dc452d289314280a0f8842a65","topics":["0xfec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e07"],"data":"0xb81725973077ecc6db7dd73510be46152917f31ab7d02210aace851edc0f3fbb000000000000000000000000000000000000000000000000a5953ec9be11bd73","blockNumber":"0x13ec371","transactionHash":"0x09b63a10295261192885b38af317ba138ad7fe5828ce25524e7f0f053e250458","transactionIndex":"0x7","blockHash":"0x291e59d96ccc8b661842cfd9c4dcce1d11ed30cd4cf2b8034bff2a8d7a595785","logIndex":"0x3e","removed":false}]` var events []types.Log err := json.Unmarshal([]byte(eventRaw), &events) require.NoError(t, err) - callFrameRaw := `{ "from": "0x5b93d80da1a359340d1f339fb574bdc56763f995", "gas": "0x7805c", "gasUsed": "0xaa29", "to": "0x111111125421ca6dc452d289314280a0f8842a65", "input": "0xf497df75e26b9977fabcf23097e49776cb360dda5656330c99a7c8f531e674118829d376000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000125195019f8400000000000000000000000000000000000000000000000000000000001299cd101824a000000000000000000000000000000000066ff91df00000000000000000000148038b763276eddd7894c7e298ed1d3d5f7a11f36404027b5a00f41928a899a80cf63d4895cd14df1cd15a6533e5dbb1675976f0c32004829ebcafdd3e9825800000000000000000000000000000000000000000000000002df3926958c42eba8000257000015000000000000000000000000000000000000000002f06464b800000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000028073a38006d23517a1d383c88929b2014f8835b38b000002370000018e0000018e0000009a0000009a0000004d0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc0030fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc003018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000111111125421ca6dc452d289314280a0f8842a65ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006700e0b9000000000000000000000000000000000000000000000000000000000000001c64498e3e35a5a54425bf9c1054eecb870749d1af47e06a8375f0273906f369e300997b5116afb64e6528c971d0b42fbcb839658ce392a85cdf681868ed0ff9abfb2809a5314473e1165f6b58018e20ed8f07b84066ff8f63b09498030ae3416b66dc0000b8394f2220fac7e6ade60000339fb574bdc56763f9950000d18bd45f0b94f54a968f0000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab322337800006de5e0e428ac771d77b5000006455390207c1d485be90000db05a6a504f04d92e79d00000cf7a62884e542b3bddd0000f7f4f96b98e102b56b040000605b93d80da1a359340d1f339fb574bdc56763f99503", "output": "0x00000000000000000000000000000000000000000000000002df3926958c42eb00000000000000000000000000000000000000000000000000000002f06464b8b81725973077ecc6db7dd73510be46152917f31ab7d02210aace851edc0f3fbb", "calls": [ { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x73e61", "gasUsed": "0xabd", "to": "0xfb2809a5314473e1165f6b58018e20ed8f07b840", "input": "0xd7ff8a80e26b9977fabcf23097e49776cb360dda5656330c99a7c8f531e674118829d376000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000125195019f8400000000000000000000000000000000000000000000000000000000001299cd101824a000000000000000000000000000000000066ff91df0000000000000000000000000000000000000000000000000000000000000000000000000000000001c0b81725973077ecc6db7dd73510be46152917f31ab7d02210aace851edc0f3fbb0000000000000000000000005b93d80da1a359340d1f339fb574bdc56763f99500000000000000000000000000000000000000000000000002df3926958c42eb000000000000000000000000000000000000000000000000a87477f0539e005e00000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000257000002370000018e0000018e0000009a0000009a0000004d0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc0030fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc003018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000111111125421ca6dc452d289314280a0f8842a65ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006700e0b9000000000000000000000000000000000000000000000000000000000000001c64498e3e35a5a54425bf9c1054eecb870749d1af47e06a8375f0273906f369e300997b5116afb64e6528c971d0b42fbcb839658ce392a85cdf681868ed0ff9abfb2809a5314473e1165f6b58018e20ed8f07b84066ff8f63b09498030ae3416b66dc0000b8394f2220fac7e6ade60000339fb574bdc56763f9950000d18bd45f0b94f54a968f0000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab322337800006de5e0e428ac771d77b5000006455390207c1d485be90000db05a6a504f04d92e79d00000cf7a62884e542b3bddd0000f7f4f96b98e102b56b0400006000000000000000000000000000000000000000000000000000000000000000000000000000000000390000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc003000000000000000", "output": "0x00000000000000000000000000000000000000000000000000000002f06464b8", "type": "STATICCALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x722d3", "gasUsed": "0x2870", "to": "0x18084fba666a33d37592fa2633fd49a74dd93a88", "input": "0x23b872dd000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f800000000000000000000000073a38006d23517a1d383c88929b2014f8835b38b00000000000000000000000000000000000000000000000002df3926958c42eb", "output": "0x0000000000000000000000000000000000000000000000000000000000000001", "logs": [ { "address": "0x18084fba666a33d37592fa2633fd49a74dd93a88", "topics": [ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8", "0x00000000000000000000000073a38006d23517a1d383c88929b2014f8835b38b" ], "data": "0x00000000000000000000000000000000000000000000000002df3926958c42eb", "position": "0x0" } ], "value": "0x0", "type": "CALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x6f4d6", "gasUsed": "0x1d3", "to": "0x5b93d80da1a359340d1f339fb574bdc56763f995", "input": "0xadf38ba1e26b9977fabcf23097e49776cb360dda5656330c99a7c8f531e674118829d376000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000125195019f8400000000000000000000000000000000000000000000000000000000001299cd101824a000000000000000000000000000000000066ff91df0000000000000000000000000000000000000000000000000000000000000000000000000000000001e0b81725973077ecc6db7dd73510be46152917f31ab7d02210aace851edc0f3fbb0000000000000000000000005b93d80da1a359340d1f339fb574bdc56763f99500000000000000000000000000000000000000000000000002df3926958c42eb00000000000000000000000000000000000000000000000000000002f06464b8000000000000000000000000000000000000000000000000a87477f0539e005e00000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000000000257000002370000018e0000018e0000009a0000009a0000004d0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc0030fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc003018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000111111125421ca6dc452d289314280a0f8842a65ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006700e0b9000000000000000000000000000000000000000000000000000000000000001c64498e3e35a5a54425bf9c1054eecb870749d1af47e06a8375f0273906f369e300997b5116afb64e6528c971d0b42fbcb839658ce392a85cdf681868ed0ff9abfb2809a5314473e1165f6b58018e20ed8f07b84066ff8f63b09498030ae3416b66dc0000b8394f2220fac7e6ade60000339fb574bdc56763f9950000d18bd45f0b94f54a968f0000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab322337800006de5e0e428ac771d77b5000006455390207c1d485be90000db05a6a504f04d92e79d00000cf7a62884e542b3bddd0000f7f4f96b98e102b56b0400006000000000000000000000000000000000000000000000000000000000000000000000000000000000010300000000000000000000000000000000000000000000000000000000000000", "value": "0x0", "type": "CALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x6ef4b", "gasUsed": "0x1e32", "to": "0xdac17f958d2ee523a2206206994597c13d831ec7", "input": "0x23b872dd0000000000000000000000005b93d80da1a359340d1f339fb574bdc56763f995000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f800000000000000000000000000000000000000000000000000000002f06464b8", "logs": [ { "address": "0xdac17f958d2ee523a2206206994597c13d831ec7", "topics": [ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x0000000000000000000000005b93d80da1a359340d1f339fb574bdc56763f995", "0x000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8" ], "data": "0x00000000000000000000000000000000000000000000000000000002f06464b8", "position": "0x0" } ], "value": "0x0", "type": "CALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x6c9f6", "gasUsed": "0x7ff", "to": "0xfb2809a5314473e1165f6b58018e20ed8f07b840", "input": "0x462ebde2e26b9977fabcf23097e49776cb360dda5656330c99a7c8f531e674118829d376000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000125195019f8400000000000000000000000000000000000000000000000000000000001299cd101824a000000000000000000000000000000000066ff91df0000000000000000000000000000000000000000000000000000000000000000000000000000000001e0b81725973077ecc6db7dd73510be46152917f31ab7d02210aace851edc0f3fbb0000000000000000000000005b93d80da1a359340d1f339fb574bdc56763f99500000000000000000000000000000000000000000000000002df3926958c42eb00000000000000000000000000000000000000000000000000000002f06464b8000000000000000000000000000000000000000000000000a87477f0539e005e00000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000000000257000002370000018e0000018e0000009a0000009a0000004d0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc0030fb2809a5314473e1165f6b58018e20ed8f07b8400000bc0000124b66ff8f7b00025801537c01456d0054013adf00540136850054011bb5005400c554005400c3db001800c2cb006c0000bc003018084fba666a33d37592fa2633fd49a74dd93a88000000000000000000000000a231659f41c77ef38b7da914276ffa37422783f8000000000000000000000000111111125421ca6dc452d289314280a0f8842a65ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006700e0b9000000000000000000000000000000000000000000000000000000000000001c64498e3e35a5a54425bf9c1054eecb870749d1af47e06a8375f0273906f369e300997b5116afb64e6528c971d0b42fbcb839658ce392a85cdf681868ed0ff9abfb2809a5314473e1165f6b58018e20ed8f07b84066ff8f63b09498030ae3416b66dc0000b8394f2220fac7e6ade60000339fb574bdc56763f9950000d18bd45f0b94f54a968f0000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab322337800006de5e0e428ac771d77b5000006455390207c1d485be90000db05a6a504f04d92e79d00000cf7a62884e542b3bddd0000f7f4f96b98e102b56b04000060000000000000000000000000000000000000000000000000000000000000000000000000000000009566ff8f63b09498030ae3416b66dc0000b8394f2220fac7e6ade60000339fb574bdc56763f9950000d18bd45f0b94f54a968f0000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab322337800006de5e0e428ac771d77b5000006455390207c1d485be90000db05a6a504f04d92e79d00000cf7a62884e542b3bddd0000f7f4f96b98e102b56b040000600000000000000000000000", "value": "0x0", "type": "CALL" } ], "logs": [ { "address": "0x111111125421ca6dc452d289314280a0f8842a65", "topics": [ "0xfec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e07" ], "data": "0xb81725973077ecc6db7dd73510be46152917f31ab7d02210aace851edc0f3fbb000000000000000000000000000000000000000000000000a5953ec9be11bd73", "position": "0x5" } ], "value": "0x0", "type": "CALL" }` + callFrameRaw := `{ "from": "0xad3b67bca8935cb510c8d18bd45f0b94f54a968f", "gas": "0x23ebe", "gasUsed": "0x195eb", "to": "0x111111125421ca6dc452d289314280a0f8842a65", "input": "0xf497df75e26b997789188a3dd5468b4ad85639625ac2b1223073991f906fb14e40079c620000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe3530000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000111111111117dc0aa78b770fa6a738034120c30200000000000000000000000000000000000000000000000001252b544ee06c0000000000000000000000000000000000000000000000001ebefa5d232e991c858a00000000000000000000001254000000006759c58a00000000000000000000da15554be651d54e0854e7cb9b77d02cecc80920014b0c03704046a50b423b13dbe4c1861d79eb80df92e52e506e0a21e946fc5a0e49cd73477a242fed392ed800000000000000000000000000000000000000000000000001252b544ee06c008000011b0000000000000000000000000000009bc8430b2577b5a268bb3c5c0200000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000011b000000fb0000005e0000005e0000005e0000005e0000002f0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400b706700005d6c6759c4ca0000b4166675151c9d003c0b70670078fb2809a5314473e1165f6b58018e20ed8f07b8400b706700005d6c6759c4ca0000b4166675151c9d003c0b70670078fb2809a5314473e1165f6b58018e20ed8f07b8406759c4a6d18bd45f0b94f54a968f0000b09498030ae3416b66dc0024b8394f2220fac7e6ade60000339fb574bdc56763f9950000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab32233780000bb2ef6bb1a30be7ee6be000095770895ad27ad6b0d9500006a637b6b08ebe78b9da500006de5e0e428ac771d77b50000580000000000", "output": "0x00000000000000000000000000000000000000000000000001252b544ee06c000000000000000000000000000000000000000000000000209f87f61f655242943619ad9770ded3691012de684ae4329b72b0e3292c7f19ba38dd73e9b1389e69", "calls": [ { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x22a2e", "gasUsed": "0xbb8", "to": "0x0000000000000000000000000000000000000001", "input": "0x3619ad9770ded3691012de684ae4329b72b0e3292c7f19ba38dd73e9b1389e69000000000000000000000000000000000000000000000000000000000000001cda15554be651d54e0854e7cb9b77d02cecc80920014b0c03704046a50b423b135be4c1861d79eb80df92e52e506e0a21e946fc5a0e49cd73477a242fed392ed8", "output": "0x0000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe353", "type": "STATICCALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x1febc", "gasUsed": "0x772", "to": "0xfb2809a5314473e1165f6b58018e20ed8f07b840", "input": "0xd7ff8a80e26b997789188a3dd5468b4ad85639625ac2b1223073991f906fb14e40079c620000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe3530000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000111111111117dc0aa78b770fa6a738034120c30200000000000000000000000000000000000000000000000001252b544ee06c0000000000000000000000000000000000000000000000001ebefa5d232e991c858a00000000000000000000001254000000006759c58a0000000000000000000000000000000000000000000000000000000000000000000000000000000001c03619ad9770ded3691012de684ae4329b72b0e3292c7f19ba38dd73e9b1389e69000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f00000000000000000000000000000000000000000000000001252b544ee06c0000000000000000000000000000000000000000000000000001252b544ee06c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000011b000000fb0000005e0000005e0000005e0000005e0000002f0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400b706700005d6c6759c4ca0000b4166675151c9d003c0b70670078fb2809a5314473e1165f6b58018e20ed8f07b8400b706700005d6c6759c4ca0000b4166675151c9d003c0b70670078fb2809a5314473e1165f6b58018e20ed8f07b8406759c4a6d18bd45f0b94f54a968f0000b09498030ae3416b66dc0024b8394f2220fac7e6ade60000339fb574bdc56763f9950000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab32233780000bb2ef6bb1a30be7ee6be000095770895ad27ad6b0d9500006a637b6b08ebe78b9da500006de5e0e428ac771d77b50000580000000000000000000000000000000000000000000000000000000000000000000000001b0b706700005d6c6759c4ca0000b4166675151c9d003c0b706700780000000000", "output": "0x0000000000000000000000000000000000000000000000209f87f61f65524294", "type": "STATICCALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x191f0", "gasUsed": "0x3ab1", "to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "input": "0x23b872dd0000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe353000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f00000000000000000000000000000000000000000000000001252b544ee06c00", "output": "0x0000000000000000000000000000000000000000000000000000000000000001", "logs": [ { "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "topics": [ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x0000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe353", "0x000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f" ], "data": "0x00000000000000000000000000000000000000000000000001252b544ee06c00", "position": "0x0" } ], "value": "0x0", "type": "CALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0x14b03", "gasUsed": "0x921c", "to": "0x111111111117dc0aa78b770fa6a738034120c302", "input": "0x23b872dd000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f0000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe3530000000000000000000000000000000000000000000000209f87f61f65524294", "output": "0x0000000000000000000000000000000000000000000000000000000000000001", "logs": [ { "address": "0x111111111117dc0aa78b770fa6a738034120c302", "topics": [ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f", "0x0000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe353" ], "data": "0x0000000000000000000000000000000000000000000000209f87f61f65524294", "position": "0x0" }, { "address": "0x111111111117dc0aa78b770fa6a738034120c302", "topics": [ "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", "0x000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f", "0x000000000000000000000000111111125421ca6dc452d289314280a0f8842a65" ], "data": "0xfffffffffffffffffffffffffffffffffffffffffffe505d9df8a1a2bf71e3d5", "position": "0x0" } ], "value": "0x0", "type": "CALL" }, { "from": "0x111111125421ca6dc452d289314280a0f8842a65", "gas": "0xb3ac", "gasUsed": "0x659", "to": "0xfb2809a5314473e1165f6b58018e20ed8f07b840", "input": "0x462ebde2e26b997789188a3dd5468b4ad85639625ac2b1223073991f906fb14e40079c620000000000000000000000007f6c33ec51b71c91e8d4a7b188fa6435afafe3530000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000111111111117dc0aa78b770fa6a738034120c30200000000000000000000000000000000000000000000000001252b544ee06c0000000000000000000000000000000000000000000000001ebefa5d232e991c858a00000000000000000000001254000000006759c58a0000000000000000000000000000000000000000000000000000000000000000000000000000000001e03619ad9770ded3691012de684ae4329b72b0e3292c7f19ba38dd73e9b1389e69000000000000000000000000ad3b67bca8935cb510c8d18bd45f0b94f54a968f00000000000000000000000000000000000000000000000001252b544ee06c000000000000000000000000000000000000000000000000209f87f61f6552429400000000000000000000000000000000000000000000000001252b544ee06c000000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000011b000000fb0000005e0000005e0000005e0000005e0000002f0000000000000000fb2809a5314473e1165f6b58018e20ed8f07b8400b706700005d6c6759c4ca0000b4166675151c9d003c0b70670078fb2809a5314473e1165f6b58018e20ed8f07b8400b706700005d6c6759c4ca0000b4166675151c9d003c0b70670078fb2809a5314473e1165f6b58018e20ed8f07b8406759c4a6d18bd45f0b94f54a968f0000b09498030ae3416b66dc0024b8394f2220fac7e6ade60000339fb574bdc56763f9950000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab32233780000bb2ef6bb1a30be7ee6be000095770895ad27ad6b0d9500006a637b6b08ebe78b9da500006de5e0e428ac771d77b5000058000000000000000000000000000000000000000000000000000000000000000000000000896759c4a6d18bd45f0b94f54a968f0000b09498030ae3416b66dc0024b8394f2220fac7e6ade60000339fb574bdc56763f9950000d61b892b2ad6249011850000ade19567bb538035ed360000617556ed277ab32233780000bb2ef6bb1a30be7ee6be000095770895ad27ad6b0d9500006a637b6b08ebe78b9da500006de5e0e428ac771d77b50000580000000000000000000000000000000000000000000000", "value": "0x0", "type": "CALL" } ], "logs": [ { "address": "0x111111125421ca6dc452d289314280a0f8842a65", "topics": [ "0xfec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e07" ], "data": "0x3619ad9770ded3691012de684ae4329b72b0e3292c7f19ba38dd73e9b1389e690000000000000000000000000000000000000000000000000000000000000000", "position": "0x5" } ], "value": "0x0", "type": "CALL" }` var callFrame types2.CallFrame err = json.Unmarshal([]byte(callFrameRaw), &callFrame) require.NoError(t, err) - p := MustNewParser() + db, tearDown := testutil.MustNewDevelopmentDB("../../../cmd/migrations") + l := zap.S() + defer func() { + assert.NoError(t, tearDown()) + }() + + // promotee storage + promoteeS := promoteesStorage.New(l, db) + var promotees []promoteesStorage.Promotee + promotees = append(promotees, promoteesStorage.Promotee{ + Promoter: "0xf63392356a985ead50b767a3e97a253ff870e91a", + Promotee: "0xad3b67bca8935cb510c8d18bd45f0b94f54a968f", + Timestamp: 1690946915, + TxHash: "0x3d60f68df749eb9a34b427955459d3f441c5051c6a2c202be64f696fbde1eec6", + ChainId: "1", + BlockNumber: 17800000, + }) + assert.NoError(t, promoteeS.Insert(promotees), "failed to insert promotees") + for _, promotee := range promotees { + t.Log(promotee) + } + + p := MustNewParser(promoteeS) for _, event := range events { logs, err := p.ParseWithCallFrame(callFrame, event, uint64(time.Now().Unix())) require.NoError(t, err) @@ -67,6 +114,7 @@ func TestParseEvent(t *testing.T) { t.Log(log.Taker) t.Log(log.TakerToken) t.Log(log.TakerTokenAmount) + t.Log(log.Type) } } diff --git a/v2/pkg/parser/oneinchv6/parser.go b/v2/pkg/parser/oneinchv6/parser.go index bfddfdd..47e6dcb 100644 --- a/v2/pkg/parser/oneinchv6/parser.go +++ b/v2/pkg/parser/oneinchv6/parser.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/tradelogs/v2/pkg/constant" "github.com/KyberNetwork/tradelogs/v2/pkg/decoder" "github.com/KyberNetwork/tradelogs/v2/pkg/parser" + promotee_storage "github.com/KyberNetwork/tradelogs/v2/pkg/storage/promotees" storageTypes "github.com/KyberNetwork/tradelogs/v2/pkg/storage/tradelogs/types" "github.com/KyberNetwork/tradelogs/v2/pkg/types" "github.com/ethereum/go-ethereum/accounts/abi" @@ -36,12 +37,13 @@ func init() { } type Parser struct { - abi *abi.ABI - ps *Oneinchv6Filterer - eventHash string + abi *abi.ABI + ps *Oneinchv6Filterer + eventHash string + promoteeStorage *promotee_storage.Storage } -func MustNewParser() *Parser { +func MustNewParser(promoteeStorage *promotee_storage.Storage) *Parser { ps, err := NewOneinchv6Filterer(common.Address{}, nil) if err != nil { panic(err) @@ -56,9 +58,10 @@ func MustNewParser() *Parser { } return &Parser{ - ps: ps, - abi: ab, - eventHash: event.ID.String(), + ps: ps, + abi: ab, + eventHash: event.ID.String(), + promoteeStorage: promoteeStorage, } } @@ -116,8 +119,19 @@ func (p *Parser) ParseFromInternalCall(order storageTypes.TradeLog, internalCall if err != nil { return order, fmt.Errorf("error when parse contract call to order %w", err) } - order.Taker = internalCall.From + + if order.Type == storageTypes.RFQType { + return order, nil + } + + fusion, err := p.promoteeStorage.CheckPromoteeExist(strings.ToLower(order.Taker)) + if err != nil { + return order, nil + } + if fusion { + order.Type = storageTypes.FusionType + } return order, nil } diff --git a/v2/pkg/price_filler/price_filler.go b/v2/pkg/price_filler/price_filler.go index f7ce8bf..ace07b9 100644 --- a/v2/pkg/price_filler/price_filler.go +++ b/v2/pkg/price_filler/price_filler.go @@ -18,17 +18,16 @@ import ( ) const ( - NetworkETHChainID = 1 - NetworkETHChainIDString = "1" - NetworkETH = "ETH" - updateAllCoinInfoInterval = 12 * time.Hour - backfillTradeLogsPriceInterval = 10 * time.Minute - backfillTradeLogsLimit = 60 - addressETH1 = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - addressETH2 = "0x0000000000000000000000000000000000000000" - coinUSDT = "USDT" - USDTAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7" - invalidSymbolErrString = " code=-1121, msg=Invalid symbol." + NetworkETHChainID = 1 + NetworkETHChainIDString = "1" + NetworkETH = "ETH" + updateAllCoinInfoInterval = 12 * time.Hour + backfillTradeLogsLimit = 60 + addressETH1 = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + addressETH2 = "0x0000000000000000000000000000000000000000" + coinUSDT = "USDT" + USDTAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7" + invalidSymbolErrString = " code=-1121, msg=Invalid symbol." ) var ( @@ -86,9 +85,9 @@ func NewPriceFiller(l *zap.SugaredLogger, return p, nil } -func (p *PriceFiller) Run() { +func (p *PriceFiller) Run(fillPriceInterval time.Duration) { go p.runUpdateAllCoinInfoRoutine() - p.runBackFillTradelogPriceRoutine() + p.runBackFillTradelogPriceRoutine(fillPriceInterval) } func (p *PriceFiller) getPrice(token string, timestamp int64) (float64, error) { @@ -141,8 +140,8 @@ func (p *PriceFiller) runUpdateAllCoinInfoRoutine() { } } -func (p *PriceFiller) runBackFillTradelogPriceRoutine() { - ticker := time.NewTicker(backfillTradeLogsPriceInterval) +func (p *PriceFiller) runBackFillTradelogPriceRoutine(fillPriceInterval time.Duration) { + ticker := time.NewTicker(fillPriceInterval) defer ticker.Stop() for ; ; <-ticker.C { @@ -200,19 +199,20 @@ func (p *PriceFiller) fullFillBebopTradeLog(tradeLog storageTypes.TradeLog) (sto takerAmounts := strings.Split(tradeLog.TakerTokenAmount, ",") makerPrice, makerSumUsdAmount, err := p.getSumAmountUsd(makerTokens, makerAmounts, int64(tradeLog.Timestamp)) - - if err != nil { + if isConnectionRefusedError(err) { + p.l.Errorw("Failed to getSumAndAmountUsd for maker", "err", err) return tradeLog, err } - tradeLog.MakerTokenPrice = &makerPrice // set zero price for multi-maker trade - tradeLog.MakerUsdAmount = &makerSumUsdAmount - takerPrice, takerUsdAmount, err := p.getSumAmountUsd(takerTokens, takerAmounts, int64(tradeLog.Timestamp)) - if err != nil { + if isConnectionRefusedError(err) { + p.l.Errorw("Failed to getSumAmountUsd for taker", "err", err) return tradeLog, err } + tradeLog.MakerTokenPrice = &makerPrice // set zero price for multi-maker trade + tradeLog.MakerUsdAmount = &makerSumUsdAmount + tradeLog.TakerTokenPrice = &takerPrice tradeLog.TakerUsdAmount = &takerUsdAmount @@ -333,6 +333,9 @@ func isConnectionRefusedError(err error) bool { if err == nil { return false } + if errors.Is(err, mtm.ErrRateLimit) { + return true + } var netErr *net.OpError if errors.As(err, &netErr) { if strings.Contains(netErr.Err.Error(), "connection refused") { diff --git a/v2/pkg/storage/promotees/storage.go b/v2/pkg/storage/promotees/storage.go index 8b6a982..8ea176d 100644 --- a/v2/pkg/storage/promotees/storage.go +++ b/v2/pkg/storage/promotees/storage.go @@ -59,9 +59,9 @@ func (s *Storage) Insert(promotees []Promotee) error { func (s *Storage) Get(query PromoteesQuery) ([]Promotee, error) { builder := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar). - Select(fmt.Sprintf("%s.promoter, promotee, chain_id, tx_hash, timestamp, name", promoteesTable)). + Select(fmt.Sprintf("%s.promoter, promotee, chain_id, tx_hash, timestamp, COALESCE(%s.name, '') AS name", promoteesTable, nameTable)). From(promoteesTable). - Join(fmt.Sprintf("%s ON %s.promoter = %s.promoter", nameTable, promoteesTable, nameTable)) + LeftJoin(fmt.Sprintf("%s ON %s.promoter = %s.promoter", nameTable, promoteesTable, nameTable)) v := reflect.ValueOf(query) types := v.Type() @@ -128,3 +128,25 @@ func (s *Storage) InsertPromoterName(promotees []Promotee) error { } return nil } + +func (s *Storage) CheckPromoteeExist(promotee string) (bool, error) { + builder := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar). + Select("COUNT(*)"). + From(promoteesTable). + Where(squirrel.Eq{"promotee": promotee}). + Where(squirrel.Eq{"chain_id": "1"}) + + q, p, err := builder.ToSql() + if err != nil { + return false, err + } + + var count int + if err := s.db.Get(&count, q, p...); err != nil { + return false, err + } + if count >= 1 { + return true, nil + } + return false, nil +} diff --git a/v2/pkg/storage/promotees/storage_test.go b/v2/pkg/storage/promotees/storage_test.go index bc550e3..1710e43 100644 --- a/v2/pkg/storage/promotees/storage_test.go +++ b/v2/pkg/storage/promotees/storage_test.go @@ -27,16 +27,13 @@ func TestInsert(t *testing.T) { t.Log(promotee) } - // byteValue2, err := os.Open("test2.json") + byteValue2, err := os.Open("test2.json") - // assert.NoError(t, err) - // assert.NoError(t, json.NewDecoder(byteValue2).Decode(&promotees), "failed to parse promotees") - // assert.NoError(t, s.Insert(promotees), "failed to insert promotees") - // t.Log(promotees) - var query PromoteesQuery - query.Promoter = "" - query.Promotee = "" - query.ChainId = "" + assert.NoError(t, err) + assert.NoError(t, json.NewDecoder(byteValue2).Decode(&promotees), "failed to parse promotees") + assert.NoError(t, s.Insert(promotees), "failed to insert promotees") + t.Log(promotees) + query := PromoteesQuery{} pwithname, err := s.Get(query) assert.NoError(t, err, "Failed to get promotees") @@ -64,4 +61,5 @@ func TestInsert(t *testing.T) { } } + t.Log(s.CheckPromoteeExist("0x0b8a49d816cc709b6eadb09498030ae3416b66dc")) } diff --git a/v2/pkg/storage/promotees/test.json b/v2/pkg/storage/promotees/test.json index a71dde7..1d8fc3f 100644 --- a/v2/pkg/storage/promotees/test.json +++ b/v2/pkg/storage/promotees/test.json @@ -3,7 +3,7 @@ "promoter": "0xd7f6f541d4210550ca56f7b4c4a549efd4cafb49", "promotee": "0x1e9d349cec77fea6481f009593101d0e20a69490", "timestamp": 498529484, - "event_hash": "0xf8cf20ddcd5eaf81ea4967c60402d1f3805804126fd4371bf9e39a7605ccad02", + "tx_hash": "0xf8cf20ddcd5eaf81ea4967c60402d1f3805804126fd4371bf9e39a7605ccad02", "chain_id": "1", "block_number": 1 }, @@ -11,7 +11,7 @@ "promoter": "0xe023f53f735c196e4a028233c2ee425957812a41", "promotee": "0xd1742b3c4fbb096990c8950fa635aec75b30781a", "timestamp": 498539324, - "event_hash": "0x4dc9aa484e1afe6f9e01280925504841c26a81e0db09c6406ca7b1869bdc6ea8", + "tx_hash": "0x4dc9aa484e1afe6f9e01280925504841c26a81e0db09c6406ca7b1869bdc6ea8", "chain_id": "2", "block_number": 2 }, @@ -19,7 +19,7 @@ "promoter": "0xa260f8b7c8f37c2f1bc11b04c19902829de6ac8a", "promotee": "0x0b8a49d816cc709b6eadb09498030ae3416b66dc", "timestamp": 498539524, - "event_hash": "0xeb0bd6036ef28377b2288e0d1fb38c064c14635085777c6e88c617f9b21ac85b", + "tx_hash": "0xeb0bd6036ef28377b2288e0d1fb38c064c14635085777c6e88c617f9b21ac85b", "chain_id": "1", "block_number": 3 }, @@ -27,7 +27,7 @@ "promoter": "0xe023f53f735c196e4a028233c2ee425957812a41", "promotee": "0x01372be9616ff00469d3e509b77d6960af757180", "timestamp": 4985437524, - "event_hash": "0x46ab12e2cb6e5e7c2a1e0a1da7735785b713124aeb93ba3093e64ed69451e624", + "tx_hash": "0x46ab12e2cb6e5e7c2a1e0a1da7735785b713124aeb93ba3093e64ed69451e624", "chain_id": "2", "block_number": 4 } diff --git a/v2/pkg/storage/promotees/test2.json b/v2/pkg/storage/promotees/test2.json index fe5a5cc..919ec8f 100644 --- a/v2/pkg/storage/promotees/test2.json +++ b/v2/pkg/storage/promotees/test2.json @@ -3,7 +3,7 @@ "promoter": "0xd7f6f541d4210550ca56f7b4c4a549efd4cafb49", "promotee": "0x1e9d349cec77fea6481f009593101d0e20a69490", "timestamp": 498529484, - "event_hash": "0xf8cf20ddcd5eaf81ea4967c60402d1f3805804126fd4371bf9e39a7605ccad02", + "tx_hash": "0xf8cf20ddcd5eaf81ea4967c60402d1f3805804126fd4371bf9e39a7605ccad02", "chain_id": "1", "block_number": 1 }, @@ -11,7 +11,7 @@ "promoter": "0xe023f53f735c196e4a028233c2ee425957812a41", "promotee": "0xd1742b3c4fbb096990c8950fa635aec75b30781a", "timestamp": 498539324, - "event_hash": "0x4dc9aa484e1afe6f9e01280925504841c26a81e0db09c6406ca7b1869bdc6ea8", + "tx_hash": "0x4dc9aa484e1afe6f9e01280925504841c26a81e0db09c6406ca7b1869bdc6ea8", "chain_id": "2", "block_number": 2 }, @@ -19,7 +19,7 @@ "promoter": "0xa260f8b7c8f37c2f1bc11b04c19902829de6ac8a", "promotee": "0x0b8a49d816cc709b6eadb09498030ae3416b66dc", "timestamp": 498539524, - "event_hash": "0xeb0bd6036ef28377b2288e0d1fb38c064c14635085777c6e88c617f9b21ac85b", + "tx_hash": "0xeb0bd6036ef28377b2288e0d1fb38c064c14635085777c6e88c617f9b21ac85b", "chain_id": "1", "block_number": 3 }, @@ -27,7 +27,7 @@ "promoter": "0xa260f8b7c8f37c2f1bc11b04c19902829de6ac8a", "promotee": "0x0b8a49d816cc709b6eadb09498030ae3416b66dc", "timestamp": 498539524, - "event_hash": "0xeb0bd6036ef28377b2288e0d1fb38c064c14635085777c6e88c617f9b21ac85b", + "tx_hash": "0xeb0bd6036ef28377b2288e0d1fb38c064c14635085777c6e88c617f9b21ac85b", "chain_id": "2", "block_number": 3 }, @@ -35,7 +35,7 @@ "promoter": "0xe023f53f735c196e4a028233c257812a41", "promotee": "0x01372be9616ff00469d3e509b77d6daf757180", "timestamp": 4985437524, - "event_hash": "0x46ab12e2cb6e5e7c2a1e0a1da7735785b713124aeb93ba3093e64ed69451e624", + "tx_hash": "0x46ab12e2cb6e5e7c2a1e0a1da7735785b713124aeb93ba3093e64ed69451e624", "chain_id": "2", "block_number": 4 } diff --git a/v2/pkg/storage/tradelogs/types/oneinch_v6.go b/v2/pkg/storage/tradelogs/types/oneinch_v6.go index 64073f1..54b2d4b 100644 --- a/v2/pkg/storage/tradelogs/types/oneinch_v6.go +++ b/v2/pkg/storage/tradelogs/types/oneinch_v6.go @@ -3,5 +3,6 @@ package types type OneInchType string const ( - RFQType OneInchType = "RFQ" + RFQType OneInchType = "RFQ" + FusionType OneInchType = "Fusion" )