Skip to content

Commit 0e4796f

Browse files
authored
fix: curve incorrect pool classify (#47)
* fix: curve incorrect pool classify * add log for unsupported pools
1 parent 0f6afb9 commit 0e4796f

File tree

11 files changed

+148
-110
lines changed

11 files changed

+148
-110
lines changed

pkg/source/curve/constant.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ const (
7070
poolTypeCompound = "curve-compound"
7171
poolTypeTricrypto = "curve-tricrypto"
7272
poolTypeTwo = "curve-two"
73+
poolTypeUnsupported = "unsupported"
74+
)
75+
76+
// Curve pool types
77+
const (
78+
sourceMainRegistry = iota
79+
sourceMetaPoolsFactory
80+
sourceCryptoPoolsRegistry
81+
sourceCryptoPoolsFactory
7382
)
7483

7584
// Known weth9 implementation addresses, used in our implementation of Ether#wrapped

pkg/source/curve/pool_aave.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,35 @@ func (d *PoolsListUpdater) getNewPoolsTypeAave(
2929

3030
for i, poolAndRegistry := range poolAndRegistries {
3131
calls.AddCall(&ethrpc.Call{
32-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
33-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
32+
ABI: poolAndRegistry.RegistryOrFactoryABI,
33+
Target: poolAndRegistry.RegistryOrFactoryAddress,
3434
Method: registryOrFactoryMethodGetCoins,
3535
Params: []interface{}{poolAndRegistry.PoolAddress},
3636
}, []interface{}{&coins[i]})
3737

3838
calls.AddCall(&ethrpc.Call{
39-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
40-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
39+
ABI: poolAndRegistry.RegistryOrFactoryABI,
40+
Target: poolAndRegistry.RegistryOrFactoryAddress,
4141
Method: registryOrFactoryMethodGetUnderlyingCoins,
4242
Params: []interface{}{poolAndRegistry.PoolAddress},
4343
}, []interface{}{&underlyingCoins[i]})
4444

4545
calls.AddCall(&ethrpc.Call{
46-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
47-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
46+
ABI: poolAndRegistry.RegistryOrFactoryABI,
47+
Target: poolAndRegistry.RegistryOrFactoryAddress,
4848
Method: registryOrFactoryMethodGetUnderDecimals,
4949
Params: []interface{}{poolAndRegistry.PoolAddress},
5050
}, []interface{}{&decimals[i]})
5151

5252
calls.AddCall(&ethrpc.Call{
53-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
54-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
53+
ABI: poolAndRegistry.RegistryOrFactoryABI,
54+
Target: poolAndRegistry.RegistryOrFactoryAddress,
5555
Method: registryOrFactoryMethodGetLpToken,
5656
Params: []interface{}{poolAndRegistry.PoolAddress},
5757
}, []interface{}{&lpAddresses[i]})
5858
}
5959
if _, err := calls.TryAggregate(); err != nil {
60-
logger.WithFields(logger.Fields{
61-
"error": err,
62-
}).Errorf("failed to aggregate call to get pool data")
60+
logger.Errorf("failed to aggregate call to get pool data, err: %v", err)
6361
return nil, err
6462
}
6563

@@ -87,9 +85,7 @@ func (d *PoolsListUpdater) getNewPoolsTypeAave(
8785
}
8886
staticExtraBytes, err := json.Marshal(staticExtra)
8987
if err != nil {
90-
logger.WithFields(logger.Fields{
91-
"error": err,
92-
}).Errorf("failed to marshal static extra data")
88+
logger.Errorf("failed to marshal static extra data, err: %v", err)
9389
return nil, err
9490
}
9591

pkg/source/curve/pool_base.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func (d *PoolsListUpdater) getNewPoolsTypeBase(
3131

3232
for i, poolAndRegistry := range poolAndRegistries {
3333
calls.AddCall(&ethrpc.Call{
34-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
35-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
34+
ABI: poolAndRegistry.RegistryOrFactoryABI,
35+
Target: poolAndRegistry.RegistryOrFactoryAddress,
3636
Method: registryOrFactoryMethodGetCoins,
3737
Params: []interface{}{poolAndRegistry.PoolAddress},
3838
}, []interface{}{&coins[i]})
3939

4040
calls.AddCall(&ethrpc.Call{
41-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
42-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
41+
ABI: poolAndRegistry.RegistryOrFactoryABI,
42+
Target: poolAndRegistry.RegistryOrFactoryAddress,
4343
Method: registryOrFactoryMethodGetDecimals,
4444
Params: []interface{}{poolAndRegistry.PoolAddress},
4545
}, []interface{}{&decimals[i]})
@@ -102,7 +102,7 @@ func (d *PoolsListUpdater) getNewPoolsTypeBase(
102102
APrecision: aPrecisions[i].String(),
103103
}
104104
// The curve-base found inside the metaFactory has the lpToken equals its own pool Address and has the totalSupply method.
105-
if strings.EqualFold(staticExtra.LpToken, addressZero) && strings.EqualFold(*poolAndRegistries[i].RegistryOrFactoryAddress, d.config.MetaPoolsFactoryAddress) {
105+
if strings.EqualFold(staticExtra.LpToken, addressZero) && strings.EqualFold(poolAndRegistries[i].RegistryOrFactoryAddress, d.config.MetaPoolsFactoryAddress) {
106106
staticExtra.LpToken = strings.ToLower(poolAndRegistries[i].PoolAddress.Hex())
107107
}
108108
for j := range coins[i] {

pkg/source/curve/pool_compound.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@ func (d *PoolsListUpdater) getNewPoolsTypeCompound(
3030

3131
for i, poolAndRegistry := range poolAndRegistries {
3232
calls.AddCall(&ethrpc.Call{
33-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
34-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
33+
ABI: poolAndRegistry.RegistryOrFactoryABI,
34+
Target: poolAndRegistry.RegistryOrFactoryAddress,
3535
Method: registryOrFactoryMethodGetCoins,
3636
Params: []interface{}{poolAndRegistry.PoolAddress},
3737
}, []interface{}{&coins[i]})
3838

3939
calls.AddCall(&ethrpc.Call{
40-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
41-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
40+
ABI: poolAndRegistry.RegistryOrFactoryABI,
41+
Target: poolAndRegistry.RegistryOrFactoryAddress,
4242
Method: registryOrFactoryMethodGetUnderlyingCoins,
4343
Params: []interface{}{poolAndRegistry.PoolAddress},
4444
}, []interface{}{&underlyingCoins[i]})
4545

4646
calls.AddCall(&ethrpc.Call{
47-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
48-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
47+
ABI: poolAndRegistry.RegistryOrFactoryABI,
48+
Target: poolAndRegistry.RegistryOrFactoryAddress,
4949
Method: registryOrFactoryMethodGetUnderDecimals,
5050
Params: []interface{}{poolAndRegistry.PoolAddress},
5151
}, []interface{}{&decimals[i]})
5252

5353
calls.AddCall(&ethrpc.Call{
54-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
55-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
54+
ABI: poolAndRegistry.RegistryOrFactoryABI,
55+
Target: poolAndRegistry.RegistryOrFactoryAddress,
5656
Method: registryOrFactoryMethodGetLpToken,
5757
Params: []interface{}{poolAndRegistry.PoolAddress},
5858
}, []interface{}{&lpAddresses[i]})

pkg/source/curve/pool_lists_classifier.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ import (
1313

1414
func (d *PoolsListUpdater) classifyPoolTypes(
1515
ctx context.Context,
16+
poolsSourceIndex int,
1617
registryOrFactoryABI abi.ABI,
1718
registryOrFactoryAddress string,
1819
poolAddresses []common.Address,
1920
) ([]string, error) {
20-
if strings.EqualFold(registryOrFactoryAddress, d.config.CryptoPoolsRegistryAddress) ||
21-
strings.EqualFold(registryOrFactoryAddress, d.config.CryptoPoolsFactoryAddress) {
21+
switch poolsSourceIndex {
22+
case sourceMainRegistry:
23+
return d.classifyCurveV1PoolTypes(ctx, registryOrFactoryABI, registryOrFactoryAddress, poolAddresses)
24+
case sourceMetaPoolsFactory:
25+
return d.classifyCurveV1PoolTypes(ctx, registryOrFactoryABI, registryOrFactoryAddress, poolAddresses)
26+
case sourceCryptoPoolsRegistry:
2227
return d.classifyCurveV2PoolTypes(ctx, registryOrFactoryABI, registryOrFactoryAddress, poolAddresses)
28+
case sourceCryptoPoolsFactory:
29+
return d.classifyCurveV2PoolTypes(ctx, registryOrFactoryABI, registryOrFactoryAddress, poolAddresses)
30+
default:
31+
return d.classifyCurveV1PoolTypes(ctx, registryOrFactoryABI, registryOrFactoryAddress, poolAddresses)
2332
}
24-
25-
return d.classifyCurveV1PoolTypes(ctx, registryOrFactoryABI, registryOrFactoryAddress, poolAddresses)
2633
}
2734

2835
// classifyCurveV1PoolTypes includes plainOracle, base, meta, aave, compound
@@ -150,7 +157,7 @@ func (d *PoolsListUpdater) classifyCurveV2PoolTypes(
150157
registryOrFactoryAddress string,
151158
poolAddresses []common.Address,
152159
) ([]string, error) {
153-
var coins = make([][8]common.Address, len(poolAddresses))
160+
coins := make([][8]common.Address, len(poolAddresses))
154161
calls := d.ethrpcClient.NewRequest().SetContext(ctx)
155162
for i, poolAddress := range poolAddresses {
156163
calls.AddCall(&ethrpc.Call{
@@ -171,8 +178,11 @@ func (d *PoolsListUpdater) classifyCurveV2PoolTypes(
171178
for i := range poolAddresses {
172179
if d.isTwo(coins[i]) {
173180
poolTypes[i] = poolTypeTwo
174-
} else {
181+
} else if d.isTricrypto(coins[i]) {
175182
poolTypes[i] = poolTypeTricrypto
183+
} else {
184+
logger.Infof("unsupported curve v2 pool: %s", poolAddresses[i].Hex())
185+
poolTypes[i] = poolTypeUnsupported
176186
}
177187
}
178188

@@ -265,7 +275,7 @@ func (d *PoolsListUpdater) isCompoundPool(
265275
// isTwo TwoCryptoPool
266276
// is curveV2, belongs to CryptoFactory and CryptoRegistry
267277
// has "gamma" in its contracts
268-
// has only 2 coins (has 2 coins is TriCryptoPool)
278+
// has only 2 coins (has 3 coins is TricryptoPool)
269279
func (d *PoolsListUpdater) isTwo(coins [8]common.Address) bool {
270280
var numberOfCoin = 0
271281
for _, coin := range coins {
@@ -277,3 +287,18 @@ func (d *PoolsListUpdater) isTwo(coins [8]common.Address) bool {
277287

278288
return numberOfCoin == 2
279289
}
290+
291+
// isTricrypto is curveV2, belongs to CryptoRegistry and CryptoFactory
292+
// has "gamma" in its contracts
293+
// has only 3 coins (has 2 coins is TwoPool)
294+
func (d *PoolsListUpdater) isTricrypto(coins [8]common.Address) bool {
295+
var numberOfCoin = 0
296+
for _, coin := range coins {
297+
if strings.EqualFold(coin.Hex(), addressZero) {
298+
break
299+
}
300+
numberOfCoin += 1
301+
}
302+
303+
return numberOfCoin == 3
304+
}

pkg/source/curve/pool_meta.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (d *PoolsListUpdater) getNewPoolsTypeMeta(
3030
calls := d.ethrpcClient.NewRequest().SetContext(ctx)
3131

3232
for i, poolAndRegistry := range poolAndRegistries {
33-
if strings.EqualFold(*poolAndRegistry.RegistryOrFactoryAddress, d.config.MetaPoolsFactoryAddress) {
33+
if strings.EqualFold(poolAndRegistry.RegistryOrFactoryAddress, d.config.MetaPoolsFactoryAddress) {
3434
calls.AddCall(&ethrpc.Call{
3535
ABI: metaPoolFactoryABI,
3636
Target: d.config.MetaPoolsFactoryAddress,
@@ -47,22 +47,22 @@ func (d *PoolsListUpdater) getNewPoolsTypeMeta(
4747
}
4848

4949
calls.AddCall(&ethrpc.Call{
50-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
51-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
50+
ABI: poolAndRegistry.RegistryOrFactoryABI,
51+
Target: poolAndRegistry.RegistryOrFactoryAddress,
5252
Method: registryOrFactoryMethodGetCoins,
5353
Params: []interface{}{poolAndRegistry.PoolAddress},
5454
}, []interface{}{&coins[i]})
5555

5656
calls.AddCall(&ethrpc.Call{
57-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
58-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
57+
ABI: poolAndRegistry.RegistryOrFactoryABI,
58+
Target: poolAndRegistry.RegistryOrFactoryAddress,
5959
Method: registryOrFactoryMethodGetUnderlyingCoins,
6060
Params: []interface{}{poolAndRegistry.PoolAddress},
6161
}, []interface{}{&underlyingCoins[i]})
6262

6363
calls.AddCall(&ethrpc.Call{
64-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
65-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
64+
ABI: poolAndRegistry.RegistryOrFactoryABI,
65+
Target: poolAndRegistry.RegistryOrFactoryAddress,
6666
Method: registryOrFactoryMethodGetDecimals,
6767
Params: []interface{}{poolAndRegistry.PoolAddress},
6868
}, []interface{}{&decimals[i]})
@@ -82,17 +82,13 @@ func (d *PoolsListUpdater) getNewPoolsTypeMeta(
8282
}, []interface{}{&aPreciseList[i]})
8383
}
8484
if _, err := calls.TryAggregate(); err != nil {
85-
logger.WithFields(logger.Fields{
86-
"error": err,
87-
}).Errorf("failed to aggregate call to get pool data")
85+
logger.Errorf("failed to aggregate call to get pool data, err: %v", err)
8886
return nil, err
8987
}
9088

9189
aPrecisions, err := getAPrecisions(aList, aPreciseList)
9290
if err != nil {
93-
logger.WithFields(logger.Fields{
94-
"error": err,
95-
}).Errorf("failed to calculate aPrecisions")
91+
logger.Errorf("failed to calculate aPrecisions, err: %v", err)
9692
return nil, err
9793
}
9894

@@ -124,9 +120,7 @@ func (d *PoolsListUpdater) getNewPoolsTypeMeta(
124120
}
125121
staticExtraBytes, err := json.Marshal(staticExtra)
126122
if err != nil {
127-
logger.WithFields(logger.Fields{
128-
"error": err,
129-
}).Errorf("failed to marshal static extra data")
123+
logger.Errorf("failed to marshal static extra data, err: %v", err)
130124
return nil, err
131125
}
132126

pkg/source/curve/pool_plain_oracle.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,27 @@ func (d *PoolsListUpdater) getNewPoolsTypePlainOracle(
2020
poolAndRegistries []PoolAndRegistries,
2121
) ([]entity.Pool, error) {
2222
var (
23-
coins = make([][8]common.Address, len(poolAndRegistries))
24-
underlyingCoins = make([][8]common.Address, len(poolAndRegistries))
25-
decimals = make([][8]*big.Int, len(poolAndRegistries))
26-
aList = make([]*big.Int, len(poolAndRegistries))
27-
aPreciseList = make([]*big.Int, len(poolAndRegistries))
28-
plainOracles = make([]common.Address, len(poolAndRegistries))
29-
lpAddresses = make([]common.Address, len(poolAndRegistries))
23+
coins = make([][8]common.Address, len(poolAndRegistries))
24+
decimals = make([][8]*big.Int, len(poolAndRegistries))
25+
aList = make([]*big.Int, len(poolAndRegistries))
26+
aPreciseList = make([]*big.Int, len(poolAndRegistries))
27+
plainOracles = make([]common.Address, len(poolAndRegistries))
28+
lpAddresses = make([]common.Address, len(poolAndRegistries))
3029
)
3130

3231
calls := d.ethrpcClient.NewRequest().SetContext(ctx)
3332

3433
for i, poolAndRegistry := range poolAndRegistries {
3534
calls.AddCall(&ethrpc.Call{
36-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
37-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
35+
ABI: poolAndRegistry.RegistryOrFactoryABI,
36+
Target: poolAndRegistry.RegistryOrFactoryAddress,
3837
Method: registryOrFactoryMethodGetCoins,
3938
Params: []interface{}{poolAndRegistry.PoolAddress},
4039
}, []interface{}{&coins[i]})
4140

4241
calls.AddCall(&ethrpc.Call{
43-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
44-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
45-
Method: registryOrFactoryMethodGetUnderlyingCoins,
46-
Params: []interface{}{poolAndRegistry.PoolAddress},
47-
}, []interface{}{&underlyingCoins[i]})
48-
49-
calls.AddCall(&ethrpc.Call{
50-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
51-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
42+
ABI: poolAndRegistry.RegistryOrFactoryABI,
43+
Target: poolAndRegistry.RegistryOrFactoryAddress,
5244
Method: registryOrFactoryMethodGetDecimals,
5345
Params: []interface{}{poolAndRegistry.PoolAddress},
5446
}, []interface{}{&decimals[i]})
@@ -106,7 +98,7 @@ func (d *PoolsListUpdater) getNewPoolsTypePlainOracle(
10698
Oracle: plainOracles[i].Hex(),
10799
}
108100
// The curve-base found inside the metaFactory has the lpToken equals its own pool Address and has the totalSupply method.
109-
if strings.EqualFold(staticExtra.LpToken, addressZero) && strings.EqualFold(*poolAndRegistries[i].RegistryOrFactoryAddress, d.config.MetaPoolsFactoryAddress) {
101+
if strings.EqualFold(staticExtra.LpToken, addressZero) && strings.EqualFold(poolAndRegistries[i].RegistryOrFactoryAddress, d.config.MetaPoolsFactoryAddress) {
110102
staticExtra.LpToken = strings.ToLower(poolAndRegistries[i].PoolAddress.Hex())
111103
}
112104
for j := range coins[i] {

pkg/source/curve/pool_tricrypto.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ func (d *PoolsListUpdater) getNewPoolsTypeTricrypto(
2828

2929
for i, poolAndRegistry := range poolAndRegistries {
3030
calls.AddCall(&ethrpc.Call{
31-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
32-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
31+
ABI: poolAndRegistry.RegistryOrFactoryABI,
32+
Target: poolAndRegistry.RegistryOrFactoryAddress,
3333
Method: registryOrFactoryMethodGetCoins,
3434
Params: []interface{}{poolAndRegistry.PoolAddress},
3535
}, []interface{}{&coins[i]})
3636

3737
calls.AddCall(&ethrpc.Call{
38-
ABI: *poolAndRegistry.RegistryOrFactoryABI,
39-
Target: *poolAndRegistry.RegistryOrFactoryAddress,
38+
ABI: poolAndRegistry.RegistryOrFactoryABI,
39+
Target: poolAndRegistry.RegistryOrFactoryAddress,
4040
Method: registryOrFactoryMethodGetDecimals,
4141
Params: []interface{}{poolAndRegistry.PoolAddress},
4242
}, []interface{}{&decimals[i]})

0 commit comments

Comments
 (0)