<commit_before>import BN from 'bn.js';
import Web3 from 'web3';
import { TransactionReceipt, TransactionConfig } from 'web3-core';
import { ContractOptions } from 'web3-eth-contract';
import { AbiItem } from 'web3-utils';
import ERC20ABI from '../contracts/abi/erc-20';
import ForeignAMBABI from '../contracts/abi/foreign-amb';
import ForeignBridgeABI from '../contracts/abi/foreign-bridge-mediator';
import { getAddress } from '../contracts/addresses';
import {
  TransactionOptions,
  waitUntilTransactionMined,
  isTransactionHash,
  waitUntilBlock,
} from './utils/general-utils';

// The TokenBridge is created between 2 networks, referred to as a Native (or Home) Network and a Foreign network.
// The Native or Home network has fast and inexpensive operations. All bridge operations to collect validator confirmations are performed on this side of the bridge.
// The Foreign network can be any chain, but generally refers to the Ethereum mainnet.

export interface ITokenBridgeForeignSide {
  unlockTokens(txnHash: string): Promise<TransactionReceipt>;
  unlockTokens(
    tokenAddress: string,
    amount: string,
    txnOptions?: TransactionOptions,
    contractOptions?: ContractOptions
  ): Promise<TransactionReceipt>;
  relayTokens(txnHash: string): Promise<TransactionReceipt>;
  relayTokens(
    tokenAddress: string,
    recipientAddress: string,
    amount: string,
    txnOptions?: TransactionOptions,
    contractOptions?: ContractOptions
  ): Promise<TransactionReceipt>;
  claimBridgedTokens(txnHash: string): Promise<TransactionReceipt>;
  claimBridgedTokens(
    messageId: string,
    encodedData: string,
    signatures: string[],
    txnOptions?: TransactionOptions,
    contractOptions?: ContractOptions
  ): Promise<TransactionReceipt>;
}

// Note that as we support new CPXD tokens, we'll need to measure the gas limit
// the new tokens require for transfer which will effect this value. Ultimately
// this value reflects the gas limit that the token bridge is configured with
// for performing withdrawals.
const CLAIM_BRIDGED_TOKENS_GAS_LIMIT = 300000;

// Note:  To accommodate the fix for infura block mismatch errors (made in
// CS-2391), we are waiting one extra block for all layer 1 transactions.
export default class TokenBridgeForeignSide implements ITokenBridgeForeignSide {
  constructor(private layer1Web3: Web3) {}

  async unlockTokens(txnHash: string): Promise<TransactionReceipt>;
  async unlockTokens(
    tokenAddress: string,<commit_msg>reverting the fine tuning--flew too close to the sun (#2342)<commit_after>import BN from 'bn.js';
import Web3 from 'web3';
import { TransactionReceipt, TransactionConfig } from 'web3-core';
import { ContractOptions } from 'web3-eth-contract';
import { AbiItem } from 'web3-utils';
import ERC20ABI from '../contracts/abi/erc-20';
import ForeignAMBABI from '../contracts/abi/foreign-amb';
import ForeignBridgeABI from '../contracts/abi/foreign-bridge-mediator';
import { getAddress } from '../contracts/addresses';
import {
  TransactionOptions,
  waitUntilTransactionMined,
  isTransactionHash,
  waitUntilBlock,
} from './utils/general-utils';

// The TokenBridge is created between 2 networks, referred to as a Native (or Home) Network and a Foreign network.
// The Native or Home network has fast and inexpensive operations. All bridge operations to collect validator confirmations are performed on this side of the bridge.
// The Foreign network can be any chain, but generally refers to the Ethereum mainnet.

export interface ITokenBridgeForeignSide {
  unlockTokens(txnHash: string): Promise<TransactionReceipt>;
  unlockTokens(
    tokenAddress: string,
    amount: string,
    txnOptions?: TransactionOptions,
    contractOptions?: ContractOptions
  ): Promise<TransactionReceipt>;
  relayTokens(txnHash: string): Promise<TransactionReceipt>;
  relayTokens(
    tokenAddress: string,
    recipientAddress: string,
    amount: string,
    txnOptions?: TransactionOptions,
    contractOptions?: ContractOptions
  ): Promise<TransactionReceipt>;
  claimBridgedTokens(txnHash: string): Promise<TransactionReceipt>;
  claimBridgedTokens(
    messageId: string,
    encodedData: string,
    signatures: string[],
    txnOptions?: TransactionOptions,
    contractOptions?: ContractOptions
  ): Promise<TransactionReceipt>;
}

// Note that as we support new CPXD tokens, we'll need to measure the gas limit
// the new tokens require for transfer which will effect this value. Ultimately
// this value reflects the gas limit that the token bridge is configured with
// for performing withdrawals.
const CLAIM_BRIDGED_TOKENS_GAS_LIMIT = 350000;

// Note:  To accommodate the fix for infura block mismatch errors (made in
// CS-2391), we are waiting one extra block for all layer 1 transactions.
export default class TokenBridgeForeignSide implements ITokenBridgeForeignSide {
  constructor(private layer1Web3: Web3) {}

  async unlockTokens(txnHash: string): Promise<TransactionReceipt>;
  async unlockTokens(
    tokenAddress: string,
{'fraction_non_alphanumeric': 0.08388125124526798, 'fraction_numerical': 0.010360629607491532, 'mean_word_length': 4.933806146572104, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '9095', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1335, 'n_words': 478}