Skip to content

Commit fc1e3c4

Browse files
authored
ft: integrate aethonswap-v4 and expand iziswap and uniswap-v4-euler to monad (#1175)
1 parent 5461c92 commit fc1e3c4

File tree

7 files changed

+184
-954
lines changed

7 files changed

+184
-954
lines changed

pkg/source/ramsesv2/abis/PoolV2.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,24 @@
222222
{
223223
"inputs": [
224224
{
225-
"internalType": "uint32",
225+
"internalType": "uint8",
226226
"name": "feeProtocol0Old",
227-
"type": "uint32"
227+
"type": "uint8"
228228
},
229229
{
230-
"internalType": "uint32",
230+
"internalType": "uint8",
231231
"name": "feeProtocol1Old",
232-
"type": "uint32"
232+
"type": "uint8"
233233
},
234234
{
235-
"internalType": "uint32",
235+
"internalType": "uint8",
236236
"name": "feeProtocol0New",
237-
"type": "uint32"
237+
"type": "uint8"
238238
},
239239
{
240-
"internalType": "uint32",
240+
"internalType": "uint8",
241241
"name": "feeProtocol1New",
242-
"type": "uint32"
242+
"type": "uint8"
243243
}
244244
],
245245
"name": "SetFeeProtocol",

pkg/source/ramsesv2/abis/abigen_pool_v2.go

Lines changed: 9 additions & 548 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/source/ramsesv2/abis/abigen_pool_v3.go

Lines changed: 19 additions & 312 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/source/ramsesv2/pool_tracker.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ func NewPoolTracker(
5050
}, nil
5151
}
5252

53-
func (d *PoolTracker) GetNewPoolState(
53+
func (t *PoolTracker) GetNewPoolState(
5454
ctx context.Context,
5555
p entity.Pool,
5656
param sourcePool.GetNewPoolStateParams,
5757
) (entity.Pool, error) {
58-
logger.Infof("[%s] Start getting new state of pool: %v", d.config.DexID, p.Address)
58+
logger.Infof("[%s] Start getting new state of pool: %v", t.config.DexID, p.Address)
5959

6060
var (
6161
rpcData *FetchRPCResult
@@ -65,7 +65,7 @@ func (d *PoolTracker) GetNewPoolState(
6565
g := pool.New().WithContext(ctx)
6666
g.Go(func(context.Context) error {
6767
var err error
68-
rpcData, err = d.FetchRPCData(ctx, &p, 0)
68+
rpcData, err = t.FetchRPCData(ctx, &p, 0)
6969
if err != nil {
7070
logger.WithFields(logger.Fields{
7171
"poolAddress": p.Address,
@@ -77,8 +77,8 @@ func (d *PoolTracker) GetNewPoolState(
7777
})
7878
g.Go(func(context.Context) error {
7979
var err error
80-
if d.config.AlwaysUseTickLens {
81-
poolTicks, err = ticklens.GetPoolTicksFromSC(ctx, d.ethrpcClient, d.config.TickLensAddress, p, nil)
80+
if t.config.AlwaysUseTickLens {
81+
poolTicks, err = ticklens.GetPoolTicksFromSC(ctx, t.ethrpcClient, t.config.TickLensAddress, p, nil)
8282
if err != nil {
8383
logger.WithFields(logger.Fields{
8484
"error": err,
@@ -87,7 +87,7 @@ func (d *PoolTracker) GetNewPoolState(
8787
return err
8888
}
8989

90-
poolTicks, err = d.getPoolTicks(ctx, p.Address)
90+
poolTicks, err = t.getPoolTicks(ctx, p.Address)
9191
if err != nil {
9292
logger.WithFields(logger.Fields{
9393
"poolAddress": p.Address,
@@ -145,12 +145,12 @@ func (d *PoolTracker) GetNewPoolState(
145145
rpcData.Reserve1.String(),
146146
}
147147

148-
logger.Infof("[%s] Finish updating state of pool: %v", d.config.DexID, p.Address)
148+
logger.Infof("[%s] Finish updating state of pool: %v", t.config.DexID, p.Address)
149149

150150
return p, nil
151151
}
152152

153-
func (d *PoolTracker) FetchRPCData(ctx context.Context, p *entity.Pool, blockNumber uint64) (*FetchRPCResult, error) {
153+
func (t *PoolTracker) FetchRPCData(ctx context.Context, p *entity.Pool, blockNumber uint64) (*FetchRPCResult, error) {
154154
var (
155155
liquidity *big.Int
156156
slot0 Slot0
@@ -160,15 +160,15 @@ func (d *PoolTracker) FetchRPCData(ctx context.Context, p *entity.Pool, blockNum
160160
reserve1 = zeroBI
161161
)
162162

163-
rpcRequest := d.ethrpcClient.NewRequest()
163+
rpcRequest := t.ethrpcClient.NewRequest()
164164
rpcRequest.SetContext(ctx)
165165
if blockNumber > 0 {
166166
var blockNumberBI big.Int
167167
blockNumberBI.SetUint64(blockNumber)
168168
rpcRequest.SetBlockNumber(&blockNumberBI)
169169
}
170170

171-
if d.config.IsPoolV3 {
171+
if t.config.IsPoolV3 {
172172
rpcRequest.AddCall(&ethrpc.Call{
173173
ABI: poolV3ABI,
174174
Target: p.Address,
@@ -236,8 +236,8 @@ func (d *PoolTracker) FetchRPCData(ctx context.Context, p *entity.Pool, blockNum
236236
}, err
237237
}
238238

239-
func (d *PoolTracker) getPoolTicks(ctx context.Context, poolAddress string) ([]ticklens.TickResp, error) {
240-
allowSubgraphError := d.config.IsAllowSubgraphError()
239+
func (t *PoolTracker) getPoolTicks(ctx context.Context, poolAddress string) ([]ticklens.TickResp, error) {
240+
allowSubgraphError := t.config.IsAllowSubgraphError()
241241
lastTickIdx := ""
242242
var ticks []ticklens.TickResp
243243

@@ -249,7 +249,7 @@ func (d *PoolTracker) getPoolTicks(ctx context.Context, poolAddress string) ([]t
249249
Meta *valueobject.SubgraphMeta `json:"_meta"`
250250
}
251251

252-
if err := d.graphqlClient.Run(ctx, req, &resp); err != nil {
252+
if err := t.graphqlClient.Run(ctx, req, &resp); err != nil {
253253
// Workaround at the moment to live with the error subgraph on Arbitrum
254254
if allowSubgraphError {
255255
if resp.Ticks == nil {
@@ -272,7 +272,7 @@ func (d *PoolTracker) getPoolTicks(ctx context.Context, poolAddress string) ([]t
272272
}
273273
}
274274

275-
resp.Meta.CheckIsLagging(d.config.DexID, poolAddress)
275+
resp.Meta.CheckIsLagging(t.config.DexID, poolAddress)
276276

277277
if len(resp.Ticks) == 0 {
278278
break
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ramsesv2
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"github.com/ethereum/go-ethereum/core/types"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func Test_PoolTracker_getTickIndexesFromLogs(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
logs []types.Log
16+
want []int
17+
}{
18+
{
19+
name: "Mint V3",
20+
logs: []types.Log{{
21+
Address: common.HexToAddress("0xee02e3a3034e9ef3bd569b140bc9911fcf1ba067"),
22+
Topics: []common.Hash{
23+
common.HexToHash("0xd78218c0d304e8893cb3200abe394bbc8d5b7804d9c51f236df9fdcf481d02d3"),
24+
common.HexToHash("0x000000000000000000000000b3f77c5134d643483253d22e0ca24627ae42ed51"),
25+
common.HexToHash("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc57e8"),
26+
common.HexToHash("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc57f2"),
27+
},
28+
Data: common.FromHex("0x000000000000000000000000b3f77c5134d643483253d22e0ca24627ae42ed51000000000000000000000000000000000000000000000000000000000000247d000000000000000000000000000000000000000000000000006195d80fdba6de0000000000000000000000000000000000000000000000001e709140f362c0ad0000000000000000000000000000000000000000000000000000000000000000"),
29+
}},
30+
want: []int{-239640, -239630},
31+
},
32+
{
33+
name: "Burn V3",
34+
logs: []types.Log{{
35+
Address: common.HexToAddress("0xee02e3a3034e9ef3bd569b140bc9911fcf1ba067"),
36+
Topics: []common.Hash{
37+
common.HexToHash("0x0c396cd989a39f4459b5fa1aed6a9a8dcdbc45908acfd67e028cd568da98982c"),
38+
common.HexToHash("0x000000000000000000000000b3f77c5134d643483253d22e0ca24627ae42ed51"),
39+
common.HexToHash("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc57f2"),
40+
common.HexToHash("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc57fc"),
41+
},
42+
Data: common.FromHex("0x0000000000000000000000000000000000000000000000000061a2965d1d517e0000000000000000000000000000000000000000000000001e70a533f0846dce0000000000000000000000000000000000000000000000000000000000000000"),
43+
}},
44+
want: []int{-239630, -239620},
45+
},
46+
}
47+
for _, tt := range tests {
48+
t.Run(tt.name, func(t *testing.T) {
49+
poolTracker := PoolTracker{}
50+
got, err := poolTracker.getTickIndexesFromLogs(tt.logs)
51+
require.NoError(t, err)
52+
assert.ElementsMatch(t, got, tt.want)
53+
})
54+
}
55+
}

pkg/valueobject/address.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const (
1010
DAITokenAddress = "0x6b175474e89094c44da98b954eedeac495271d0f"
1111
)
1212

13+
var (
14+
AddrZero common.Address
15+
AddrNative = common.HexToAddress(NativeAddress)
16+
)
17+
1318
func IsZeroAddress(address common.Address) bool {
14-
return address.Cmp(common.Address{}) == 0
19+
return address == AddrZero
1520
}

0 commit comments

Comments
 (0)