Skip to content

Commit

Permalink
WarpySyncer: ListaDAO integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeuchi committed Oct 28, 2024
1 parent 42e71d1 commit 8bd6ddd
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 50 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/lestrrat-go/jwx v1.2.25
github.com/lib/pq v1.10.7
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.14.0
github.com/redis/go-redis/v9 v9.0.5
github.com/robfig/cron v1.2.0
Expand Down Expand Up @@ -105,7 +106,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -159,7 +159,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down Expand Up @@ -201,7 +200,6 @@ require (
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
pgregory.net/rapid v0.5.5 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFP
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/OffchainLabs/go-ethereum v0.0.0-20230822203130-9a31b6205dba h1:wP31KC1na/F9wx6rPzGpajv6us7Nj2fgqtCs3W9Rp/A=
github.com/OffchainLabs/go-ethereum v0.0.0-20230822203130-9a31b6205dba/go.mod h1:dbMa0Avlq6Y7gF7MHunW9BCVCSYC1O+kF40ya9aU/3E=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
Expand Down Expand Up @@ -340,8 +338,6 @@ github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSM
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/gobuffalo/logger v1.0.6 h1:nnZNpxYo0zx+Aj9RfMPBm+x9zAU2OayFh/xrAWi34HU=
github.com/gobuffalo/logger v1.0.6/go.mod h1:J31TBEHR1QLV2683OXTAItYIg8pv2JMHnF/quuAbMjs=
github.com/gobuffalo/packd v1.0.1 h1:U2wXfRr4E9DH8IdsDLlRFwTZTK7hLfq9qT/QHXGVe/0=
Expand Down Expand Up @@ -1484,8 +1480,6 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
Expand Down
15 changes: 8 additions & 7 deletions src/utils/config/warpy_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func setWarpySyncerDefaults() {
viper.SetDefault("WarpySyncer.SyncerContractId", "p5OI99-BaY4QbZts266T7EDwofZqs-wVuYJmMCS0SUU")
viper.SetDefault("WarpySyncer.SyncerNameServiceContractId", "p5OI99-BaY4QbZts266T7EDwofZqs-wVuYJmMCS0SUU")
viper.SetDefault("WarpySyncer.SyncerChain", eth.Bsc)
viper.SetDefault("WarpySyncer.SyncerProtocol", eth.Venus)
viper.SetDefault("WarpySyncer.SyncerProtocol", eth.ListaDAO)
viper.SetDefault("WarpySyncer.SyncerDreUrl", "https://dre-warpy.warp.cc")
viper.SetDefault("WarpySyncer.SyncerWarpyApiUrl", "https://api-warpy.warp.cc")
viper.SetDefault("WarpySyncer.SyncerApiKey", "")
Expand All @@ -181,9 +181,9 @@ func setWarpySyncerDefaults() {
viper.SetDefault("WarpySyncer.SyncerDeltaRedstoneData", "000002ed57011e0000")
viper.SetDefault("WarpySyncer.SyncerDeltaNumWorkers", "50")
viper.SetDefault("WarpySyncer.SyncerDeltaWorkerQueueSize", "10")
viper.SetDefault("WarpySyncer.SyncerDepositContractIds", []string{"0xA07c5b74C9B40447a954e1466938b865b6BBea36", "0x882C173bC7Ff3b7786CA16dfeD3DFFfb9Ee7847B"})
viper.SetDefault("WarpySyncer.SyncerDepositContractIds", []string{"0xa835F890Fcde7679e7F7711aBfd515d2A267Ed0B", "0xB68443Ee3e828baD1526b3e0Bdf2Dfc6b1975ec4"})
viper.SetDefault("WarpySyncer.SyncerDepositBackoffInterval", "3s")
viper.SetDefault("WarpySyncer.SyncerDepositFunctions", []string{"mint", "redeem", "redeemUnderlying"})
viper.SetDefault("WarpySyncer.SyncerDepositFunctions", []string{"deposit", "provide", "provide0", "withdraw", "release"})
viper.SetDefault("WarpySyncer.SyncerDepositMarkets", []string{
// wETH
"0x952083cde7aaa11AB8449057F7de23A970AA8472",
Expand All @@ -197,17 +197,18 @@ func setWarpySyncerDefaults() {
})
viper.SetDefault("WarpySyncer.SyncerDepositToken", "0x6A0d9584D88D22BcaD7D4F83E7d6AB7949895DDF")
viper.SetDefault("WarpySyncer.SyncerDepositWithdrawLog", "Redeem")
viper.SetDefault("WarpySyncer.SyncerDepositDepositLog", "Mint")
viper.SetDefault("WarpySyncer.StoreDepositWithdrawFunctions", []string{"redeem", "redeemUnderlying"})
viper.SetDefault("WarpySyncer.SyncerDepositDepositLog", "Deposit")
viper.SetDefault("WarpySyncer.StoreDepositWithdrawFunctions", []string{"withdraw", "release"})
viper.SetDefault("WarpySyncer.StoreBatchSize", "500")
viper.SetDefault("WarpySyncer.StoreInterval", "2s")
viper.SetDefault("WarpySyncer.StoreMaxBackoffInterval", "30s")
viper.SetDefault("WarpySyncer.AssetsCalculatorDepositAssetsNames", []string{"mintAmount"})
viper.SetDefault("WarpySyncer.AssetsCalculatorWithdrawAssetsNames", []string{"redeemAmount"})
viper.SetDefault("WarpySyncer.AssetsCalculatorDepositAssetsNames", []string{"amount", "dink"})
viper.SetDefault("WarpySyncer.AssetsCalculatorWithdrawAssetsNames", []string{"amount", "dink"})
viper.SetDefault("WarpySyncer.PollerDepositChannelBufferLength", 100)
viper.SetDefault("WarpySyncer.PollerDepositInterval", "1m")
viper.SetDefault("WarpySyncer.PollerDepositTimeout", "90s")
viper.SetDefault("WarpySyncer.PollerDepositPointsBase", 1000)
// FIXME update this
viper.SetDefault("WarpySyncer.WriterPointsCap", 5000000)
viper.SetDefault("WarpySyncer.WriterIntegrationDurationInSec", 432000)
viper.SetDefault("WarpySyncer.PollerDepositSecondsForSelect", 3600)
Expand Down
21 changes: 18 additions & 3 deletions src/utils/eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
LayerBank Protocol = iota
Pendle Protocol = iota
Venus Protocol = iota
ListaDAO Protocol = iota
)

type Chain int
Expand All @@ -58,6 +59,7 @@ func (chain Chain) RpcProviderUrl() (rpcProviderUrl string, err error) {
return
case Manta:
rpcProviderUrl = "https://pacific-rpc.manta.network/http"
return
case Bsc:
rpcProviderUrl = "https://bsc-rpc.publicnode.com"
return
Expand All @@ -77,6 +79,7 @@ func (chain Chain) Api() (apiUrl string, err error) {
return
case Manta:
apiUrl = "https://pacific-explorer.manta.network/api"
return
case Bsc:
apiUrl = "https://api.bscscan.com/api"
return
Expand All @@ -98,6 +101,8 @@ func (protocol Protocol) String() string {
return "pendle"
case Venus:
return "venus"
case ListaDAO:
return "lista_dao"
}
return ""
}
Expand All @@ -106,6 +111,8 @@ func (protocol Protocol) GetAbi() string {
switch protocol {
case Sommelier, LayerBank, Venus:
return "direct"
case ListaDAO:
return "proxy"
case Pendle:
return "IPActionSwapPTV3.json"
}
Expand Down Expand Up @@ -140,10 +147,10 @@ func (chain Chain) Decimals() float64 {

func GetTokenName(contract string) string {
switch contract {
case "0xA07c5b74C9B40447a954e1466938b865b6BBea36":
case "0xa835F890Fcde7679e7F7711aBfd515d2A267Ed0B":
return "binancecoin"
case "0xB68443Ee3e828baD1526b3e0Bdf2Dfc6b1975ec4":
return "binancecoin"
case "0x882C173bC7Ff3b7786CA16dfeD3DFFfb9Ee7847B":
return "bitcoin"
}

return ""
Expand Down Expand Up @@ -210,6 +217,14 @@ func GetContractABI(contractAddress, apiKey string, chain Chain) (*abi.ABI, erro
return &contractABI, nil
}

func GetContractProxyABI(contractAddress, apiKey string, chain Chain) (*abi.ABI, error) {
abiProxies := map[string]string{
"0xB68443Ee3e828baD1526b3e0Bdf2Dfc6b1975ec4": "0x3a0f552C0555468A9f8Ab641FE44F5ba86208A9C",
"0xa835F890Fcde7679e7F7711aBfd515d2A267Ed0B": "0xF85D7C7BaF867A97A91fEB9583464B9D44D40a99",
}
return GetContractABI(abiProxies[contractAddress], apiKey, chain)
}

func DecodeTransactionInputData(contractABI *abi.ABI, data []byte) (method *abi.Method, inputsMap map[string]interface{}, err error) {
if len(data) == 0 {
err = errors.New("no data to decode")
Expand Down
19 changes: 5 additions & 14 deletions src/warpy_sync/assets_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package warpy_sync

import (
"context"
"encoding/json"
"errors"
"math"
"math/big"
Expand Down Expand Up @@ -105,7 +104,7 @@ func (self *AssetsCalculator) run() (err error) {
}

if assets == nil {
assets, err = self.getAssetsFromLog(payload.Method.Name, payload.Transaction, assetsNames)
assets, err = self.getAssetsFromLog(payload.Method.RawName, payload.Transaction, assetsNames)
}

if err != nil {
Expand Down Expand Up @@ -159,18 +158,10 @@ func (self *AssetsCalculator) run() (err error) {
}

func (self *AssetsCalculator) getAssetsFromInput(assetsNames []string, input map[string]interface{}) (assets interface{}) {
for i, a := range assetsNames {
if i == 0 {
assets = input[a]
} else {
var assetsInterface map[string]interface{}
assetsParsed, _ := json.Marshal(assets)
err := json.Unmarshal(assetsParsed, &assetsInterface)
if err != nil {
self.Log.WithError(err).Error("Could not parse assets input")
return nil
}
assets = assetsInterface[a]
for _, a := range assetsNames {
assets = input[a]
if assets != nil {
return
}
}
return
Expand Down
6 changes: 5 additions & 1 deletion src/warpy_sync/block_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math"
"math/big"
"runtime"
"strings"
"sync"

"github.com/cenkalti/backoff"
Expand Down Expand Up @@ -182,7 +183,10 @@ func (self *BlockDownloader) downloadBlockOrHeader(height int64) (blockHeight ui
return backoff.Permanent(err)
}
self.monitor.GetReport().WarpySyncer.Errors.BlockDownloaderFailures.Inc()
self.Log.WithError(err).WithField("height", height).Warn("Failed to download block, retrying...")
if strings.HasPrefix(err.Error(), "429 Too Many Requests") {
err = errors.New("429 Too Many Requests")
}
self.Log.WithField("height", height).WithError(err).Warn("Failed to download block, retrying...")
return err
}).
Run(func() (err error) {
Expand Down
8 changes: 7 additions & 1 deletion src/warpy_sync/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewController(config *config.Config) (self *Controller, err error) {
writerTask = writer.Task
syncerTask = syncer.Task
syncerOutput = syncer.Output
case eth.Sommelier, eth.LayerBank, eth.Pendle, eth.Venus:
case eth.Sommelier, eth.LayerBank, eth.Pendle, eth.Venus, eth.ListaDAO:
var contractAbi map[string]*abi.ABI
contractAbi = make(map[string]*abi.ABI)

Expand All @@ -111,6 +111,11 @@ func NewController(config *config.Config) (self *Controller, err error) {
syncerDepositContractId,
config.WarpySyncer.SyncerApiKey,
config.WarpySyncer.SyncerChain)
} else if abiSource == "proxy" {
contractAbi[syncerDepositContractId], err = eth.GetContractProxyABI(
syncerDepositContractId,
config.WarpySyncer.SyncerApiKey,
config.WarpySyncer.SyncerChain)
} else if abiSource != "" {
contractAbi[syncerDepositContractId], err = eth.GetContractABIFromFile(abiSource)
} else {
Expand All @@ -121,6 +126,7 @@ func NewController(config *config.Config) (self *Controller, err error) {
// to be removed in prod
if config.WarpySyncer.SyncerProtocol == eth.Venus {
pwd, _ := os.Getwd()
// FIXME update this
records := files.ReadCsvFile(fmt.Sprintf("%s/src/warpy_sync/files/testers.csv", pwd))

addresses := make([]string, len(records))
Expand Down
4 changes: 2 additions & 2 deletions src/warpy_sync/syncer_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (self *SyncerDeposit) checkTx(tx *types.Transaction, block *BlockInfoPayloa
return nil
}

if slices.Contains(self.Config.WarpySyncer.SyncerDepositFunctions, method.Name) {
if slices.Contains(self.Config.WarpySyncer.SyncerDepositFunctions, method.RawName) {
parsedInputsMap, err := json.Marshal(inputsMap)
if err != nil {
self.Log.WithError(err).Error("Could not parse transaction input")
Expand All @@ -167,7 +167,7 @@ func (self *SyncerDeposit) checkTx(tx *types.Transaction, block *BlockInfoPayloa
}
}

self.Log.WithField("method_name", method.Name).WithField("inputs_map", string(parsedInputsMap)).
self.Log.WithField("method_name", method.RawName).WithField("inputs_map", string(parsedInputsMap)).
Info("New transaction decoded")

select {
Expand Down
Loading

0 comments on commit 8bd6ddd

Please sign in to comment.