Best Python code snippet using lisa_python
main_generated_transactions_read_params_beta.py
Source:main_generated_transactions_read_params_beta.py  
...103                        cnt += 1104                    elif rejection_risk_action == VMRejectionAlertBehaviour.SINGLE_SMALLER_ALLOWED_SWAP:105                        desired_swap_amount = amount106                        for attempt in range(0, 6):107                            if attempt == 5 or amm.verify_swap(cnt, Transaction(row['datetime_timestamp'], amount, row['token_in'], row['token_out']), DEFAULT_SLIPPAGE) == TransactionStatus.SUCCESS:108                                amm.swap(cnt, Transaction(row['datetime_timestamp'], amount, row['token_in'], row['token_out'],109                                                    sequence_swap_cnt=0, desired_token_in_amount=desired_swap_amount, attempt_cnt=attempt), DEFAULT_SLIPPAGE)110                                cnt += 1111                                break112                            amount = amount * swap_decrease_factor_numerator // swap_decrease_factor_denominator113                    elif rejection_risk_action == VMRejectionAlertBehaviour.SEQUENCE_SMALLER_ALLOWED_SWAPS:114                        desired_swap_amount = amount115                        swapped_amount = 0116                        max_swaps = 5117                        max_tries = 10118                        curr_swaps = 0119                        for attempt in range(0, max_tries):120                            if swapped_amount >= desired_swap_amount or curr_swaps >= max_swaps:121                                break122                                123                            if attempt == max_tries - 1 or amm.verify_swap(cnt, Transaction(row['datetime_timestamp']+swap_timestamp_shift, amount, row['token_in'], row['token_out']), DEFAULT_SLIPPAGE) == TransactionStatus.SUCCESS:124                                amm.swap(cnt, Transaction(row['datetime_timestamp']+swap_timestamp_shift, amount, row['token_in'], row['token_out'], 125                                                    sequence_swap_cnt=curr_swaps, desired_token_in_amount=desired_swap_amount, attempt_cnt=attempt), DEFAULT_SLIPPAGE)126                                127                                if swapped_amount < desired_swap_amount and curr_swaps + 1< max_swaps:128                                    swap_timestamp_shift += timedelta(seconds=16)129                                swapped_amount += amount130                                curr_swaps += 1131                                cnt += 1132                                amount = min(amount, desired_swap_amount - swapped_amount)133                            else:134                                amount = min(amount * swap_decrease_factor_numerator // swap_decrease_factor_denominator, desired_swap_amount - swapped_amount)135                SwapTransaction.save_all(f'{BASE_DIR}/{iteration}/{subindex}/swaps.csv')136                blockchain.reset_state()137                amm.export_pool_states_to_csv(f'{BASE_DIR}/{iteration}/{subindex}/pool_before_transaction.csv', ...main_generated_transactions_read_params_savepoint.py
Source:main_generated_transactions_read_params_savepoint.py  
...84                    if row['datetime_timestamp'] - start_time <= timedelta(days=1):85                        amount = row['token_in_amount'] // 1000 86                    else:87                        amount = row['token_in_amount']88                    if vm == True and amm.verify_swap(cnt, Transaction(row['datetime_timestamp'], amount, row['token_in'], row['token_out'], row['slope'])):89                        amm.swap(cnt, Transaction(row['datetime_timestamp'], amount, row['token_in'], row['token_out'], row['slope']))90                    else:91                        retry = 1 #random.randint(0, 1)92                        if retry == 1:93                            for i in range(0, 5):94                                amount = amount * 3 // 495                            96                                if amm.verify_swap(cnt, Transaction(row['datetime_timestamp'], amount, row['token_in'], row['token_out'], row['slope'])):97                                    amm.swap(cnt, Transaction(row['datetime_timestamp'], amount, row['token_in'], row['token_out'], row['slope']))98                                    99                                    break100                    cnt += 1101                SwapTransaction.save_all(f'{BASE_DIR}/{iteration}/{subindex}/swaps.csv')102                blockchain.reset_state()103                amm.export_pool_states_to_csv(f'{BASE_DIR}/{iteration}/{subindex}/pool_before_transaction.csv', 104                                                f'{BASE_DIR}/{iteration}/{subindex}/pool_after_transaction.csv')105                logger.info("Start normalizing...")106                normalize_csv(f'{BASE_DIR}/{iteration}/{subindex}/swaps.csv', ['token_in_amount', 'token_out_amount', 'token_out_amount_min', 'system_fee', 'oracle_amount_out', 'oracle_price'], f'{BASE_DIR}/{iteration}/{subindex}/swaps_normalized.csv')107                normalize_pool_state(f'{BASE_DIR}/{iteration}/{subindex}/pool_before_transaction.csv', f'{BASE_DIR}/{iteration}/{subindex}/pool_before_transaction_normalized.csv')108                normalize_pool_state(f'{BASE_DIR}/{iteration}/{subindex}/pool_after_transaction.csv', f'{BASE_DIR}/{iteration}/{subindex}/pool_after_transaction_normalized.csv')109                logger.info("Finished normalizing")110            iteration += 1...amm.py
Source:amm.py  
...70        blockchain.update(int(transaction.datetime_timestamp.timestamp()))71        swap_transaction = SwapTransaction(transaction, slippage, self, id)72                73        blockchain.receive_transaction(swap_transaction)74    def verify_swap(self, id, transaction, slippage):75        blockchain.update(int(transaction.datetime_timestamp.timestamp()))76        swap_transaction = SwapTransaction(transaction, slippage, self, id, save_transaction=False)77        return swap_transaction.check_execute_status(blockchain.get_curr_block_timestamp())78    79    def mint(self, amount_X, amount_Y, timestamp, id):80        blockchain.update(int(timestamp.timestamp()))81        mint_transaction = MintTransaction(amount_X, amount_Y, timestamp, self, id)82        blockchain.receive_transaction(mint_transaction)83    def burn(self, amount_X, amount_Y, timestamp, id):84        blockchain.update(int(timestamp.timestamp()))85        burn_transaction = BurnTransaction(amount_X, amount_Y, timestamp, self, id)86        blockchain.receive_transaction(burn_transaction)87    def save_pool_state(self, before_swap: bool, transaction_id: int):88        if before_swap:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
