Skip to content

Commit cadfa0c

Browse files
committed
fix: etherlink
1 parent 9b7b327 commit cadfa0c

File tree

6 files changed

+94
-2
lines changed

6 files changed

+94
-2
lines changed

ds/execute_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ func (f *FacadeCallNameWithMulticall) v3(client core.ClientI, events []*schemas.
161161
}
162162
eventToken := (*events[eventInd].Args)["token"]
163163
//
164-
log.Info(utils.ToJson(eventToken))
165-
log.Info(common.BytesToAddress(multiCall.CallData[4 : 4+32]))
164+
// log.Info(utils.ToJson(eventToken))
165+
// log.Info(common.BytesToAddress(multiCall.CallData[4 : 4+32]))
166166
//
167167
if eventToken != nil {
168168
tokenfromcall := common.BytesToAddress(multiCall.CallData[4 : 4+32])

ds/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/Gearbox-protocol/sdk-go/core/schemas/schemas_v3"
1212
"github.com/Gearbox-protocol/sdk-go/log"
1313
"github.com/Gearbox-protocol/sdk-go/pkg/redstone"
14+
"github.com/Gearbox-protocol/third-eye/config"
1415
"github.com/Gearbox-protocol/third-eye/ds/dc_wrapper"
1516
"github.com/ethereum/go-ethereum/common"
1617
"gorm.io/gorm"
@@ -59,6 +60,7 @@ type RepositoryI interface {
5960
GetBlocks() map[int64]*schemas.Block
6061
GetDisabledTokens() []*schemas.AllowedToken
6162
LoadBlocks(from, to int64)
63+
GetCfg() *config.Config
6264
// credit account operations
6365
AddAccountOperation(accountOperation *schemas.AccountOperation)
6466
// for getting executeparser

ds/repo_dummy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/Gearbox-protocol/sdk-go/core/schemas/schemas_v3"
1111
"github.com/Gearbox-protocol/sdk-go/log"
1212
"github.com/Gearbox-protocol/sdk-go/pkg/redstone"
13+
"github.com/Gearbox-protocol/third-eye/config"
1314
"github.com/Gearbox-protocol/third-eye/ds/dc_wrapper"
1415
"github.com/ethereum/go-ethereum/common"
1516
"gorm.io/gorm"
@@ -258,6 +259,9 @@ func (DummyRepo) IsBlockRecent(block int64, dur time.Duration) bool { return fal
258259
func (DummyRepo) GetRedStonemgr() redstone.RedStoneMgrI {
259260
return nil
260261
}
262+
func (DummyRepo) GetCfg() *config.Config {
263+
return nil
264+
}
261265

262266
type DieselBalance struct {
263267
BalanceBI *core.BigInt `gorm:"column:balance_bi"`

models/aggregated_block_feed/curve_price_feed/model.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package curve_price_feed
22

33
import (
44
"math/big"
5+
"strings"
56
"time"
67

78
"github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
89
"github.com/Gearbox-protocol/sdk-go/core"
910
"github.com/Gearbox-protocol/sdk-go/core/schemas"
1011
"github.com/Gearbox-protocol/sdk-go/log"
12+
"github.com/Gearbox-protocol/sdk-go/utils"
1113
"github.com/Gearbox-protocol/third-eye/ds"
1214
"github.com/Gearbox-protocol/third-eye/models/aggregated_block_feed/base_price_feed"
15+
"github.com/Gearbox-protocol/third-eye/models/aggregated_block_feed/redstone_price_feed"
16+
"github.com/ethereum/go-ethereum/accounts/abi"
1317
"github.com/ethereum/go-ethereum/common"
1418
)
1519

@@ -40,6 +44,25 @@ var curvePFLatestRoundDataTimer = map[string]log.TimerFn{}
4044
func (adapter *CurvePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, _ string, force ...bool) *schemas.PriceFeed {
4145
result := results[len(results)-1]
4246
if !result.Success {
47+
if core.GetBaseChainId(adapter.Client) == 42793 {
48+
calls, _ := adapter.GetUnderlyingCalls(blockNum)
49+
mcabi := core.GetAbi("MultiCall")
50+
calldata, err := mcabi.Pack("tryAggregate", false, calls)
51+
log.CheckFatal(err)
52+
53+
rpc := strings.Split(adapter.Repo.GetCfg().EthProvider, ",")
54+
multicallresult := redstone_price_feed.GetRedStoneResult(calldata, blockNum, rpc[0])
55+
value, err := core.GetAbi("YearnPriceFeed").Unpack("latestRoundData", multicallresult)
56+
log.CheckFatal(err)
57+
price := *abi.ConvertType(value[1], new(*big.Int)).(**big.Int)
58+
log.Info(price)
59+
return &schemas.PriceFeed{
60+
RoundId: 0,
61+
PriceBI: (*core.BigInt)(price),
62+
Price: utils.GetFloat64Decimal(price, 8),
63+
BlockNumber: blockNum,
64+
}
65+
}
4366
if adapter.GetVersion().LessThan(core.NewVersion(300)) { // failed and
4467
// if virtualprice of pool for this oracle is not within lowerBound and upperBound , ignore the price
4568
oracleAddr := common.HexToAddress(adapter.GetAddress())
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package redstone_price_feed
2+
3+
import (
4+
"encoding/hex"
5+
"fmt"
6+
"os/exec"
7+
"strings"
8+
9+
"github.com/Gearbox-protocol/sdk-go/log"
10+
)
11+
12+
func GetRedStoneResult(data []byte, block int64, rpc string) []byte {
13+
// Define the command and its arguments.
14+
// The first argument to exec.Command is the command itself,
15+
// and subsequent arguments are passed to that command.
16+
cmdstr := []string{
17+
"cast",
18+
"call",
19+
"0xca11bde05977b3631167028862be2a173976ca11", // multicall
20+
"--data",
21+
hex.EncodeToString(data),
22+
"--block",
23+
fmt.Sprintf("%d", block),
24+
"-r",
25+
rpc,
26+
"--trace",
27+
}
28+
cmd := exec.Command(cmdstr[0], cmdstr[1:]...) // Example: list files in the current directory
29+
30+
// Execute the command and capture its standard output.
31+
output, err := cmd.Output()
32+
if err != nil {
33+
log.Fatalf("Error executing command: %v", err)
34+
}
35+
36+
// Convert output to string and get the last line
37+
outputStr := string(output)
38+
lines := strings.Split(strings.TrimSpace(outputStr), "\n")
39+
if len(lines) == 0 {
40+
return nil
41+
}
42+
lastLine := ""
43+
for _, line := range lines {
44+
if strings.Contains(line, "0x") {
45+
lastLine = line
46+
}
47+
}
48+
49+
// Extract hex string from the last line (remove "0x" prefix if present)
50+
spls := strings.Split(strings.TrimSpace(lastLine), "0x")
51+
// Convert hex string to bytes
52+
log.Info(spls[1])
53+
bytes, err := hex.DecodeString(spls[1])
54+
if err != nil {
55+
log.Errorf("Error decoding hex string: %v", err)
56+
return nil
57+
}
58+
59+
return bytes[len(bytes)-5*32:]
60+
}

repository/index.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func NewRepository(db *gorm.DB, client core.ClientI, config *config.Config, ep *
7373
r := GetRepository(db, client, config, ep)
7474
return r
7575
}
76+
func (r Repository) GetCfg() *config.Config {
77+
return r.config
78+
}
7679

7780
func (r Repository) GetDB() *gorm.DB {
7881
return r.db

0 commit comments

Comments
 (0)