Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(wallet): route erc20 transfer encoding through the wallet module

Steven Enamakele6cd439b99d0
diff --git a/crates/openhuman-core/src/modules/wallet.rs b/crates/openhuman-core/src/modules/wallet.rs
index c57b0b669c..3e33cdeead 100644
--- a/crates/openhuman-core/src/modules/wallet.rs
+++ b/crates/openhuman-core/src/modules/wallet.rs
@@ -71,8 +71,9 @@ use serde::Serialize;
use tinywallet_bus::names::methods;
use tinywallet_bus::wire::{
DeriveMnemonicSeedRequest, DeriveMnemonicSeedResponse, DerivedAccount, ExportRequest,
- ExportedKey, GenerateMnemonicRequest, GenerateMnemonicResponse, Scheme, SecretMaterial,
- SignMessageRequest, SignRequest, Signature, SignedTransaction, TransactionSpec,
+ EncodeErc20TransferRequest, EncodeErc20TransferResponse, ExportedKey,
+ GenerateMnemonicRequest, GenerateMnemonicResponse, Scheme, SecretMaterial, SignMessageRequest,
+ SignRequest, Signature, SignedTransaction, TransactionSpec,
};
use zeroize::Zeroize;
@@ -195,6 +196,29 @@ pub async fn derive_mnemonic_seed(
result
}
+/// Encode ERC-20 transfer calldata with the module-owned ABI implementation.
+///
+/// # Errors
+///
+/// Returns [`WalletCallError`] if the module is unavailable or rejects the
+/// recipient or base-unit amount.
+pub async fn encode_erc20_transfer(
+ config: &Config,
+ to_address: &str,
+ amount_raw: &str,
+) -> Result<String, WalletCallError> {
+ let response: EncodeErc20TransferResponse = call(
+ config,
+ methods::ENCODE_ERC20_TRANSFER,
+ &EncodeErc20TransferRequest {
+ to_address: to_address.to_owned(),
+ amount_raw: amount_raw.to_owned(),
+ },
+ )
+ .await?;
+ Ok(response.calldata)
+}
+
/// Sign opaque bytes with the key derived from `secret`.
///
/// Blind: the module cannot check what the bytes mean, so
diff --git a/crates/openhuman-core/src/web3/wallet/execution.rs b/crates/openhuman-core/src/web3/wallet/execution.rs
index 40875f2785..f0bfd0167f 100644
--- a/crates/openhuman-core/src/web3/wallet/execution.rs
+++ b/crates/openhuman-core/src/web3/wallet/execution.rs
@@ -222,6 +222,14 @@ pub async fn lookup_tx(
))
}
+/// Encode ERC-20 transfer calldata in the loaded wallet module.
+pub async fn encode_erc20_transfer(to_address: &str, amount_raw: &str) -> Result<String, String> {
+ let config = config_rpc::load_config_with_timeout().await?;
+ wallet_module::encode_erc20_transfer(&config, to_address, amount_raw)
+ .await
+ .map_err(|error| error.to_string())
+}
+
/// The quotes that can still be executed. Test support and the introspection
/// harness read the engine's store through this.
pub fn prepared_quotes_for_test() -> Vec<PreparedTransaction> {
diff --git a/crates/openhuman-core/src/web3/wallet/mod.rs b/crates/openhuman-core/src/web3/wallet/mod.rs
index 1a46c38e47..5e5da14806 100644
--- a/crates/openhuman-core/src/web3/wallet/mod.rs
+++ b/crates/openhuman-core/src/web3/wallet/mod.rs
@@ -4,21 +4,19 @@
//!
//! ## Where the logic lives
//!
-//! The wallet engine — balances, the prepare/confirm/execute flow, the per-chain
-//! signing choreography and the agent tools — lives in
-//! `tinywallet_web3::crypto`. This module is the host adapter over it:
+//! The wallet engine — balances, the prepare/confirm/execute flow, signing,
+//! transaction encoding, provider interaction, and agent tools — lives in the
+//! compiled TinyWallet module. This module holds host configuration, custody,
+//! approvals, product RPC adapters, and module lifecycle:
//!
//! - [`ops`] — setup, status, recovery-phrase reveal and `secret_material`
//! (keyring, consent, credentials). Stays here: it is the host's state.
-//! - [`execution`] — the engine's operations wrapped in the controller
-//! contract's `Outcome`.
-//! - [`endpoints`] — the `OPENHUMAN_WALLET_RPC_*` / `OPENHUMAN_SOLANA_CLUSTER`
-//! environment resolution the engine's `RpcEndpoints` seam asks.
-//! - [`transport`] / [`rpc`] — the host `Transport` seam: endpoint resolution,
-//! URL redaction and error classification over the shared `reqwest` client.
+//! - [`execution`] — typed module operations adapted to product controller
+//! responses.
+//! - [`endpoints`] / [`rpc`] — host endpoint configuration and guarded,
+//! credential-aware transport callbacks.
//! - `schemas` — the controllers, with their RPC namespace strings.
-//! - The seam implementations and the process-wide engine are in
-//! [`crate::web3::seams`].
+//! - [`crate::modules::wallet_service`] owns the native module service lifetime.
//!
//! ## Compile-time gate (`web3` feature)
//!
@@ -58,7 +56,7 @@ pub(crate) mod test_support;
pub use endpoints::solana_cluster;
#[cfg(feature = "web3")]
pub use execution::{
- balances, chain_status, execute_prepared, lookup_tx,
+ balances, chain_status, encode_erc20_transfer, execute_prepared, lookup_tx,
network_defaults as wallet_network_defaults, prepare_transfer, prepared_quotes_for_test,
supported_assets, tx_receipt, tx_status, BalanceInfo, ChainStatus, ExecutePreparedParams,
ExecutionResult, PrepareTransferParams, PreparedKind, PreparedStatus, PreparedTransaction,
@@ -79,8 +77,6 @@ pub use schemas::{
all_wallet_registered_controllers, schemas, wallet_schemas,
};
#[cfg(feature = "web3")]
-pub use tinywallet_web3::crypto::abi::encode_erc20_transfer;
-#[cfg(feature = "web3")]
pub use tinywallet_bus::wire::{
EvmNetwork, RpcSource, SolanaCluster, WalletAssetDefinition, WalletNetworkDefaults,
};
diff --git a/crates/openhuman-core/src/web3/wallet/schemas.rs b/crates/openhuman-core/src/web3/wallet/schemas.rs
index 770a866b86..61c8217169 100644
--- a/crates/openhuman-core/src/web3/wallet/schemas.rs
+++ b/crates/openhuman-core/src/web3/wallet/schemas.rs
@@ -470,10 +470,10 @@ fn handle_encode_erc20_transfer(params: Map<String, Value>) -> ControllerFuture
if parsed.chain != WalletChain::Evm {
return Err("encode_erc20_transfer only supports the evm chain".to_string());
}
- serde_json::to_value(encode_erc20_transfer(
+ serde_json::to_value(super::encode_erc20_transfer(
&parsed.to_address,
&parsed.amount_raw,
- )?)
+ ).await?)
.map_err(|e| format!("failed to encode ERC20 transfer output: {e}"))
})
}