From 1669bc36361b2efb866d6f14a3c0d3a5a5582dee Mon Sep 17 00:00:00 2001 From: minhthanh Date: Wed, 2 Oct 2024 17:46:06 +0700 Subject: [PATCH] update uniswap amount (#75) --- pkg/parser/uniswapx/parser.go | 8 ++++++-- pkg/parser/uniswapx/uniswap_test.go | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pkg/parser/uniswapx/parser.go b/pkg/parser/uniswapx/parser.go index d63d650..0efb653 100644 --- a/pkg/parser/uniswapx/parser.go +++ b/pkg/parser/uniswapx/parser.go @@ -20,6 +20,8 @@ const ( FilledEvent = "Fill" ) +var BPS = big.NewInt(10000) + type ResolvedOrder struct { Info struct { Reactor common.Address "json:\"reactor\"" @@ -260,9 +262,11 @@ func (p *Parser) updateOrder(internal storage.TradeLog, parsed []interface{}) (s makerAmount := big.NewInt(0) for _, o := range order.Outputs { - makerAmount = makerAmount.Add(makerAmount, decay(o.StartAmount, o.EndAmount, + output := decay(o.StartAmount, o.EndAmount, order.CosignerData.DecayStartTime, order.CosignerData.DecayEndTime, - big.NewInt(int64(internal.Timestamp/1000)))) + big.NewInt(int64(internal.Timestamp/1000))) + output = mulDivUp(output, new(big.Int).Add(BPS, order.CosignerData.ExclusivityOverrideBps), BPS) + makerAmount = makerAmount.Add(makerAmount, output) } internal.MakerTokenAmount = makerAmount.String() if order.Info.Deadline != nil { diff --git a/pkg/parser/uniswapx/uniswap_test.go b/pkg/parser/uniswapx/uniswap_test.go index bdca445..1392c7b 100644 --- a/pkg/parser/uniswapx/uniswap_test.go +++ b/pkg/parser/uniswapx/uniswap_test.go @@ -30,8 +30,8 @@ func TestFetchEvent(t *testing.T) { require.Equal(t, p.abi.Events[FilledEvent].ID, common.HexToHash("0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66")) logs, err := ethClient.FilterLogs(context.Background(), ethereum.FilterQuery{ BlockHash: nil, - FromBlock: big.NewInt(19719300), - ToBlock: big.NewInt(19719300), + FromBlock: big.NewInt(20655762), + ToBlock: big.NewInt(20655762), Addresses: nil, Topics: [][]common.Hash{ { @@ -47,7 +47,7 @@ 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":"0x3867393cc6ea7b0414c2c3e1d9fe7cea987fd066","topics":["0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66","0x510fd6dd82e657a1bc4e007ee563925923c5896fecc6996e491adcaff6c8a528","0x000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec6","0x000000000000000000000000250a94c03b9b57c93cc5549760d59d6eacfb136d"],"data":"0x04683239f5ccb91d719180e8d856523bf095571534b3cd850e678dd61919c153","blockNumber":"0x12ce484","transactionHash":"0xcbd70c12e81d3521ca0e96dc887ae6653063f75dbdcd943a5ee406fa30446619","transactionIndex":"0x81","blockHash":"0x32fc731de2f9509f6c829995e31b843c28594b866b39f9009cac65dbb8bee173","logIndex":"0x10c","removed":false}` + eventRaw := `{"address":"0x00000011f84b9aa48e5f8aa8b9897600006289be","topics":["0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66","0x9e57c601cc099a21f2adebee775f5c87197f64449d8dc14f4daa363a0acccd82","0x000000000000000000000000807cf9a772d5a3f9cefbc1192e939d62f0d9bd38","0x00000000000000000000000097e1e6c70fe9f2209792640336534bfc9f93aa7a"],"data":"0x046832e0bb8b67660fa0dab20dd6c717f3c188907d1b33cf6bb432d0434b4631","blockNumber":"0x13b2e92","transactionHash":"0x82f36abfb0f492ce6f6363cd9f233b2a86626234bfac5b1efe54e1c25a6fc410","transactionIndex":"0x1e","blockHash":"0xe6877169821ccccaf15256d0f802b4de56f11d6ca86783eb29a2530cc19fcdbe","logIndex":"0xc3","removed":false}` event := types.Log{} err := json.Unmarshal([]byte(eventRaw), &event) require.NoError(t, err) @@ -61,10 +61,10 @@ func TestParseEvent(t *testing.T) { require.NoError(t, err) fmt.Printf("%+v\n", log) require.Equal(t, log.EventHash, p.eventHash) - require.Equal(t, log.Maker, "0xff8Ba4D1fC3762f6154cc942CCF30049A2A0cEC6") - require.Equal(t, log.Taker, "0x250A94C03b9b57C93CC5549760D59d6eAcfB136d") - require.Equal(t, log.MakerTokenAmount, "42282994361466557") - require.Equal(t, log.TakerTokenAmount, "146889265") - require.Equal(t, log.Expiry, uint64(1713890185)) + require.Equal(t, log.Maker, "0x807cF9A772d5a3f9CeFBc1192e939D62f0D9bD38") + require.Equal(t, log.Taker, "0x97e1e6C70fe9F2209792640336534bFc9F93AA7A") + require.Equal(t, log.MakerTokenAmount, "197069169177783279401") + require.Equal(t, log.TakerTokenAmount, "10000000000000000000") + require.Equal(t, log.Expiry, uint64(0x66d46102)) t.Log(log) }