|
| 1 | +package scenarios |
| 2 | + |
| 3 | +import ( |
| 4 | + "math/big" |
| 5 | + |
| 6 | + "github.com/ethereum/go-ethereum/common" |
| 7 | + ethtypes "github.com/ethereum/go-ethereum/core/types" |
| 8 | + |
| 9 | + "github.com/sei-protocol/sei-load/config" |
| 10 | + types2 "github.com/sei-protocol/sei-load/types" |
| 11 | +) |
| 12 | + |
| 13 | +const EVMTransferFast = "evmtransferfast" |
| 14 | + |
| 15 | +// EVMTransferFastScenario implements the TxGenerator interface for simple ETH transfers |
| 16 | +// that only involve values that are multiples of 10^12 and no tipping. |
| 17 | +type EVMTransferFastScenario struct { |
| 18 | + *ScenarioBase |
| 19 | +} |
| 20 | + |
| 21 | +// NewEVMTransferScenario creates a new ETH transfer scenario |
| 22 | +func NewEVMTransferFastScenario(cfg config.Scenario) TxGenerator { |
| 23 | + scenario := &EVMTransferFastScenario{} |
| 24 | + scenario.ScenarioBase = NewScenarioBase(scenario, cfg) |
| 25 | + return scenario |
| 26 | +} |
| 27 | + |
| 28 | +// Name returns the name of the scenario. |
| 29 | +func (s *EVMTransferFastScenario) Name() string { |
| 30 | + return EVMTransfer |
| 31 | +} |
| 32 | + |
| 33 | +// DeployScenario implements ScenarioDeployer interface - no deployment needed for ETH transfers |
| 34 | +func (s *EVMTransferFastScenario) DeployScenario(config *config.LoadConfig, deployer *types2.Account) common.Address { |
| 35 | + // No deployment needed for simple ETH transfers |
| 36 | + // Return zero address to indicate no contract deployment |
| 37 | + return common.Address{} |
| 38 | +} |
| 39 | + |
| 40 | +// AttachScenario implements ScenarioDeployer interface - no attachment needed for ETH transfers. |
| 41 | +func (s *EVMTransferFastScenario) AttachScenario(config *config.LoadConfig, address common.Address) common.Address { |
| 42 | + // No attachment needed for simple ETH transfers |
| 43 | + // Return zero address to indicate no contract deployment |
| 44 | + return common.Address{} |
| 45 | +} |
| 46 | + |
| 47 | +// CreateTransaction EVMTransferFastScenario ScenarioDeployer interface - creates ETH transfer transaction |
| 48 | +func (s *EVMTransferFastScenario) CreateTransaction(config *config.LoadConfig, scenario *types2.TxScenario) (*ethtypes.Transaction, error) { |
| 49 | + // Create transaction with value transfer |
| 50 | + tx := ðtypes.DynamicFeeTx{ |
| 51 | + Nonce: scenario.Sender.GetAndIncrementNonce(), |
| 52 | + To: &scenario.Receiver, |
| 53 | + Value: big.NewInt(1_000_000_000_000), |
| 54 | + Gas: 21000, // Standard gas limit for ETH transfer |
| 55 | + GasTipCap: big.NewInt(0), // 2 gwei |
| 56 | + GasFeeCap: big.NewInt(200000000000), // 200 gwei |
| 57 | + Data: nil, // No data for simple transfer |
| 58 | + } |
| 59 | + |
| 60 | + if s.scenarioConfig.GasPicker != nil { |
| 61 | + var err error |
| 62 | + tx.Gas, err = s.scenarioConfig.GasPicker.GenerateGas() |
| 63 | + if err != nil { |
| 64 | + return nil, err |
| 65 | + } |
| 66 | + } |
| 67 | + if s.scenarioConfig.GasTipCapPicker != nil { |
| 68 | + gasTipCap, err := s.scenarioConfig.GasTipCapPicker.GenerateGas() |
| 69 | + if err != nil { |
| 70 | + return nil, err |
| 71 | + } |
| 72 | + tx.GasTipCap = big.NewInt(int64(gasTipCap)) |
| 73 | + } |
| 74 | + if s.scenarioConfig.GasFeeCapPicker != nil { |
| 75 | + gasFeeCap, err := s.scenarioConfig.GasFeeCapPicker.GenerateGas() |
| 76 | + if err != nil { |
| 77 | + return nil, err |
| 78 | + } |
| 79 | + tx.GasFeeCap = big.NewInt(int64(gasFeeCap)) |
| 80 | + } |
| 81 | + |
| 82 | + // Sign the transaction |
| 83 | + signer := ethtypes.NewCancunSigner(config.GetChainID()) |
| 84 | + signedTx, err := ethtypes.SignTx(ethtypes.NewTx(tx), signer, scenario.Sender.PrivKey) |
| 85 | + if err != nil { |
| 86 | + return nil, err |
| 87 | + } |
| 88 | + |
| 89 | + return signedTx, nil |
| 90 | +} |
0 commit comments