populateTransaction(transaction) {
        return __awaiter$3(this, void 0, void 0, function* () {
            const tx = yield resolveProperties(this.checkTransaction(transaction));
            if (tx.to != null) {
                tx.to = Promise.resolve(tx.to).then((to) => __awaiter$3(this, void 0, void 0, function* () {
                    if (to == null) {
                        return null;
                    }
                    const address = yield this.resolveName(to);
                    if (address == null) {
                        logger$f.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
                    }
                    return address;
                }));
                // Prevent this error from causing an UnhandledPromiseException
                tx.to.catch((error) => { });
            }
            // Do not allow mixing pre-eip-1559 and eip-1559 properties
            const hasEip1559 = (tx.maxFeePerGas != null || tx.maxPriorityFeePerGas != null);
            if (tx.gasPrice != null && (tx.type === 2 || hasEip1559)) {
                logger$f.throwArgumentError("eip-1559 transaction do not support gasPrice", "transaction", transaction);
            }
            else if ((tx.type === 0 || tx.type === 1) && hasEip1559) {
                logger$f.throwArgumentError("pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas", "transaction", transaction);
            }
            if ((tx.type === 2 || tx.type == null) && (tx.maxFeePerGas != null && tx.maxPriorityFeePerGas != null)) {
                // Fully-formed EIP-1559 transaction (skip getFeeData)
                tx.type = 2;
            }
            else if (tx.type === 0 || tx.type === 1) {
                // Explicit Legacy or EIP-2930 transaction
                // Populate missing gasPrice
                if (tx.gasPrice == null) {
                    tx.gasPrice = this.getGasPrice();
                }
            }
            else {
                // We need to get fee data to determine things
                const feeData = yield this.getFeeData();
                if (tx.type == null) {
                    // We need to auto-detect the intended type of this transaction...
                    if (feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null) {
                        // The network supports EIP-1559!
                        // Upgrade transaction from null to eip-1559
                        tx.type = 2;
                        if (tx.gasPrice != null) {
                            // Using legacy gasPrice property on an eip-1559 network,
                            // so use gasPrice as both fee properties
                            const gasPrice = tx.gasPrice;
                            delete tx.gasPrice;
                            tx.maxFeePerGas = gasPrice;
                            tx.maxPriorityFeePerGas = gasPrice;
                        }
                        else {
                            // Populate missing fee data
                            if (tx.maxFeePerGas == null) {
                                tx.maxFeePerGas = feeData.maxFeePerGas;
                            }
                            if (tx.maxPriorityFeePerGas == null) {
                                tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
                            }
                        }
                    }
                    else if (feeData.gasPrice != null) {
                        // Network doesn't support EIP-1559...
                        // ...but they are trying to use EIP-1559 properties
                        if (hasEip1559) {
                            logger$f.throwError("network does not support EIP-1559", Logger.errors.UNSUPPORTED_OPERATION, {
                                operation: "populateTransaction"
                            });
                        }
                        // Populate missing fee data
                        if (tx.gasPrice == null) {
                            tx.gasPrice = feeData.gasPrice;
                        }
                        // Explicitly set untyped transaction to legacy
                        tx.type = 0;
                    }
                    else {
                        // getFeeData has failed us.
                        logger$f.throwError("failed to get consistent fee data", Logger.errors.UNSUPPORTED_OPERATION, {
                            operation: "signer.getFeeData"
                        });
                    }
                }
                else if (tx.type === 2) {
                    // Explicitly using EIP-1559
                    // Populate missing fee data
                    if (tx.maxFeePerGas == null) {
                        tx.maxFeePerGas = feeData.maxFeePerGas;
                    }
                    if (tx.maxPriorityFeePerGas == null) {
                        tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
                    }
                }
            }
            if (tx.nonce == null) {
                tx.nonce = this.getTransactionCount("pending");
            }
            if (tx.gasLimit == null) {
                tx.gasLimit = this.estimateGas(tx).catch((error) => {
                    if (forwardErrors.indexOf(error.code) >= 0) {
                        throw error;
                    }
                    return logger$f.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
                        error: error,
                        tx: tx
                    });
                });
            }
            if (tx.chainId == null) {
                tx.chainId = this.getChainId();
            }
            else {
                tx.chainId = Promise.all([
                    Promise.resolve(tx.chainId),
                    this.getChainId()
                ]).then((results) => {
                    if (results[1] !== 0 && results[0] !== results[1]) {
                        logger$f.throwArgumentError("chainId address mismatch", "transaction", transaction);
                    }
                    return results[0];
                });
            }
            return yield resolveProperties(tx);
        });
    }
