|
|
@@ -3,22 +3,29 @@ package arbitrage
|
|
|
import (
|
|
|
"github.com/ethereum/go-ethereum/arbitrage/api"
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
+ "github.com/ethereum/go-ethereum/params"
|
|
|
+ "math/big"
|
|
|
)
|
|
|
|
|
|
// FundMovements 池子资金动向
|
|
|
type FundMovements struct {
|
|
|
- LpHash string
|
|
|
- Fee int64
|
|
|
- InIndex uint64
|
|
|
- InToken string
|
|
|
- OutIndex uint64
|
|
|
- OutToken string
|
|
|
+ LpHash string
|
|
|
+ Fee int64
|
|
|
+
|
|
|
+ InIndex uint64
|
|
|
+ InToken string
|
|
|
+ InReserve *big.Int
|
|
|
+
|
|
|
+ OutIndex uint64
|
|
|
+ OutToken string
|
|
|
+ OutReserve *big.Int
|
|
|
}
|
|
|
|
|
|
// Path 交易路径
|
|
|
type Path struct {
|
|
|
LoanTokenHash string
|
|
|
Level int64
|
|
|
+ Profit int64
|
|
|
FmList []FundMovements
|
|
|
}
|
|
|
|
|
|
@@ -90,21 +97,29 @@ func GeneratePathListCore(finalMapping map[string][]api.V2Lp, level int64, maxLe
|
|
|
// 3.2 构造FundMovements,必须要
|
|
|
if lastFm.OutToken == lp.Token0 {
|
|
|
newPath.FmList = append(path.FmList, FundMovements{
|
|
|
- LpHash: lp.Hash,
|
|
|
- Fee: lp.Fee,
|
|
|
- InIndex: 0,
|
|
|
- InToken: lp.Token0,
|
|
|
- OutIndex: 1,
|
|
|
- OutToken: lp.Token1,
|
|
|
+ LpHash: lp.Hash,
|
|
|
+ Fee: lp.Fee,
|
|
|
+
|
|
|
+ InIndex: 0,
|
|
|
+ InToken: lp.Token0,
|
|
|
+ InReserve: lp.R0,
|
|
|
+
|
|
|
+ OutIndex: 1,
|
|
|
+ OutToken: lp.Token1,
|
|
|
+ OutReserve: lp.R1,
|
|
|
})
|
|
|
} else if lastFm.OutToken == lp.Token1 {
|
|
|
newPath.FmList = append(path.FmList, FundMovements{
|
|
|
- LpHash: lp.Hash,
|
|
|
- Fee: lp.Fee,
|
|
|
- InIndex: 1,
|
|
|
- InToken: lp.Token1,
|
|
|
- OutIndex: 0,
|
|
|
- OutToken: lp.Token0,
|
|
|
+ LpHash: lp.Hash,
|
|
|
+ Fee: lp.Fee,
|
|
|
+
|
|
|
+ InIndex: 1,
|
|
|
+ InToken: lp.Token1,
|
|
|
+ InReserve: lp.R1,
|
|
|
+
|
|
|
+ OutIndex: 0,
|
|
|
+ OutToken: lp.Token0,
|
|
|
+ OutReserve: lp.R0,
|
|
|
})
|
|
|
} else {
|
|
|
log.Error("path生成有错误,请重新debug查询。", "lp hash", lp.Hash)
|
|
|
@@ -128,7 +143,18 @@ func GeneratePathList(finalLpList []api.V2Lp, finalMapping map[string][]api.V2Lp
|
|
|
LoanTokenHash: lp.Token1,
|
|
|
Level: NowLevel,
|
|
|
FmList: []FundMovements{
|
|
|
- {LpHash: lp.Hash, Fee: lp.Fee, InIndex: 0, InToken: lp.Token0, OutIndex: 1, OutToken: lp.Token1},
|
|
|
+ {
|
|
|
+ LpHash: lp.Hash,
|
|
|
+ Fee: lp.Fee,
|
|
|
+
|
|
|
+ InIndex: 0,
|
|
|
+ InToken: lp.Token0,
|
|
|
+ OutReserve: lp.R0,
|
|
|
+
|
|
|
+ OutIndex: 1,
|
|
|
+ OutToken: lp.Token1,
|
|
|
+ InReserve: lp.R1,
|
|
|
+ },
|
|
|
},
|
|
|
}
|
|
|
pathListA := GeneratePathListCore(finalMapping, NowLevel+1, maxLevel, pathA)
|
|
|
@@ -136,7 +162,18 @@ func GeneratePathList(finalLpList []api.V2Lp, finalMapping map[string][]api.V2Lp
|
|
|
LoanTokenHash: lp.Token0,
|
|
|
Level: NowLevel,
|
|
|
FmList: []FundMovements{
|
|
|
- {LpHash: lp.Hash, Fee: lp.Fee, InIndex: 1, InToken: lp.Token1, OutIndex: 0, OutToken: lp.Token0},
|
|
|
+ {
|
|
|
+ LpHash: lp.Hash,
|
|
|
+ Fee: lp.Fee,
|
|
|
+
|
|
|
+ InIndex: 1,
|
|
|
+ InToken: lp.Token1,
|
|
|
+ InReserve: lp.R1,
|
|
|
+
|
|
|
+ OutIndex: 0,
|
|
|
+ OutToken: lp.Token0,
|
|
|
+ OutReserve: lp.R0,
|
|
|
+ },
|
|
|
},
|
|
|
}
|
|
|
pathListB := GeneratePathListCore(finalMapping, NowLevel+1, maxLevel, pathB)
|
|
|
@@ -181,3 +218,34 @@ func ParseLpListToLpHashList(lpList []api.V2Lp) []string {
|
|
|
|
|
|
return rst
|
|
|
}
|
|
|
+
|
|
|
+func (h *HistoryArbitrage) GetLpList() []api.V2Lp {
|
|
|
+ rst, err := h.javaApi.V2LpListByChainIdAndPaginate(api.V2LpListByChainIdAndPaginateRequest{
|
|
|
+ ChainId: params.CoreChainConfig.ChainID.Uint64(),
|
|
|
+ PageNumber: 1,
|
|
|
+ PageSize: MaxLpLength,
|
|
|
+ AuthObj: api.GenerateAuth(),
|
|
|
+ })
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ HistoryError("Get lp list error.", err.Error())
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if !rst.State {
|
|
|
+ HistoryError("Get lp list java error.", err.Error())
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ return rst.Data
|
|
|
+}
|
|
|
+
|
|
|
+func PutR0R1ToLpList(lpList *[]api.V2Lp, balanceMapping map[string][2]*big.Int) {
|
|
|
+ for i := range *lpList {
|
|
|
+ lp := &((*lpList)[i])
|
|
|
+
|
|
|
+ reserves := balanceMapping[lp.Hash]
|
|
|
+ lp.R0 = reserves[0]
|
|
|
+ lp.R1 = reserves[1]
|
|
|
+ }
|
|
|
+}
|