Skip to content

Commit

Permalink
Fix signer resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 committed Nov 11, 2024
1 parent 7c70809 commit 98d4030
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 58 deletions.
48 changes: 37 additions & 11 deletions zetaclient/chains/evm/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,69 @@ func (signer *Signer) WithEvmClient(client interfaces.EVMRPCClient) {

// SetZetaConnectorAddress sets the zeta connector address
func (signer *Signer) SetZetaConnectorAddress(addr ethcommon.Address) {
// noop
if (addr == ethcommon.Address{}) || signer.zetaConnectorAddress == addr {
return
}

signer.Logger().Std.Info().
Str("signer.old_zeta_connector_address", signer.zetaConnectorAddress.String()).
Str("signer.new_zeta_connector_address", addr.String()).
Msg("Updated zeta connector address")

signer.Lock()
defer signer.Unlock()
signer.zetaConnectorAddress = addr
signer.Unlock()
}

// SetERC20CustodyAddress sets the erc20 custody address
func (signer *Signer) SetERC20CustodyAddress(addr ethcommon.Address) {
// noop
if (addr == ethcommon.Address{}) || signer.er20CustodyAddress == addr {
return
}

signer.Logger().Std.Info().
Str("signer.old_erc20_custody_address", signer.er20CustodyAddress.String()).
Str("signer.new_erc20_custody_address", addr.String()).
Msg("Updated erc20 custody address")

signer.Lock()
defer signer.Unlock()
signer.er20CustodyAddress = addr
signer.Unlock()
}

// SetGatewayAddress sets the gateway address
func (signer *Signer) SetGatewayAddress(addr string) {
func (signer *Signer) SetGatewayAddress(addrRaw string) {
addr := ethcommon.HexToAddress(addrRaw)

// noop
if (addr == ethcommon.Address{}) || signer.gatewayAddress == addr {
return
}

signer.Logger().Std.Info().
Str("signer.old_gateway_address", signer.gatewayAddress.String()).
Str("signer.new_gateway_address", addr.String()).
Msg("Updated gateway address")

signer.Lock()
defer signer.Unlock()
signer.gatewayAddress = ethcommon.HexToAddress(addr)
signer.gatewayAddress = addr
signer.Unlock()
}

// GetZetaConnectorAddress returns the zeta connector address
func (signer *Signer) GetZetaConnectorAddress() ethcommon.Address {
signer.Lock()
defer signer.Unlock()
return signer.zetaConnectorAddress
}

// GetERC20CustodyAddress returns the erc20 custody address
func (signer *Signer) GetERC20CustodyAddress() ethcommon.Address {
signer.Lock()
defer signer.Unlock()
return signer.er20CustodyAddress
}

// GetGatewayAddress returns the gateway address
func (signer *Signer) GetGatewayAddress() string {
signer.Lock()
defer signer.Unlock()
return signer.gatewayAddress.String()
}

Expand Down
23 changes: 17 additions & 6 deletions zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,36 @@ func (signer *Signer) prepareWhitelistTx(

// SetGatewayAddress sets the gateway address
func (signer *Signer) SetGatewayAddress(address string) {
// noop
if address == "" {
return
}

// parse gateway ID and PDA
gatewayID, pda, err := contracts.ParseGatewayIDAndPda(address)
if err != nil {
signer.Logger().Std.Error().Err(err).Msgf("cannot parse gateway address: %s", address)
signer.Logger().Std.Error().Err(err).Str("address", address).Msgf("Unable to parse gateway address")
return
}

// update gateway ID and PDA
signer.Lock()
defer signer.Unlock()
// noop
if signer.gatewayID.Equals(gatewayID) {
return
}

signer.Logger().Std.Info().
Str("signer.old_gateway_address", signer.gatewayID.String()).
Str("signer.new_gateway_address", gatewayID.String()).
Msg("Updated gateway address")

signer.Lock()
signer.gatewayID = gatewayID
signer.pda = pda
signer.Unlock()
}

// GetGatewayAddress returns the gateway address
func (signer *Signer) GetGatewayAddress() string {
signer.Lock()
defer signer.Unlock()
return signer.gatewayID.String()
}

Expand Down
7 changes: 6 additions & 1 deletion zetaclient/chains/ton/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (s *Signer) GetGatewayAddress() string {
// SetGatewayAddress sets gateway address. Has a check for noop.
func (s *Signer) SetGatewayAddress(addr string) {
// noop
if s.gateway.AccountID().ToRaw() == addr {
if addr == "" || s.gateway.AccountID().ToRaw() == addr {
return
}

Expand All @@ -288,6 +288,11 @@ func (s *Signer) SetGatewayAddress(addr string) {
return
}

s.Logger().Std.Info().
Str("signer.old_gateway_address", s.gateway.AccountID().ToRaw()).
Str("signer.new_gateway_address", acc.ToRaw()).
Msg("Updated gateway address")

s.Lock()
s.gateway = toncontracts.NewGateway(acc)
s.Unlock()
Expand Down
46 changes: 6 additions & 40 deletions zetaclient/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

sdkmath "cosmossdk.io/math"
ethcommon "github.com/ethereum/go-ethereum/common"
eth "github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/samber/lo"
Expand Down Expand Up @@ -164,47 +164,13 @@ func (oc *Orchestrator) resolveSigner(app *zctx.AppContext, chainID int64) (inte
params := chain.Params()

// update zeta connector, ERC20 custody, and gateway addresses
zetaConnectorAddress := ethcommon.HexToAddress(params.GetConnectorContractAddress())
if zetaConnectorAddress != signer.GetZetaConnectorAddress() {
signer.SetZetaConnectorAddress(zetaConnectorAddress)
oc.logger.Info().
Str("signer.connector_address", zetaConnectorAddress.String()).
Msgf("updated zeta connector address for chain %d", chainID)
}
erc20CustodyAddress := ethcommon.HexToAddress(params.GetErc20CustodyContractAddress())
if erc20CustodyAddress != signer.GetERC20CustodyAddress() {
signer.SetERC20CustodyAddress(erc20CustodyAddress)
oc.logger.Info().
Str("signer.erc20_custody", erc20CustodyAddress.String()).
Msgf("updated erc20 custody address for chain %d", chainID)
}
if params.GatewayAddress != signer.GetGatewayAddress() {
signer.SetGatewayAddress(params.GatewayAddress)
oc.logger.Info().
Str("signer.gateway_address", params.GatewayAddress).
Msgf("updated gateway address for chain %d", chainID)
}

signer.SetZetaConnectorAddress(eth.HexToAddress(params.ConnectorContractAddress))
signer.SetERC20CustodyAddress(eth.HexToAddress(params.Erc20CustodyContractAddress))
signer.SetGatewayAddress(params.GatewayAddress)
case chain.IsSolana():
params := chain.Params()

// update gateway address
if params.GatewayAddress != signer.GetGatewayAddress() {
signer.SetGatewayAddress(params.GatewayAddress)
oc.logger.Info().
Str("signer.gateway_address", params.GatewayAddress).
Msgf("updated gateway address for chain %d", chainID)
}
signer.SetGatewayAddress(chain.Params().GatewayAddress)
case chain.IsTON():
newAddress := chain.Params().GatewayAddress

if newAddress != signer.GetGatewayAddress() {
signer.SetGatewayAddress(newAddress)
oc.logger.Info().
Str("signer.new_gateway_address", newAddress).
Int64("signer.chain_id", chainID).
Msg("set gateway address")
}
signer.SetGatewayAddress(chain.Params().GatewayAddress)
}

return signer, nil
Expand Down

0 comments on commit 98d4030

Please sign in to comment.