Skip to content

Commit 5f6f3b5

Browse files
feat: add evm price oracle (#1235)
1 parent 5f252c8 commit 5f6f3b5

File tree

16 files changed

+973
-292
lines changed

16 files changed

+973
-292
lines changed

cmd/consts/consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var Executables = struct {
3434
Eibc string
3535
CelestiaApp string
3636
Oracle string
37+
Solc string
3738
}{
3839
Roller: fmt.Sprintf("%s/roller", binsDir),
3940
RollappEVM: fmt.Sprintf("%s/rollappd", binsDir),
@@ -45,6 +46,7 @@ var Executables = struct {
4546
Eibc: fmt.Sprintf("%s/eibc-client", binsDir),
4647
CelestiaApp: fmt.Sprintf("%s/celestia-appd", InternalBinsDir),
4748
Oracle: fmt.Sprintf("%s/oracle", InternalBinsDir),
49+
Solc: fmt.Sprintf("%s/solc", InternalBinsDir),
4850
}
4951

5052
var KeysIds = struct {

cmd/consts/da.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ var DaNetworks = map[string]DaData{
5050
ApiUrl: DefaultCelestiaRestApiEndpoint,
5151
ID: CelestiaTestnet,
5252
RpcUrl: DefaultCelestiaRPC,
53-
CurrentStateNode: "mocha-4-consensus.mesa.newmetric.xyz",
53+
CurrentStateNode: "rpc-mocha.pops.one",
5454
StateNodes: []string{
55-
"mocha-4-consensus.mesa.newmetric.xyz",
5655
"public-celestia-mocha4-consensus.numia.xyz",
5756
"full.consensus.mocha-4.celestia-mocha.com",
5857
"consensus-full-mocha-4.celestia-mocha.com",

cmd/da-light-client/start/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func Cmd() *cobra.Command {
156156

157157
func addFlags(cmd *cobra.Command) {
158158
cmd.Flags().
159-
StringP(rpcEndpointFlag, "", "mocha-4-consensus.mesa.newmetric.xyz", "The DA rpc endpoint to connect to.")
159+
StringP(rpcEndpointFlag, "", "rpc-mocha.pops.one", "The DA rpc endpoint to connect to.")
160160
cmd.Flags().
161161
StringP(metricsEndpointFlag, "", "", "The OTEL collector metrics endpoint to connect to.")
162162
}

cmd/da-light-client/update/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Cmd() *cobra.Command {
4949

5050
func addFlags(cmd *cobra.Command) {
5151
cmd.Flags().
52-
StringP(rpcEndpointFlag, "", "mocha-4-consensus.mesa.newmetric.xyz", "The DA rpc endpoint to connect to.")
52+
StringP(rpcEndpointFlag, "", "rpc-mocha.pops.one", "The DA rpc endpoint to connect to.")
5353
cmd.Flags().
5454
StringP(metricsEndpointFlag, "", "", "The OTEL collector metrics endpoint to connect to.")
5555
}

cmd/oracle/config.go

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package oracle
33
import (
44
"bytes"
55
"crypto/sha256"
6-
"encoding/hex"
76
"encoding/json"
87
"fmt"
98
"os"
@@ -13,8 +12,6 @@ import (
1312
"time"
1413

1514
cosmossdkmath "cosmossdk.io/math"
16-
"github.com/cosmos/cosmos-sdk/crypto/hd"
17-
"github.com/cosmos/go-bip39"
1815
"github.com/pterm/pterm"
1916

2017
"github.com/dymensionxyz/roller/cmd/consts"
@@ -26,7 +23,6 @@ import (
2623
)
2724

2825
type OracleConfig struct {
29-
PrivateKey string
3026
OracleVmType string
3127
ConfigDirPath string
3228
CodeID string
@@ -35,7 +31,12 @@ type OracleConfig struct {
3531
ContractAddress string
3632
}
3733

38-
func NewOracle(rollerData roller.RollappConfig) *OracleConfig {
34+
type KeyData struct {
35+
Name string
36+
Address string
37+
}
38+
39+
func NewOracleConfig(rollerData roller.RollappConfig) *OracleConfig {
3940
cd := filepath.Join(rollerData.Home, consts.ConfigDirName.Oracle)
4041
ovt := rollerData.RollappVMType
4142
return &OracleConfig{
@@ -51,67 +52,32 @@ func (o *OracleConfig) ConfigDir(rollerData roller.RollappConfig) string {
5152
return o.ConfigDirPath
5253
}
5354

54-
func (o *OracleConfig) SetKey(rollerData roller.RollappConfig) error {
55-
addr, err := generateRaOracleKeys(rollerData.Home, rollerData)
55+
// generateRaOracleKeys generates a new key or retrieves an existing one from the keyring
56+
// as the second return value it returns whether the key was generated or retrieved where
57+
// true is retrieved and false is new generated key
58+
func generateRaOracleKeys(
59+
home string,
60+
rollerData roller.RollappConfig,
61+
) ([]keys.KeyInfo, bool, error) {
62+
oracleKeys, err := getOracleKeyConfig(rollerData.RollappVMType)
5663
if err != nil {
57-
return fmt.Errorf("failed to retrieve oracle keys: %v", err)
58-
}
59-
60-
if len(addr) == 0 {
61-
return fmt.Errorf("no oracle keys generated")
62-
}
63-
64-
hexKey, err := GetSecp256k1PrivateKey(addr[0].Mnemonic)
65-
if err != nil {
66-
return err
67-
}
68-
69-
o.KeyAddress = addr[0].Address
70-
o.KeyName = addr[0].Name
71-
o.PrivateKey = hexKey
72-
return nil
73-
}
74-
75-
func GetSecp256k1PrivateKey(mnemonic string) (string, error) {
76-
if !bip39.IsMnemonicValid(mnemonic) {
77-
return "", fmt.Errorf("invalid mnemonic")
78-
}
79-
80-
seed := bip39.NewSeed(mnemonic, "")
81-
82-
hdPath := "m/44'/60'/0'/0/0"
83-
master, ch := hd.ComputeMastersFromSeed(seed)
84-
privKey, err := hd.DerivePrivateKeyForPath(master, ch, hdPath)
85-
if err != nil {
86-
return "", err
87-
}
88-
89-
// Convert private key bytes to hex string
90-
hexKey := hex.EncodeToString(privKey)
91-
fmt.Println(hexKey)
92-
93-
return hexKey, nil
94-
}
95-
96-
func generateRaOracleKeys(home string, rollerData roller.RollappConfig) ([]keys.KeyInfo, error) {
97-
oracleKeys, err := getOracleKeyConfig()
98-
if err != nil {
99-
return nil, err
64+
return nil, false, err
10065
}
10166

10267
kc := oracleKeys[0]
10368
ok, err := kc.IsInKeyring(home)
10469
if err != nil {
105-
return nil, err
70+
return nil, false, err
10671
}
10772

10873
if ok {
10974
pterm.Info.Printfln("existing oracle key found, using it")
11075
ki, err := kc.Info(home)
76+
ki.Mnemonic = "not available for already existing keys"
11177
if err != nil {
112-
return nil, err
78+
return nil, false, err
11379
}
114-
return []keys.KeyInfo{*ki}, nil
80+
return []keys.KeyInfo{*ki}, true, nil
11581
}
11682

11783
shouldImportWallet, _ := pterm.DefaultInteractiveConfirm.WithDefaultText(
@@ -123,21 +89,21 @@ func generateRaOracleKeys(home string, rollerData roller.RollappConfig) ([]keys.
12389
if shouldImportWallet {
12490
ki, err := kc.Create(home)
12591
if err != nil {
126-
return nil, err
92+
return nil, false, err
12793
}
12894
addr = append(addr, *ki)
12995
} else {
13096
addr, err = createOraclesKeys(rollerData)
13197
if err != nil {
132-
return nil, err
98+
return nil, false, err
13399
}
134100
}
135101

136-
return addr, nil
102+
return addr, false, nil
137103
}
138104

139105
func createOraclesKeys(rollerData roller.RollappConfig) ([]keys.KeyInfo, error) {
140-
oracleKeys, err := getOracleKeyConfig()
106+
oracleKeys, err := getOracleKeyConfig(rollerData.RollappVMType)
141107
if err != nil {
142108
return nil, err
143109
}
@@ -218,7 +184,7 @@ func (o *OracleConfig) StoreWasmContract(rollerData roller.RollappConfig) error
218184
isAddrFunded := balance.Amount.GTE(one)
219185

220186
if !isAddrFunded {
221-
oracleKeys, err := getOracleKeyConfig()
187+
oracleKeys, err := getOracleKeyConfig(rollerData.RollappVMType)
222188
if err != nil {
223189
return fmt.Errorf("failed to get oracle keys: %v", err)
224190
}
@@ -326,7 +292,7 @@ func (o *OracleConfig) StoreEvmContract(rollerData roller.RollappConfig) error {
326292
isAddrFunded := balance.Amount.GTE(one)
327293

328294
if !isAddrFunded {
329-
oracleKeys, err := getOracleKeyConfig()
295+
oracleKeys, err := getOracleKeyConfig(rollerData.RollappVMType)
330296
if err != nil {
331297
return fmt.Errorf("failed to get oracle keys: %v", err)
332298
}
@@ -357,26 +323,15 @@ func (o *OracleConfig) StoreEvmContract(rollerData roller.RollappConfig) error {
357323
return fmt.Errorf("failed to store contract: %v, output: %s", err, output)
358324
}
359325

360-
tob := bytes.NewBufferString(output.String())
361-
err = tx_utils.CheckTxYamlStdOut(*tob)
362-
if err != nil {
363-
return err
364-
}
326+
time.Sleep(time.Second * 2)
365327

366-
// Extract transaction hash
367328
txHash, err := bash.ExtractTxHash(output.String())
368329
if err != nil {
369330
return fmt.Errorf("failed to extract transaction hash: %v", err)
370331
}
371332

372333
pterm.Info.Printfln("transaction hash: %s", txHash)
373334

374-
// // Monitor transaction
375-
// wsURL := "http://localhost:26657"
376-
// if err := tx.MonitorTransaction(wsURL, txHash); err != nil {
377-
// return fmt.Errorf("failed to monitor transaction: %v", err)
378-
// }
379-
380335
return nil
381336
}
382337

cmd/oracle/deployer.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package oracle
22

33
import (
44
"context"
5-
"crypto/ecdsa"
65
)
76

87
// ContractDeployer defines the interface for deploying contracts on different chains
@@ -13,9 +12,20 @@ type ContractDeployer interface {
1312
// DeployContract deploys the contract on chain and returns its address
1413
DeployContract(
1514
ctx context.Context,
16-
privateKey *ecdsa.PrivateKey,
17-
contractCode []byte,
1815
) (string, error)
1916

17+
// Config returns the OracleConfig
2018
Config() *OracleConfig
19+
20+
// PrivateKey returns the private key used to deploy the contract
21+
PrivateKey() string
22+
23+
// IsContractDeployed returns whether the contract has been deployed to the chain
24+
IsContractDeployed() (string, bool) // address, bool
25+
26+
// ContractPath returns the path to the contract file on the local machine
27+
ContractPath() string
28+
29+
// ClientConfigPath returns the filepath to the client config file
30+
ClientConfigPath() string
2131
}

0 commit comments

Comments
 (0)