Skip to content

Commit

Permalink
Merge pull request #27 from Brahma-fi/ft-fix-exports
Browse files Browse the repository at this point in the history
simplify interfaces and move to types
  • Loading branch information
rahul0tripathi authored Feb 25, 2025
2 parents 2b3fbb6 + ad35b6c commit 0b43317
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
- staticcheck
- bidichk
- durationcheck
- exportloopref
- whitespace
- revive # only certain checks enabled
- nilerr # finds the code that returns nil even if it checks that the error is not nil
Expand Down
20 changes: 3 additions & 17 deletions gasestimate/gas_estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ type ethClientFactory interface {
Client(chainID int64) (*ethclient.Client, error)
}

type addressProvider interface {
GetAddress(key string) (common.Address, error)
}

type addressRegistry interface {
AddressProvider(chainID int64) (addressProvider, error)
}

type estimateGasResponse struct {
Jsonrpc string `json:"jsonrpc"`
ID int `json:"id"`
Expand Down Expand Up @@ -78,7 +70,7 @@ type estimateGasRequest struct {

type Estimation struct {
clientFactory ethClientFactory
addressRegistry addressRegistry
addressRegistry types.AddressRegistry

safeAbi *abi.ABI
accessorAbi *abi.ABI
Expand All @@ -88,7 +80,7 @@ type Estimation struct {

func NewGasEstimation(
clientFactory ethClientFactory,
addRegistry addressRegistry,
addRegistry types.AddressRegistry,

safeAbi *abi.ABI,
accessorAbi *abi.ABI,
Expand Down Expand Up @@ -196,16 +188,10 @@ func (g *Estimation) EstimateSafeGasv1_3_0(ctx context.Context, safeTxn *types.S
func (g *Estimation) EstimateSafeGasv1_4_0(_ context.Context, safeTxn *types.SafeTx) (uint64, error) {
chainID := (*big.Int)(safeTxn.ChainId).Int64()

addressProvider, err := g.addressRegistry.AddressProvider(chainID)
simAddress, err := g.addressRegistry.GetAddressByChainID(chainID, SimulateTxnAccessor)
if err != nil {
return 0, err
}

simAddress, err := addressProvider.GetAddress(SimulateTxnAccessor)
if err != nil {
return 0, err
}

safeAddress := safeTxn.Safe.Address()
//nolint:lll
// see https://github.com/safe-global/safe-contracts/blob/7a77545f288361893313af23194988731ee95261/test/accessors/SimulateTxAccessor.spec.ts#L70
Expand Down
15 changes: 5 additions & 10 deletions metadata/safe_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ var (
)

type SafeMetadataService struct {
addressRegistry addressRegistry
multiCaller multiCaller
addressRegistry types.AddressRegistry
multiCaller types.MultiCaller

safeAbi *abi.ABI
walletRegistryAbi *abi.ABI
re *regexp.Regexp
}

func NewSafeMetadataService(
addrRegistry addressRegistry,
mc multiCaller,
addrRegistry types.AddressRegistry,
mc types.MultiCaller,
) (*SafeMetadataService, error) {
walletRegistryAbi, err := abi.JSON(strings.NewReader(walletregistry.WalletregistryMetaData.ABI))
if err != nil {
Expand Down Expand Up @@ -214,12 +214,7 @@ func (s *SafeMetadataService) GetSafeMetadata(
safes []common.Address,
chainID int64,
) ([]types.Metadata, error) {
provider, err := s.addressRegistry.AddressProvider(chainID)
if err != nil {
return nil, err
}

walletRegistry, err := provider.GetAddress(WalletRegistryAddress)
walletRegistry, err := s.addressRegistry.GetAddressByChainID(chainID, WalletRegistryAddress)
if err != nil {
return nil, err
}
Expand Down
12 changes: 4 additions & 8 deletions metadata/interfaces.go → types/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package metadata
package types

import (
"context"
Expand All @@ -8,15 +8,11 @@ import (
"github.com/ethereum/go-ethereum/common"
)

type addressProvider interface {
GetAddress(key string) (common.Address, error)
type AddressRegistry interface {
GetAddressByChainID(chainID int64, key string) (common.Address, error)
}

type addressRegistry interface {
AddressProvider(chainID int64) (addressProvider, error)
}

type multiCaller interface {
type MultiCaller interface {
Aggregate3(
ctx context.Context,
calls []multicall.Multicall3Call3,
Expand Down

0 comments on commit 0b43317

Please sign in to comment.