diff --git a/scripts/bridge/setup/cmd/setup.go b/scripts/bridge/setup/cmd/setup.go index 4b29c59a..44d552ef 100644 --- a/scripts/bridge/setup/cmd/setup.go +++ b/scripts/bridge/setup/cmd/setup.go @@ -22,7 +22,6 @@ import ( "github.com/limechain/hedera-eth-bridge-validator/scripts/bridge/setup" ) - func main() { privateKey := flag.String("privateKey", "0x0", "Hedera Private Key") accountID := flag.String("accountID", "0.0", "Hedera Account ID") @@ -34,7 +33,7 @@ func main() { // pass empty array of private keys since we are using this script for new accounts hederaPrivateKeys := make([]hedera.PrivateKey, 0) - result := setup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, topicThreshold) + result := setup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, *topicThreshold) if result.Error != nil { panic(result.Error) } diff --git a/scripts/bridge/setup/from-config/cmd/setup-from-config.go b/scripts/bridge/setup/from-config/cmd/setup-from-config.go index 5f9a0807..efaac8d2 100644 --- a/scripts/bridge/setup/from-config/cmd/setup-from-config.go +++ b/scripts/bridge/setup/from-config/cmd/setup-from-config.go @@ -19,9 +19,14 @@ package main import ( "flag" "fmt" + "math" + "github.com/hashgraph/hedera-sdk-go/v2" "github.com/limechain/hedera-eth-bridge-validator/config" - cfgParser "github.com/limechain/hedera-eth-bridge-validator/config/parser" + + "io/ioutil" + "strings" + "github.com/limechain/hedera-eth-bridge-validator/constants" bridgeSetup "github.com/limechain/hedera-eth-bridge-validator/scripts/bridge/setup" "github.com/limechain/hedera-eth-bridge-validator/scripts/bridge/setup/parser" @@ -31,8 +36,6 @@ import ( nativeNftCreate "github.com/limechain/hedera-eth-bridge-validator/scripts/token/native/nft/create" wrappedFungibleCreate "github.com/limechain/hedera-eth-bridge-validator/scripts/token/wrapped/create" "gopkg.in/yaml.v2" - "io/ioutil" - "strings" ) const ( @@ -52,8 +55,6 @@ func main() { members := flag.Int("members", 1, "The count of the members") memberPrivateKeys := flag.String("memberPrivateKeys", "", "Member private keys array, seperated by ','") adminKey := flag.String("adminKey", "", "The admin key") - topicThreshold := flag.Uint("topicThreshold", 1, "Topic member keys sign threshold") - wrappedFungibleThreshold := flag.Uint("wrappedTokenThreshold", 1, "The desired threshold of n/m keys required for supply key of wrapped tokens") configPath := flag.String("configPath", "scripts/bridge/setup/extend-config/extended-bridge.yml", "Path to the 'bridge.yaml' config file") flag.Parse() @@ -71,16 +72,18 @@ func main() { } } - validateArguments(privateKey, accountID, adminKey, topicThreshold, members, configPath, network) + treshold := uint(math.Ceil(float64(*members) * float64(0.51))) + + validateArguments(privateKey, accountID, adminKey, members, configPath, network) if *network == "testnet" { hederaNetworkId = HederaTestnetNetworkId } else { hederaNetworkId = HederaMainnetNetworkId } parsedBridgeCfgForDeploy := parseExtendedBridge(configPath) - bridgeDeployResult := deployBridge(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, topicThreshold, parsedBridgeCfgForDeploy) + bridgeDeployResult := deployBridge(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, treshold, parsedBridgeCfgForDeploy) createAndAssociateTokens( - wrappedFungibleThreshold, + &treshold, bridgeDeployResult, privateKey, accountID, @@ -89,7 +92,7 @@ func main() { ) printTitle("Updated Bridge yaml config:") - newBridgeYml, err := yaml.Marshal(cfgParser.Config{Bridge: *parsedBridgeCfgForDeploy.ToBridgeParser()}) + newBridgeYml, err := yaml.Marshal(*parsedBridgeCfgForDeploy.ToBridgeParser()) if err != nil { panic(fmt.Sprintf("Failed to marshal updated bridge config to yaml. Err: [%s]", err)) } @@ -118,9 +121,9 @@ func createAndAssociateTokens(wrappedFungibleThreshold *uint, bridgeDeployResult fmt.Println("====================================") } -func deployBridge(privateKey *string, accountID *string, adminKey *string, network *string, members *int, hederaPrivateKeys []hedera.PrivateKey, topicThreshold *uint, parsedBridgeCfgForDeploy *parser.ExtendedBridge) bridgeSetup.DeployResult { +func deployBridge(privateKey *string, accountID *string, adminKey *string, network *string, members *int, hederaPrivateKeys []hedera.PrivateKey, treshold uint, parsedBridgeCfgForDeploy *parser.ExtendedBridge) bridgeSetup.DeployResult { printTitle("Starting Deployment of Bridge ...") - bridgeDeployResult := bridgeSetup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, topicThreshold) + bridgeDeployResult := bridgeSetup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, treshold) if bridgeDeployResult.Error != nil { panic(bridgeDeployResult.Error) } @@ -130,6 +133,17 @@ func deployBridge(privateKey *string, accountID *string, adminKey *string, netwo for index, accountId := range bridgeDeployResult.MembersAccountIDs { parsedBridgeCfgForDeploy.Networks[hederaNetworkId].Members[index] = accountId.String() } + monitored_accounts := map[string]string{} + var index_of_monitored_account int = 0 + for key, _ := range parsedBridgeCfgForDeploy.MonitoredAccounts { + monitored_accounts[key] = bridgeDeployResult.MembersAccountIDs[index_of_monitored_account].String() + index_of_monitored_account++ + } + parsedBridgeCfgForDeploy.MonitoredAccounts = monitored_accounts + parsedBridgeCfgForDeploy.TopicId = bridgeDeployResult.TopicId.String() + + // TODO: redeploy the config topic and assign the new topic id to the config + parsedBridgeCfgForDeploy.ConfigTopicId = "0.0.0" fmt.Println("====================================") return bridgeDeployResult @@ -151,6 +165,9 @@ func createAndAssociateWrappedTokens(network uint64, networkInfo *parser.Network if _, ok := tokenInfo.Networks[hederaNetworkId]; !ok { continue } + if tokenInfo.Decimals > 8 { + tokenInfo.Decimals = 8 + } fmt.Printf("Creating Hedera Wrapped Fungible Token based on info of token with address [%s] ...\n", tokenAddress) tokenId, err := wrappedFungibleCreate.WrappedFungibleToken( client, @@ -261,8 +278,8 @@ func associateToken(tokenId *hedera.TokenID, client *hedera.Client, accountId he return err } -func validateArguments(privateKey *string, accountID *string, adminKey *string, topicThreshold *uint, members *int, configPath *string, network *string) { - err := bridgeSetup.ValidateArguments(privateKey, accountID, adminKey, topicThreshold, members) +func validateArguments(privateKey *string, accountID *string, adminKey *string, members *int, configPath *string, network *string) { + err := bridgeSetup.ValidateArguments(privateKey, accountID, adminKey, members) if err != nil { panic(err) } diff --git a/scripts/bridge/setup/setup.go b/scripts/bridge/setup/setup.go index d21f1ab7..ebd506d9 100644 --- a/scripts/bridge/setup/setup.go +++ b/scripts/bridge/setup/setup.go @@ -19,7 +19,6 @@ package setup import ( "errors" "fmt" - "math" "github.com/limechain/hedera-eth-bridge-validator/scripts/client" @@ -38,10 +37,10 @@ type DeployResult struct { Error error } -func Deploy(privateKey *string, accountID *string, adminKey *string, network *string, members *int, previousPrivateKeys []hedera.PrivateKey, topicThreshold *uint) DeployResult { +func Deploy(privateKey *string, accountID *string, adminKey *string, network *string, members *int, previousPrivateKeys []hedera.PrivateKey, treshold uint) DeployResult { result := DeployResult{} - err := ValidateArguments(privateKey, accountID, adminKey, topicThreshold, members) + err := ValidateArguments(privateKey, accountID, adminKey, members) if err != nil { result.Error = err return result @@ -70,7 +69,9 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st fmt.Println("Members Private keys array:", result.MembersPrivateKeys) result.MembersPublicKeys = make([]hedera.PublicKey, 0, *members) - topicKey := hedera.KeyListWithThreshold(*topicThreshold) + + // treshold is 1 because each validator should be able to post to the gossip topic + topicKey := hedera.KeyListWithThreshold(1) for i := 0; i < *members; i++ { pubKey := result.MembersPrivateKeys[i].PublicKey() result.MembersPublicKeys = append(result.MembersPublicKeys, pubKey) @@ -102,13 +103,11 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st fmt.Printf("TopicID: %v\n", topicReceipt.TopicID) fmt.Println("--------------------------") - treshold := math.Ceil(float64(*members) * float64(0.51)) - custodialKey := hedera.KeyListWithThreshold(uint(treshold)) + custodialKey := hedera.KeyListWithThreshold(treshold) for i := 0; i < *members; i++ { custodialKey.Add(result.MembersPublicKeys[i]) } - // Creating Bridge threshold account bridgeAccount, err := hedera.NewAccountCreateTransaction(). SetKey(custodialKey). @@ -149,7 +148,7 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st return result } -func ValidateArguments(privateKey *string, accountID *string, adminKey *string, topicThreshold *uint, members *int) error { +func ValidateArguments(privateKey *string, accountID *string, adminKey *string, members *int) error { if *privateKey == "0x0" { return errors.New("private key was not provided") } @@ -159,9 +158,6 @@ func ValidateArguments(privateKey *string, accountID *string, adminKey *string, if *adminKey == "" { return errors.New("admin key not provided") } - if *topicThreshold > uint(*members) { - return errors.New("threshold can't be more than the members count") - } return nil }