// Copyright 2024 Prysmatic Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";

package ethereum.engine.v1;

import "proto/eth/ext/options.proto";
import "proto/engine/v1/execution_engine.proto";

option csharp_namespace = "Ethereum.Engine.V1";
option go_package = "github.com/OffchainLabs/prysm/v7/proto/engine/v1;enginev1";
option java_multiple_files = true;
option java_outer_classname = "ElectraProto";
option java_package = "org.ethereum.engine.v1";
option php_namespace = "Ethereum\\Engine\\v1";

// WithdrawalRequest is the message from the execution layer to trigger the
// withdrawal of a validator's balance to its withdrawal address new in Electra
message WithdrawalRequest {
  // The execution address receiving the funds
  bytes source_address = 1 [ (ethereum.eth.ext.ssz_size) = "20" ];

  // 48 byte BLS public key of the validator.
  bytes validator_pubkey = 2 [ (ethereum.eth.ext.ssz_size) = "48" ];

  // Deposit amount in gwei.
  uint64 amount = 3;
}

// DepositRequest is the message from the execution layer to trigger the deposit
// of a validator's balance to its balance new in Electra
message DepositRequest {
  bytes pubkey = 1 [ (ethereum.eth.ext.ssz_size) = "48" ];
  bytes withdrawal_credentials = 2 [ (ethereum.eth.ext.ssz_size) = "32" ];
  uint64 amount = 3;
  bytes signature = 4 [ (ethereum.eth.ext.ssz_size) = "96" ];
  uint64 index = 5;
}

// ConsolidationRequest is the message from the execution layer to trigger the
// consolidation of one validator to another validator.
message ConsolidationRequest {
  // Source address of account which originated the request.
  bytes source_address = 1 [ (ethereum.eth.ext.ssz_size) = "20" ];
  // Funds will be moved from this public key.
  bytes source_pubkey = 2 [ (ethereum.eth.ext.ssz_size) = "48" ];
  // Funds will be moved to this public key.
  bytes target_pubkey = 3 [ (ethereum.eth.ext.ssz_size) = "48" ];
}

// ExecutionRequests is a container that contains all the requests from the
// execution layer to be included in a block
message ExecutionRequests {
  repeated DepositRequest deposits = 1
      [ (ethereum.eth.ext.ssz_max) = "max_deposit_requests_per_payload.size" ];
  repeated WithdrawalRequest withdrawals = 2
      [ (ethereum.eth.ext.ssz_max) =
            "max_withdrawal_requests_per_payload.size" ];
  repeated ConsolidationRequest consolidations = 3
      [ (ethereum.eth.ext.ssz_max) =
            "max_consolidation_requests_per_payload.size" ];
}

// ExecutionBundleElectra is a container that builds on Payload V4 and includes
// execution requests sidecar needed post Electra
message ExecutionBundleElectra {
  ExecutionPayloadDeneb payload = 1;
  bytes value = 2;
  BlobsBundle blobs_bundle = 3;
  bool should_override_builder = 4;
  repeated bytes execution_requests = 5;
}
