{"record":{"id":"83a59d9f3254a969","repo":"nautechsystems/nautilus_trader","slug":"wrap-amount-must-be-positive","errorCode":null,"errorMessage":"Wrap amount must be positive","messagePattern":"Wrap amount must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":678,"sourceCode":"            u128::from(self.config.max_fee_per_gas_wei),\n        ))\n    }\n\n    /// Wraps native currency into the wrapped native token via a WETH `deposit()`\n    /// transaction carrying `amount_wei` of native value.\n    ///\n    /// This is an explicit operator operation; it never runs inside `submit_order`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the amount is zero, the WETH target is not a deployed ERC-20 contract,\n    /// the client is not connected, another transaction is in flight, no durable store is\n    /// configured, the WETH balance does not increase by `amount_wei`, or any RPC, policy, signing,\n    /// persistence, or broadcast step fails. A persistence failure after signing, or a failed\n    /// postcondition after finality, leaves the in-flight slot occupied.\n    pub async fn wrap(&mut self, amount_wei: U256) -> anyhow::Result<B256> {\n        if amount_wei.is_zero() {\n            anyhow::bail!(\"Wrap amount must be positive\");\n        }\n\n        self.ensure_transaction_ready(TransactionPurpose::Wrap)?;\n\n        let calldata = WETH9::depositCall {}.abi_encode();\n        let executor = self.transaction_executor()?;\n        let included = executor\n            .transact(\n                self.weth_address,\n                amount_wei,\n                Bytes::from(calldata),\n                TransactionPurpose::Wrap,\n                None,\n                TransactionAuthorization::Wrap {\n                    weth: self.weth_address,\n                },\n            )\n            .await?;","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L660-L696","documentation":"BlockchainExecutionClient::wrap converts ETH into WETH by depositing amount_wei; a zero deposit is rejected because it cannot satisfy the postcondition of increasing the WETH balance and would waste gas. The library bails early on a zero U256 amount.","triggerScenarios":"Calling client.wrap(U256::ZERO), or wrap with an amount computed to zero (e.g. balance-minus-reserve arithmetic underflowing to 0).","commonSituations":"Wrapping a computed 'excess ETH' amount that is actually zero; passing a U256 default/zero initializer by mistake; converting a Decimal human amount to wei with truncation to 0.","solutions":["Only call wrap when amount_wei > U256::zero(); skip the call otherwise","Recompute the intended wrap amount and guard against Decimal-to-U256 truncation to zero","Check the upstream calculation (e.g. excess balance logic) for underflow to zero"],"exampleFix":"// before\nclient.wrap(U256::ZERO).await?;\n// after\nif amount_wei.is_zero() {\n    return Ok(None); // nothing to wrap\n}\nlet tx_hash = client.wrap(amount_wei).await?;","handlingStrategy":"try-catch","validationCode":"if amount_wei.is_zero() {\n    // skip wrap entirely\n    return Ok(None);\n}","typeGuard":"fn is_positive_amount(a: &U256) -> bool { !a.is_zero() }","tryCatchPattern":"if amount_wei.is_zero() { return Ok(()); }\nmatch client.wrap(amount_wei).await {\n    Ok(tx_hash) => info!(\"wrap tx: {tx_hash}\"),\n    Err(e) => error!(\"wrap failed: {e}\"),\n}","preventionTips":["Guard zero amounts at the call site before wrapping","Beware Decimal-to-U256 truncation producing 0 for sub-unit amounts","Treat wrap as a no-op when the ETH excess is zero"],"tags":["validation","weth","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}