Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: slashing #167

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.1.0
v3.0.0-rc.2
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type ContractAddresses struct {
StrategyManager string
DelegationManager string
AvsDirectory string
AllocationManager string
}

func (c *Config) ChainIsOneOf(chains ...Chain) bool {
Expand All @@ -232,6 +233,7 @@ func (c *Config) GetContractsMapForChain() *ContractAddresses {
StrategyManager: "0xf9fbf2e35d8803273e214c99bf15174139f4e67a",
DelegationManager: "0x75dfe5b44c2e530568001400d3f704bc8ae350cc",
AvsDirectory: "0x141d6995556135d4997b2ff72eb443be300353bc",
AllocationManager: "0xfdd5749e11977d60850e06bf5b13221ad95eb6b4",
}
} else if c.Chain == Chain_Holesky {
return &ContractAddresses{
Expand All @@ -240,6 +242,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 @@ -267,6 +270,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.

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
Loading