//  - We allow gasPrice for EIP-1559 as long as it matches maxFeePerGas
We allow gasPrice for EIP-1559 as long as it matches maxFeePerGas
We allow gasPrice for EIP - 1559 as long as it matches maxFeePerGas
populateTransaction(transaction) {
        return __awaiter$3(this, void 0, void 0, function* () {
            const tx = yield resolveProperties(this.checkTransaction(transaction));
            if (tx.to != null) {
                tx.to = Promise.resolve(tx.to).then((to) => __awaiter$3(this, void 0, void 0, function* () {
                    if (to == null) {
                        return null;
                    }
                    const address = yield this.resolveName(to);
                    if (address == null) {
                        logger$f.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
                    }
                    return address;
                }));
                tx.to.catch((error) => { });
            }
            const hasEip1559 = (tx.maxFeePerGas != null || tx.maxPriorityFeePerGas != null);
            if (tx.gasPrice != null && (tx.type === 2 || hasEip1559)) {
                logger$f.throwArgumentError("eip-1559 transaction do not support gasPrice", "transaction", transaction);
            }
            else if ((tx.type === 0 || tx.type === 1) && hasEip1559) {
                logger$f.throwArgumentError("pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas", "transaction", transaction);
            }
            if ((tx.type === 2 || tx.type == null) && (tx.maxFeePerGas != null && tx.maxPriorityFeePerGas != null)) {
                tx.type = 2;
            }
            else if (tx.type === 0 || tx.type === 1) {
                if (tx.gasPrice == null) {
                    tx.gasPrice = this.getGasPrice();
                }
            }
            else {
                const feeData = yield this.getFeeData();
                if (tx.type == null) {
                    if (feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null) {
                        tx.type = 2;
                        if (tx.gasPrice != null) {
                            const gasPrice = tx.gasPrice;
                            delete tx.gasPrice;
                            tx.maxFeePerGas = gasPrice;
                            tx.maxPriorityFeePerGas = gasPrice;
                        }
                        else {
                            if (tx.maxFeePerGas == null) {
                                tx.maxFeePerGas = feeData.maxFeePerGas;
                            }
                            if (tx.maxPriorityFeePerGas == null) {
                                tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
                            }
                        }
                    }
                    else if (feeData.gasPrice != null) {
                        if (hasEip1559) {
                            logger$f.throwError("network does not support EIP-1559", Logger.errors.UNSUPPORTED_OPERATION, {
                                operation: "populateTransaction"
                            });
                        }
                        if (tx.gasPrice == null) {
                            tx.gasPrice = feeData.gasPrice;
                        }
                        tx.type = 0;
                    }
                    else {
                        logger$f.throwError("failed to get consistent fee data", Logger.errors.UNSUPPORTED_OPERATION, {
                            operation: "signer.getFeeData"
                        });
                    }
                }
                else if (tx.type === 2) {
                    if (tx.maxFeePerGas == null) {
                        tx.maxFeePerGas = feeData.maxFeePerGas;
                    }
                    if (tx.maxPriorityFeePerGas == null) {
                        tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
                    }
                }
            }
            if (tx.nonce == null) {
                tx.nonce = this.getTransactionCount("pending");
            }
            if (tx.gasLimit == null) {
                tx.gasLimit = this.estimateGas(tx).catch((error) => {
                    if (forwardErrors.indexOf(error.code) >= 0) {
                        throw error;
                    }
                    return logger$f.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
                        error: error,
                        tx: tx
                    });
                });
            }
            if (tx.chainId == null) {
                tx.chainId = this.getChainId();
            }
            else {
                tx.chainId = Promise.all([
                    Promise.resolve(tx.chainId),
                    this.getChainId()
                ]).then((results) => {
                    if (results[1] !== 0 && results[0] !== results[1]) {
                        logger$f.throwArgumentError("chainId address mismatch", "transaction", transaction);
                    }
                    return results[0];
                });
            }
            return yield resolveProperties(tx);
        });
    }
