Skip to content

Commit

Permalink
Release: Slashing (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Jan 8, 2025
1 parent 2941257 commit d82f3a5
Show file tree
Hide file tree
Showing 11 changed files with 1,958 additions and 81 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ node_modules
chart_releases
/snapshots/**/*.sql
/snapshots/**/*.csv

.env
*.sql
*.dump
.env
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ lint:
test:
./scripts/goTest.sh -v -p 1 -parallel 1 ./...

.PHONY: test-file
test-file:
@if [ -z "$(FILE)" ]; then \
echo "Error: FILE variable is not set."; \
echo "Usage: make test-file FILE=path/to/your_test_file.go"; \
exit 1; \
fi
./scripts/goTest.sh -v -p 1 -parallel 1 $(FILE)

.PHONY: staticcheck
staticcheck:
staticcheck ./...
Expand Down
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type ContractAddresses struct {
StrategyManager string
DelegationManager string
AvsDirectory string
AllocationManager string
}

func (c *Config) GetContractsMapForChain() *ContractAddresses {
Expand All @@ -196,6 +197,7 @@ func (c *Config) GetContractsMapForChain() *ContractAddresses {
StrategyManager: "0xf9fbf2e35d8803273e214c99bf15174139f4e67a",
DelegationManager: "0x75dfe5b44c2e530568001400d3f704bc8ae350cc",
AvsDirectory: "0x141d6995556135d4997b2ff72eb443be300353bc",
AllocationManager: "0xfdd5749e11977d60850e06bf5b13221ad95eb6b4",
}
} else if c.Chain == Chain_Holesky {
return &ContractAddresses{
Expand All @@ -204,6 +206,7 @@ func (c *Config) GetContractsMapForChain() *ContractAddresses {
StrategyManager: "0xdfb5f6ce42aaa7830e94ecfccad411bef4d4d5b6",
DelegationManager: "0xa44151489861fe9e3055d95adc98fbd462b948e7",
AvsDirectory: "0x055733000064333caddbc92763c58bf0192ffebf",
AllocationManager: "0x78469728304326cbc65f8f95fa756b0b73164462",
}
} else if c.Chain == Chain_Mainnet {
return &ContractAddresses{
Expand Down Expand Up @@ -231,6 +234,7 @@ func (c *Config) GetInterestingAddressForConfigEnv() []string {
addresses.StrategyManager,
addresses.DelegationManager,
addresses.AvsDirectory,
addresses.AllocationManager,
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/contractManager/contractManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func NewContractManager(
}
}

func (cm *ContractManager) GetContractWithImplementations(contractAddress string) ([]*contractStore.Contract, error) {
return cm.ContractStore.GetProxyContractWithImplementations(contractAddress)
}

func (cm *ContractManager) GetContractWithProxy(
contractAddress string,
blockNumber uint64,
Expand Down
13 changes: 13 additions & 0 deletions pkg/contractStore/contractStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ContractStore interface {
FindOrCreateProxyContract(blockNumber uint64, contractAddress string, proxyContractAddress string) (*ProxyContract, bool, error)
GetContractWithProxyContract(address string, atBlockNumber uint64) (*ContractsTree, error)
SetContractCheckedForProxy(address string) (*Contract, error)
GetProxyContractWithImplementations(contractAddress string) ([]*Contract, error)

InitializeCoreContracts() error
}
Expand Down Expand Up @@ -61,6 +62,18 @@ type ContractWithProxyContract struct {
ProxyContractVerified string
}

func CombineAbis(contracts []*Contract) (string, error) {
abisToCombine := make([]string, 0)

for _, contract := range contracts {
strippedContractAbi := contract.ContractAbi[1 : len(contract.ContractAbi)-1]
abisToCombine = append(abisToCombine, strippedContractAbi)
}

combinedAbi := fmt.Sprintf("[%s]", strings.Join(abisToCombine, ","))
return combinedAbi, nil
}

func (c *ContractWithProxyContract) CombineAbis() (string, error) {
if c.ProxyContractAbi == "" {
return c.ContractAbi, nil
Expand Down
35 changes: 35 additions & 0 deletions pkg/contractStore/coreContracts/preprod.json

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions pkg/contractStore/coreContracts/testnet.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions pkg/contractStore/postgresContractStore/postgresContractStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ func (s *PostgresContractStore) FindOrCreateProxyContract(
return upsertedContract, found, err
}

func (s *PostgresContractStore) GetProxyContractWithImplementations(contractAddress string) ([]*contractStore.Contract, error) {
contractAddress = strings.ToLower(contractAddress)
contracts := make([]*contractStore.Contract, 0)

query := `select
c.contract_address,
c.contract_abi,
c.bytecode_hash
from contracts as c
where c.contract_address = @contractAddress
or c.contract_address in (
select proxy_contract_address from proxy_contracts where contract_address = @contractAddress
)
`
result := s.Db.Raw(query,
sql.Named("contractAddress", contractAddress),
).Scan(&contracts)

if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
s.Logger.Sugar().Debug(fmt.Sprintf("Proxy contract not found '%s'", contractAddress))
return nil, result.Error
}
return nil, result.Error
}

return contracts, nil
}

func (s *PostgresContractStore) GetContractWithProxyContract(address string, atBlockNumber uint64) (*contractStore.ContractsTree, error) {
address = strings.ToLower(address)

Expand Down Expand Up @@ -235,6 +264,7 @@ func (s *PostgresContractStore) InitializeCoreContracts() error {
true,
)
if err != nil {
s.Logger.Sugar().Errorw("Failed to create core contract", zap.Error(err), zap.String("contractAddress", contract.ContractAddress), zap.String("contractAbi", contract.ContractAbi), zap.String("bytecodeHash", contract.BytecodeHash))
return fmt.Errorf("Failed to create core contract: %w", err)
}
if found {
Expand Down
Loading

0 comments on commit d82f3a5

Please sign in to comment.