populateTransaction ( transaction ) { return __awaiter$3 ( this , void 0 , void 0 , function * ( ) { const tx = yield resolveProperties ( this . checkTransaction ( transaction ) ) ; if ( tx . to != null ) { tx . to = Promise . resolve ( tx . to ) . then ( ( to ) => __awaiter$3 ( this , void 0 , void 0 , function * ( ) { if ( to == null ) { return null ; } const address = yield this . resolveName ( to ) ; if ( address == null ) { logger$f . throwArgumentError ( "provided ENS name resolves to null" , "tx.to" , to ) ; } return address ; } ) ) ; tx . to . catch ( ( error ) => { } ) ; } const hasEip1559 = ( tx . maxFeePerGas != null || tx . maxPriorityFeePerGas != null ) ; if ( tx . gasPrice != null && ( tx . type === 2 || hasEip1559 ) ) { logger$f . throwArgumentError ( "eip-1559 transaction do not support gasPrice" , "transaction" , transaction ) ; } else if ( ( tx . type === 0 || tx . type === 1 ) && hasEip1559 ) { logger$f . throwArgumentError ( "pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas" , "transaction" , transaction ) ; } if ( ( tx . type === 2 || tx . type == null ) && ( tx . maxFeePerGas != null && tx . maxPriorityFeePerGas != null ) ) { tx . type = 2 ; } else if ( tx . type === 0 || tx . type === 1 ) { if ( tx . gasPrice == null ) { tx . gasPrice = this . getGasPrice ( ) ; } } else { const feeData = yield this . getFeeData ( ) ; if ( tx . type == null ) { if ( feeData . maxFeePerGas != null && feeData . maxPriorityFeePerGas != null ) { tx . type = 2 ; if ( tx . gasPrice != null ) { const gasPrice = tx . gasPrice ; delete tx . gasPrice ; tx . maxFeePerGas = gasPrice ; tx . maxPriorityFeePerGas = gasPrice ; } else { if ( tx . maxFeePerGas == null ) { tx . maxFeePerGas = feeData . maxFeePerGas ; } if ( tx . maxPriorityFeePerGas == null ) { tx . maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ; } } } else if ( feeData . gasPrice != null ) { if ( hasEip1559 ) { logger$f . throwError ( "network does not support EIP-1559" , Logger . errors . UNSUPPORTED_OPERATION , { operation : "populateTransaction" } ) ; } if ( tx . gasPrice == null ) { tx . gasPrice = feeData . gasPrice ; } tx . type = 0 ; } else { logger$f . throwError ( "failed to get consistent fee data" , Logger . errors . UNSUPPORTED_OPERATION , { operation : "signer.getFeeData" } ) ; } } else if ( tx . type === 2 ) { if ( tx . maxFeePerGas == null ) { tx . maxFeePerGas = feeData . maxFeePerGas ; } if ( tx . maxPriorityFeePerGas == null ) { tx . maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ; } } } if ( tx . nonce == null ) { tx . nonce = this . getTransactionCount ( "pending" ) ; } if ( tx . gasLimit == null ) { tx . gasLimit = this . estimateGas ( tx ) . catch ( ( error ) => { if ( forwardErrors . indexOf ( error . code ) >= 0 ) { throw error ; } return logger$f . throwError ( "cannot estimate gas; transaction may fail or may require manual gas limit" , Logger . errors . UNPREDICTABLE_GAS_LIMIT , { error : error , tx : tx } ) ; } ) ; } if ( tx . chainId == null ) { tx . chainId = this . getChainId ( ) ; } else { tx . chainId = Promise . all ( [ Promise . resolve ( tx . chainId ) , this . getChainId ( ) ] ) . then ( ( results ) => { if ( results [ 1 ] !== 0 && results [ 0 ] !== results [ 1 ] ) { logger$f . throwArgumentError ( "chainId address mismatch" , "transaction" , transaction ) ; } return results [ 0 ] ; } ) ; } return yield resolveProperties ( tx ) ; } ) ; }
We allow gasPrice for EIP-1559 as long as it matches maxFeePerGas
We allow gasPrice for EIP - 1559 as long as it matches maxFeePerGas
// Prevent this error from causing an UnhandledPromiseException // Do not allow mixing pre-eip-1559 and eip-1559 properties // Fully-formed EIP-1559 transaction (skip getFeeData) // Explicit Legacy or EIP-2930 transaction // Populate missing gasPrice // We need to get fee data to determine things // We need to auto-detect the intended type of this transaction... // The network supports EIP-1559! // Upgrade transaction from null to eip-1559 // Using legacy gasPrice property on an eip-1559 network, // so use gasPrice as both fee properties // Populate missing fee data // Network doesn't support EIP-1559... // ...but they are trying to use EIP-1559 properties // Populate missing fee data // Explicitly set untyped transaction to legacy // getFeeData has failed us. // Explicitly using EIP-1559 // Populate missing fee data