diff --git a/Cargo.lock b/Cargo.lock index 8775d95797c..2a80b6648c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10718,7 +10718,7 @@ dependencies = [ [[package]] name = "tinywallet" -version = "0.28.0" +version = "0.29.0" dependencies = [ "bitcoin", "bs58", @@ -10740,7 +10740,7 @@ dependencies = [ [[package]] name = "tinywallet-bus" -version = "0.28.0" +version = "0.29.0" dependencies = [ "serde", "serde_json", @@ -10749,7 +10749,7 @@ dependencies = [ [[package]] name = "tinywallet-crypto" -version = "0.28.0" +version = "0.29.0" dependencies = [ "async-trait", "bech32 0.12.0", @@ -10765,7 +10765,7 @@ dependencies = [ [[package]] name = "tinywallet-module" -version = "0.28.0" +version = "0.29.0" dependencies = [ "async-trait", "bitcoin", @@ -10794,7 +10794,7 @@ dependencies = [ [[package]] name = "tinywallet-web3" -version = "0.28.0" +version = "0.29.0" dependencies = [ "async-trait", "base64 0.23.1", @@ -10813,7 +10813,7 @@ dependencies = [ [[package]] name = "tinywallet-x402" -version = "0.28.0" +version = "0.29.0" dependencies = [ "async-trait", "base64 0.23.1", diff --git a/crates/openhuman-app/Cargo.lock b/crates/openhuman-app/Cargo.lock index 51c40591394..22561d6808a 100644 --- a/crates/openhuman-app/Cargo.lock +++ b/crates/openhuman-app/Cargo.lock @@ -8215,7 +8215,7 @@ dependencies = [ [[package]] name = "tinysearch-bus" -version = "0.5.6" +version = "0.5.7" dependencies = [ "schemars 1.2.3", "serde", @@ -8501,7 +8501,7 @@ dependencies = [ [[package]] name = "tinywallet-bus" -version = "0.28.0" +version = "0.29.0" dependencies = [ "serde", "serde_json", diff --git a/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs b/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs index 8aff0ca9c48..a2bbe364bcc 100644 --- a/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs +++ b/crates/openhuman-core/src/modules/registry/records_docs_wallet.rs @@ -116,8 +116,9 @@ pub(crate) const TINYDOCS: ModuleRecord = ModuleRecord { /// The contract also exposes `ExportKey` for downstream hosts that must drive /// a signer locally; OpenHuman itself does not call it. /// -/// The pinned v0.26.0 release (contract 1.14) carries the native wallet, Web3, -/// and x402 bus operations, including mnemonic word-count validation. Secret-bearing +/// The pinned v0.29.0 release (contract 1.15) carries the native wallet, Web3, +/// and x402 bus operations, including mnemonic word-count validation and the +/// `NativeWalletTokenBalances` SPL token-balance read. Secret-bearing /// operations remain confidential and require both attestation and a matching /// pinned digest. pub(crate) const TINYWALLET: ModuleRecord = ModuleRecord { @@ -125,109 +126,109 @@ pub(crate) const TINYWALLET: ModuleRecord = ModuleRecord { description: "Transaction building and assembly for Bitcoin, EVM, Solana and Tron", bus_name: tinywallet_bus::names::BUS_NAME, object_path: tinywallet_bus::names::OBJECT_PATH, - version: "0.28.0", - release_url: "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.28.0", + version: "0.29.0", + release_url: "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.29.0", assets: &[ PlatformAsset { host_key: "archlinux-arm64", - archive: "tinywallet-module-0.28.0-archlinux-arm64.tar.gz", - sha256: "da90ff7b53c2a229896d5a4ab0e3121727488f37a78551b3207a9c78bc4a09a6", + archive: "tinywallet-module-0.29.0-archlinux-arm64.tar.gz", + sha256: "90d8cb352a9d6b6403549f053446139c0361d36354ca7c37e0bc0296eb544cae", library_sha256: None, }, PlatformAsset { host_key: "archlinux-x86_64", - archive: "tinywallet-module-0.28.0-archlinux-x86_64.tar.gz", - sha256: "1e80c400e50643d938e25b45aa0327de170f66f39fe65645a9d5ccb31b5f4a88", + archive: "tinywallet-module-0.29.0-archlinux-x86_64.tar.gz", + sha256: "8e9bc6e2d443807cbbb1759cb85896abbcc0d3294a0ec58007fe0c56aecb5a25", library_sha256: None, }, PlatformAsset { host_key: "fedora-43-arm64", - archive: "tinywallet-module-0.28.0-fedora-43-arm64.tar.gz", - sha256: "fb2b630ae47e64bd10a975861e647a939bfaa55b664c8f0706cd096779d62c3b", + archive: "tinywallet-module-0.29.0-fedora-43-arm64.tar.gz", + sha256: "71e8ec37af5be258c111169e441fed5f4a46d9b3934c477569ec1185ec7ceba5", library_sha256: None, }, PlatformAsset { host_key: "fedora-43-x86_64", - archive: "tinywallet-module-0.28.0-fedora-43-x86_64.tar.gz", - sha256: "84cc92b8775d26def86ad5073ed7315a50aae4b5aa7134a1cf485b923a32c38b", + archive: "tinywallet-module-0.29.0-fedora-43-x86_64.tar.gz", + sha256: "3e7438212776adbe82a54a5c48ff744cd26ee73d0dee66bce7de42b968608a16", library_sha256: None, }, PlatformAsset { host_key: "fedora-44-arm64", - archive: "tinywallet-module-0.28.0-fedora-44-arm64.tar.gz", - sha256: "14a1f4a044a7e5b246aa2df7209c31c165bf1305b38d888a540c2e438c11e202", + archive: "tinywallet-module-0.29.0-fedora-44-arm64.tar.gz", + sha256: "7612aeeca130c741b38673279268494e0cf49891dd95574e14310e64634a6840", library_sha256: None, }, PlatformAsset { host_key: "fedora-44-x86_64", - archive: "tinywallet-module-0.28.0-fedora-44-x86_64.tar.gz", - sha256: "d550966866d4b3446abef6f3b19fcf6968d914579a445c8b08fff276465b9029", + archive: "tinywallet-module-0.29.0-fedora-44-x86_64.tar.gz", + sha256: "9807227a79989d6c17be18212462751e244fb1b5f2bbe1224e0054b3f37cc188", library_sha256: None, }, PlatformAsset { host_key: "macos-15-arm64", - archive: "tinywallet-module-0.28.0-macos-15-arm64.tar.gz", - sha256: "c8c791b7464f1db2c6395f286cf63727b24bacb7606e318bb7dad5fa120387e1", + archive: "tinywallet-module-0.29.0-macos-15-arm64.tar.gz", + sha256: "228b25d3ea7869436cf009bc228dc94f8f40fcf1d7ea81c622651c14b6bbc216", library_sha256: None, }, PlatformAsset { host_key: "macos-15-x86_64", - archive: "tinywallet-module-0.28.0-macos-15-x86_64.tar.gz", - sha256: "b72c5f5b979302599b3a4f85b6783bd753c119e23ade819c0b1edf9ffd01d729", + archive: "tinywallet-module-0.29.0-macos-15-x86_64.tar.gz", + sha256: "0b173d7ebed6ce23c7224a55a32c9b9716471a054119b02869abc2add15dc391", library_sha256: None, }, PlatformAsset { host_key: "macos-26-arm64", - archive: "tinywallet-module-0.28.0-macos-26-arm64.tar.gz", - sha256: "b8d189befa3358f854346f3903187ef23b990b71d314a4a58539531c9212ca82", + archive: "tinywallet-module-0.29.0-macos-26-arm64.tar.gz", + sha256: "61ee2de3ca95cea7f8253de3e47f4da9ae42bd4ac406c65374aaf4cd22b742f3", library_sha256: None, }, PlatformAsset { host_key: "macos-26-x86_64", - archive: "tinywallet-module-0.28.0-macos-26-x86_64.tar.gz", - sha256: "9eb8990e3401b8c6d30ca08a434c64f56ff82e6bc1b6e160d27aae4d30a8c24f", + archive: "tinywallet-module-0.29.0-macos-26-x86_64.tar.gz", + sha256: "5c7593c4bb15f806a83c25dee97e26bf86a73571046d6523164885804d0c9c7d", library_sha256: None, }, PlatformAsset { host_key: "ubuntu-22.04-arm64", - archive: "tinywallet-module-0.28.0-ubuntu-22.04-arm64.tar.gz", - sha256: "c753826827230d2ebcb044eeae91f96d1f08d945f1ef37b26030ae0e0843d60c", + archive: "tinywallet-module-0.29.0-ubuntu-22.04-arm64.tar.gz", + sha256: "54085d6e1391f98fb44b86735df0f147318502153c4d3e96c5586421835cb5aa", library_sha256: None, }, PlatformAsset { host_key: "ubuntu-22.04-x86_64", - archive: "tinywallet-module-0.28.0-ubuntu-22.04-x86_64.tar.gz", - sha256: "02cec7d7e33112266b988be1bab6213b71193f7a183db8783dba941e62ef7b46", + archive: "tinywallet-module-0.29.0-ubuntu-22.04-x86_64.tar.gz", + sha256: "4d2016fac3c2001dae9ff152dad91057741aa6c031093b10fce4a4f3e1654045", library_sha256: None, }, PlatformAsset { host_key: "ubuntu-24.04-arm64", - archive: "tinywallet-module-0.28.0-ubuntu-24.04-arm64.tar.gz", - sha256: "5b8dc519829098029609e224b95b2149a71cdaad240148e33c0abac71ec5dc07", + archive: "tinywallet-module-0.29.0-ubuntu-24.04-arm64.tar.gz", + sha256: "dedb29838c947d2da479c9998a38d772de875bd914eae0d0a8b81377bb7b894c", library_sha256: None, }, PlatformAsset { host_key: "ubuntu-24.04-x86_64", - archive: "tinywallet-module-0.28.0-ubuntu-24.04-x86_64.tar.gz", - sha256: "c2bb2acd7c15b061b66d564db738aa3eac6802544fba753a6715ade541faac86", + archive: "tinywallet-module-0.29.0-ubuntu-24.04-x86_64.tar.gz", + sha256: "74036ca124938a556687ff760d83fb3ad2eebb9e91a2a9cb93873a537f8e85a3", library_sha256: None, }, PlatformAsset { host_key: "windows-11-arm64", - archive: "tinywallet-module-0.28.0-windows-11-arm64.zip", - sha256: "02598b083ce4d7e66c6d295785b5b42535861614741b2371462847760bbd2823", + archive: "tinywallet-module-0.29.0-windows-11-arm64.zip", + sha256: "5fd451a1166e64af8f5936239f22ca88deadb6ff96058e7b9295887fa8315999", library_sha256: None, }, PlatformAsset { host_key: "windows-2022-x86_64", - archive: "tinywallet-module-0.28.0-windows-2022-x86_64.zip", - sha256: "fdf15c140e0de0492fb0fde449e38e8eef0653cc7af6ebbe71c56218f5d33c17", + archive: "tinywallet-module-0.29.0-windows-2022-x86_64.zip", + sha256: "b272c66ade706b7cb3c443fbd05c549abc2ef024f044b1cdfeba19f61367db78", library_sha256: None, }, PlatformAsset { host_key: "windows-2025-x86_64", - archive: "tinywallet-module-0.28.0-windows-2025-x86_64.zip", - sha256: "a89031486e2aeb8f2f96fc314a5a291ebc4364e3b34dcdcd6a010b1a939b365e", + archive: "tinywallet-module-0.29.0-windows-2025-x86_64.zip", + sha256: "2a6b49b81af30bbe6975c7274a9c2f8cef2a3bde10a3cebae1f4c8b9c1bf5333", library_sha256: None, }, ], diff --git a/crates/openhuman-core/src/modules/registry_tests.rs b/crates/openhuman-core/src/modules/registry_tests.rs index 8ea7598ddfa..794e3ae3605 100644 --- a/crates/openhuman-core/src/modules/registry_tests.rs +++ b/crates/openhuman-core/src/modules/registry_tests.rs @@ -9,14 +9,14 @@ mod release_manifest_tests; #[test] #[cfg(feature = "web3")] -fn tinywallet_registry_matches_the_verified_v0280_release_manifest() { +fn tinywallet_registry_matches_the_verified_v0290_release_manifest() { let wallet = find("tinywallet").expect("compiled TinyWallet module"); - assert_eq!(wallet.version, "0.28.0"); + assert_eq!(wallet.version, "0.29.0"); #[cfg(feature = "web3")] - assert_eq!(tinywallet_bus::CONTRACT_VERSION, (1, 14)); + assert_eq!(tinywallet_bus::CONTRACT_VERSION, (1, 15)); assert_eq!( wallet.release_url, - "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.28.0" + "https://github.com/tinyhumansai/tinywallet/releases/tag/v0.29.0" ); let mut actual = wallet @@ -28,88 +28,88 @@ fn tinywallet_registry_matches_the_verified_v0280_release_manifest() { let mut published = [ ( "archlinux-arm64", - "tinywallet-module-0.28.0-archlinux-arm64.tar.gz", - "da90ff7b53c2a229896d5a4ab0e3121727488f37a78551b3207a9c78bc4a09a6", + "tinywallet-module-0.29.0-archlinux-arm64.tar.gz", + "90d8cb352a9d6b6403549f053446139c0361d36354ca7c37e0bc0296eb544cae", ), ( "archlinux-x86_64", - "tinywallet-module-0.28.0-archlinux-x86_64.tar.gz", - "1e80c400e50643d938e25b45aa0327de170f66f39fe65645a9d5ccb31b5f4a88", + "tinywallet-module-0.29.0-archlinux-x86_64.tar.gz", + "8e9bc6e2d443807cbbb1759cb85896abbcc0d3294a0ec58007fe0c56aecb5a25", ), ( "fedora-43-arm64", - "tinywallet-module-0.28.0-fedora-43-arm64.tar.gz", - "fb2b630ae47e64bd10a975861e647a939bfaa55b664c8f0706cd096779d62c3b", + "tinywallet-module-0.29.0-fedora-43-arm64.tar.gz", + "71e8ec37af5be258c111169e441fed5f4a46d9b3934c477569ec1185ec7ceba5", ), ( "fedora-43-x86_64", - "tinywallet-module-0.28.0-fedora-43-x86_64.tar.gz", - "84cc92b8775d26def86ad5073ed7315a50aae4b5aa7134a1cf485b923a32c38b", + "tinywallet-module-0.29.0-fedora-43-x86_64.tar.gz", + "3e7438212776adbe82a54a5c48ff744cd26ee73d0dee66bce7de42b968608a16", ), ( "fedora-44-arm64", - "tinywallet-module-0.28.0-fedora-44-arm64.tar.gz", - "14a1f4a044a7e5b246aa2df7209c31c165bf1305b38d888a540c2e438c11e202", + "tinywallet-module-0.29.0-fedora-44-arm64.tar.gz", + "7612aeeca130c741b38673279268494e0cf49891dd95574e14310e64634a6840", ), ( "fedora-44-x86_64", - "tinywallet-module-0.28.0-fedora-44-x86_64.tar.gz", - "d550966866d4b3446abef6f3b19fcf6968d914579a445c8b08fff276465b9029", + "tinywallet-module-0.29.0-fedora-44-x86_64.tar.gz", + "9807227a79989d6c17be18212462751e244fb1b5f2bbe1224e0054b3f37cc188", ), ( "macos-15-arm64", - "tinywallet-module-0.28.0-macos-15-arm64.tar.gz", - "c8c791b7464f1db2c6395f286cf63727b24bacb7606e318bb7dad5fa120387e1", + "tinywallet-module-0.29.0-macos-15-arm64.tar.gz", + "228b25d3ea7869436cf009bc228dc94f8f40fcf1d7ea81c622651c14b6bbc216", ), ( "macos-15-x86_64", - "tinywallet-module-0.28.0-macos-15-x86_64.tar.gz", - "b72c5f5b979302599b3a4f85b6783bd753c119e23ade819c0b1edf9ffd01d729", + "tinywallet-module-0.29.0-macos-15-x86_64.tar.gz", + "0b173d7ebed6ce23c7224a55a32c9b9716471a054119b02869abc2add15dc391", ), ( "macos-26-arm64", - "tinywallet-module-0.28.0-macos-26-arm64.tar.gz", - "b8d189befa3358f854346f3903187ef23b990b71d314a4a58539531c9212ca82", + "tinywallet-module-0.29.0-macos-26-arm64.tar.gz", + "61ee2de3ca95cea7f8253de3e47f4da9ae42bd4ac406c65374aaf4cd22b742f3", ), ( "macos-26-x86_64", - "tinywallet-module-0.28.0-macos-26-x86_64.tar.gz", - "9eb8990e3401b8c6d30ca08a434c64f56ff82e6bc1b6e160d27aae4d30a8c24f", + "tinywallet-module-0.29.0-macos-26-x86_64.tar.gz", + "5c7593c4bb15f806a83c25dee97e26bf86a73571046d6523164885804d0c9c7d", ), ( "ubuntu-22.04-arm64", - "tinywallet-module-0.28.0-ubuntu-22.04-arm64.tar.gz", - "c753826827230d2ebcb044eeae91f96d1f08d945f1ef37b26030ae0e0843d60c", + "tinywallet-module-0.29.0-ubuntu-22.04-arm64.tar.gz", + "54085d6e1391f98fb44b86735df0f147318502153c4d3e96c5586421835cb5aa", ), ( "ubuntu-22.04-x86_64", - "tinywallet-module-0.28.0-ubuntu-22.04-x86_64.tar.gz", - "02cec7d7e33112266b988be1bab6213b71193f7a183db8783dba941e62ef7b46", + "tinywallet-module-0.29.0-ubuntu-22.04-x86_64.tar.gz", + "4d2016fac3c2001dae9ff152dad91057741aa6c031093b10fce4a4f3e1654045", ), ( "ubuntu-24.04-arm64", - "tinywallet-module-0.28.0-ubuntu-24.04-arm64.tar.gz", - "5b8dc519829098029609e224b95b2149a71cdaad240148e33c0abac71ec5dc07", + "tinywallet-module-0.29.0-ubuntu-24.04-arm64.tar.gz", + "dedb29838c947d2da479c9998a38d772de875bd914eae0d0a8b81377bb7b894c", ), ( "ubuntu-24.04-x86_64", - "tinywallet-module-0.28.0-ubuntu-24.04-x86_64.tar.gz", - "c2bb2acd7c15b061b66d564db738aa3eac6802544fba753a6715ade541faac86", + "tinywallet-module-0.29.0-ubuntu-24.04-x86_64.tar.gz", + "74036ca124938a556687ff760d83fb3ad2eebb9e91a2a9cb93873a537f8e85a3", ), ( "windows-11-arm64", - "tinywallet-module-0.28.0-windows-11-arm64.zip", - "02598b083ce4d7e66c6d295785b5b42535861614741b2371462847760bbd2823", + "tinywallet-module-0.29.0-windows-11-arm64.zip", + "5fd451a1166e64af8f5936239f22ca88deadb6ff96058e7b9295887fa8315999", ), ( "windows-2022-x86_64", - "tinywallet-module-0.28.0-windows-2022-x86_64.zip", - "fdf15c140e0de0492fb0fde449e38e8eef0653cc7af6ebbe71c56218f5d33c17", + "tinywallet-module-0.29.0-windows-2022-x86_64.zip", + "b272c66ade706b7cb3c443fbd05c549abc2ef024f044b1cdfeba19f61367db78", ), ( "windows-2025-x86_64", - "tinywallet-module-0.28.0-windows-2025-x86_64.zip", - "a89031486e2aeb8f2f96fc314a5a291ebc4364e3b34dcdcd6a010b1a939b365e", + "tinywallet-module-0.29.0-windows-2025-x86_64.zip", + "2a6b49b81af30bbe6975c7274a9c2f8cef2a3bde10a3cebae1f4c8b9c1bf5333", ), ]; actual.sort_unstable(); diff --git a/crates/openhuman-core/src/modules/wallet.rs b/crates/openhuman-core/src/modules/wallet.rs index a27f187dd3c..ad9da5490f7 100644 --- a/crates/openhuman-core/src/modules/wallet.rs +++ b/crates/openhuman-core/src/modules/wallet.rs @@ -378,93 +378,93 @@ async fn attested_proxy(config: &Config) -> Result Crypto > Wallet Balances.", + description: "Read addresses, native balances and token balances (USDC on Solana, via wallet.token_balances), prepare/confirm/execute native + token transfers (ERC20/SPL/TRC20/BEP20), and inspect transactions (status, receipt, lookup) across the connected wallet (EVM, BTC, Solana, Tron). Quote-first; signing stays local. Agent and automated executes run inside the [wallet_policy] spend policy (asset allowlist, per-transaction, rolling-day and per-recipient weekly caps) and are recorded in a persistent ledger. Switched off by [components] wallet = false, which answers COMPONENT_DISABLED:wallet and leaves keychain material, spending limits and RPC endpoints untouched.", + how_to: "Use wallet.* RPC methods (balances, token_balances, prepare_transfer, execute_prepared, tx_status, tx_receipt, lookup_tx, policy_get, policy_update, ledger_list) via the agent or core_rpc_relay. Settings > Crypto > Wallet Balances shows native balances only; token balances come from wallet.token_balances or the agent's wallet_balances tool.", status: CapabilityStatus::Beta, privacy: LOCAL_CREDENTIALS, }, diff --git a/crates/openhuman-core/src/web3/README.md b/crates/openhuman-core/src/web3/README.md index 9f70ade29f3..ffee120db39 100644 --- a/crates/openhuman-core/src/web3/README.md +++ b/crates/openhuman-core/src/web3/README.md @@ -91,7 +91,7 @@ Namespace names are wire contracts. | `web3_swap` | `quote`, `execute`, `routes` | | `web3_bridge` | `quote`, `execute` | | `web3_dapp` | `call`, `execute` | -| [`wallet`](./wallet/README.md) | `setup`, `status`, `reveal_recovery_phrase`, `balances`, `chain_status`, `network_defaults`, `supported_assets`, `encode_erc20_transfer`, `prepare_transfer`, `execute_prepared`, `tx_status`, `tx_receipt`, `lookup_tx`, `policy_get`, `policy_update`, `ledger_list` | +| [`wallet`](./wallet/README.md) | `setup`, `status`, `reveal_recovery_phrase`, `balances`, `token_balances`, `chain_status`, `network_defaults`, `supported_assets`, `encode_erc20_transfer`, `prepare_transfer`, `execute_prepared`, `tx_status`, `tx_receipt`, `lookup_tx`, `policy_get`, `policy_update`, `ledger_list` | | [`x402`](./x402/README.md) | `get_summary`, `list_payments`, `update_budget` | The existing Wallet/Web3/x402 agent declarations come from `tinywallet-bus`; diff --git a/crates/openhuman-core/src/web3/wallet/README.md b/crates/openhuman-core/src/web3/wallet/README.md index a907da3c19c..14bde8cd955 100644 --- a/crates/openhuman-core/src/web3/wallet/README.md +++ b/crates/openhuman-core/src/web3/wallet/README.md @@ -42,7 +42,7 @@ changing the facade. | Function | Purpose | | --- | --- | | `status`, `setup`, `reveal_recovery_phrase` | Onboarding, public account metadata, encrypted phrase custody, and explicit reveal. | -| `balances`, `chain_status`, `network_defaults`, `supported_assets` | Read module-owned provider and network data. | +| `balances`, `token_balances`, `chain_status`, `network_defaults`, `supported_assets` | Read module-owned provider and network data (`token_balances`: catalogued SPL tokens such as USDC, contract 1.15). | | `encode_erc20_transfer` | Request standard EVM transfer calldata from the module. | | `prepare_transfer`, `execute_prepared` | Prepare a module-owned quote, then explicitly confirm and execute it (through the spend policy, as an interactive execute). | | `policy_get`, `policy_update` | Read and persist the `[wallet_policy]` spend policy. | @@ -61,7 +61,9 @@ The six established wallet tools are declared in `tinywallet-bus` and adapted in `tools.rs`: `wallet_status`, `wallet_chain_status`, `wallet_prepare_transfer`, `wallet_tx_status`, `wallet_tx_receipt`, and `wallet_lookup_tx`. `automation_tools.rs` adds two policy-bound tools: -`wallet_balances` (the module's native balances) and `wallet_execute_prepared` +`wallet_balances` (the module's native and token balances as `{native, tokens}`, +with `tokensError` beside the native rows when only the token read fails) and +`wallet_execute_prepared` (an execute through the spend policy below). ## Spend policy and ledger diff --git a/crates/openhuman-core/src/web3/wallet/automation_tools.rs b/crates/openhuman-core/src/web3/wallet/automation_tools.rs index 2bdb2055aa9..fbb5842d770 100644 --- a/crates/openhuman-core/src/web3/wallet/automation_tools.rs +++ b/crates/openhuman-core/src/web3/wallet/automation_tools.rs @@ -45,7 +45,8 @@ impl Tool for WalletBalancesTool { } fn description(&self) -> &'static str { - "Read the wallet's live balances: one row per account and network with the asset symbol, \ + "Read the wallet's live balances: `native` (one row per account and network) and `tokens` \ + (catalogued tokens such as USDC on Solana, with their mint), each with the asset symbol, \ decimals, raw atomic amount and formatted amount. A row whose providerStatus is not \ 'ready' could not be read and shows zero." } @@ -66,15 +67,59 @@ impl Tool for WalletBalancesTool { context: Option<&dyn tinytools::ToolRunContext>, ) -> anyhow::Result { let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(context); - match super::balances(&ctx).await { - Ok(outcome) => Ok(ToolResult::success(serde_json::to_string_pretty( - &outcome.value, - )?)), - Err(error) => Ok(ToolResult::error(error)), + // A failed native read is the tool's answer on its own: return it before + // the token read, which would otherwise hold the wallet service lock + // and delay the error behind a slow token provider. + let native = match super::balances(&ctx).await { + Ok(outcome) => outcome.value, + Err(error) => { + tracing::warn!("[wallet:tool] wallet_balances native read failed"); + return balances_tool_result(Err(error), Ok(Vec::new())); + } + }; + let tokens = super::token_balances(&ctx) + .await + .map(|outcome| outcome.value); + match &tokens { + Ok(rows) => tracing::debug!( + native_rows = native.len(), + token_rows = rows.len(), + "[wallet:tool] wallet_balances read" + ), + Err(_) => tracing::warn!( + native_rows = native.len(), + "[wallet:tool] wallet_balances token read failed; returning native rows with tokensError" + ), } + balances_tool_result(Ok(native), tokens) + } +} + +/// The tool's answer for the two reads: the combined JSON on success, a tool +/// error when the native read itself failed. +pub(crate) fn balances_tool_result( + native: Result, String>, + tokens: Result, String>, +) -> anyhow::Result { + match combine_balances(native, tokens) { + Ok(value) => Ok(ToolResult::success(serde_json::to_string_pretty(&value)?)), + Err(error) => Ok(ToolResult::error(error)), } } +/// The `wallet_balances` result: native rows and token rows. A failed token +/// read does not hide the native balances; it is reported beside them. +pub(crate) fn combine_balances( + native: Result, String>, + tokens: Result, String>, +) -> Result { + let native = native?; + Ok(match tokens { + Ok(tokens) => json!({"native": native, "tokens": tokens}), + Err(error) => json!({"native": native, "tokens": [], "tokensError": error}), + }) +} + /// Execute a prepared transfer under the spend policy. #[derive(Debug, Default)] pub struct WalletExecutePreparedTool; diff --git a/crates/openhuman-core/src/web3/wallet/automation_tools_tests.rs b/crates/openhuman-core/src/web3/wallet/automation_tools_tests.rs index 0d66e281b39..7fdf721bd8c 100644 --- a/crates/openhuman-core/src/web3/wallet/automation_tools_tests.rs +++ b/crates/openhuman-core/src/web3/wallet/automation_tools_tests.rs @@ -71,3 +71,78 @@ fn balance_tool_is_a_read() { assert_eq!(tool.permission_level(), PermissionLevel::ReadOnly); assert_eq!(automation_tools().len(), 2); } + +fn token_row(raw: &str) -> super::super::TokenBalanceInfo { + super::super::TokenBalanceInfo { + chain: tinywallet_bus::wire::WalletChain::Solana, + evm_network: None, + address: "Owner".into(), + asset_symbol: "USDC".into(), + token_address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".into(), + decimals: 6, + raw: raw.into(), + formatted: "1.500000".into(), + provider_status: super::super::ProviderStatus::Ready, + } +} + +fn native_rows() -> Vec { + vec![ + super::super::BalanceInfo { + chain: tinywallet_bus::wire::WalletChain::Solana, + evm_network: None, + address: "Owner".into(), + asset_symbol: "SOL".into(), + decimals: 9, + raw: "2500000000".into(), + formatted: "2.500000000".into(), + provider_status: super::super::ProviderStatus::Ready, + }, + super::super::BalanceInfo { + chain: tinywallet_bus::wire::WalletChain::Evm, + evm_network: Some(tinywallet_bus::wire::EvmNetwork::BaseMainnet), + address: "0xOwner".into(), + asset_symbol: "ETH".into(), + decimals: 18, + raw: "0".into(), + formatted: "0".into(), + provider_status: super::super::ProviderStatus::Missing, + }, + ] +} + +fn tool_json(result: &ToolResult) -> Value { + assert!( + !result.is_error, + "unexpected tool error: {}", + result.output() + ); + serde_json::from_str(&result.output()).expect("the tool answers with JSON") +} + +#[test] +fn balances_tool_returns_native_and_token_rows_together() { + let result = balances_tool_result(Ok(native_rows()), Ok(vec![token_row("1500000")])).unwrap(); + let value = tool_json(&result); + assert_eq!(value["native"], json!(native_rows())); + assert_eq!(value["tokens"][0]["assetSymbol"], "USDC"); + assert_eq!(value["tokens"][0]["raw"], "1500000"); + assert!(value.get("tokensError").is_none()); +} + +#[test] +fn a_failed_token_read_keeps_the_native_balances_and_says_why() { + let result = balances_tool_result(Ok(native_rows()), Err("module too old".into())).unwrap(); + let value = tool_json(&result); + assert_eq!(value["native"], json!(native_rows())); + assert_eq!(value["tokens"], json!([])); + assert_eq!(value["tokensError"], "module too old"); +} + +#[test] +fn a_failed_native_read_is_a_tool_error_even_when_tokens_were_read() { + let result = + balances_tool_result(Err("not configured".into()), Ok(vec![token_row("1")])).unwrap(); + assert!(result.is_error); + assert!(result.output().contains("not configured")); +} diff --git a/crates/openhuman-core/src/web3/wallet/execution.rs b/crates/openhuman-core/src/web3/wallet/execution.rs index aa415ded2a7..dd30b712820 100644 --- a/crates/openhuman-core/src/web3/wallet/execution.rs +++ b/crates/openhuman-core/src/web3/wallet/execution.rs @@ -11,7 +11,7 @@ use tinywallet_bus::wire::{NativeWalletServiceRequest, NativeWalletTransactionRe pub use tinywallet_bus::wire::{ BalanceInfo, ChainStatus, ExecutePreparedParams, ExecutionResult, PrepareTransferParams, PreparedKind, PreparedStatus, PreparedTransaction, ProviderStatus, SupportedAsset, - TxLookupInfo, TxReceiptInfo, TxState, TxStatusInfo, + TokenBalanceInfo, TxLookupInfo, TxReceiptInfo, TxState, TxStatusInfo, }; use tinywallet_bus::wire::{EvmNetwork, WalletNetworkDefaults}; @@ -96,6 +96,26 @@ pub async fn balances(ctx: &DispatchCtx) -> Result>, St )) } +/// Live balances of the catalogued tokens (the cluster's USDC SPL mint on +/// Solana), read by the module (`NativeWalletTokenBalances`, contract 1.15). +pub async fn token_balances(ctx: &DispatchCtx) -> Result>, String> { + let config = ctx.load_config().await?; + let result = wallet_service::with_native_wallet(ctx, &config, |service| async { + wallet_module::call( + &config, + methods::NATIVE_WALLET_TOKEN_BALANCES, + NativeWalletServiceRequest { service }, + ) + .await + }) + .await + .map_err(|error| error.to_string())?; + Ok(Outcome::new( + result, + vec!["wallet token balances listed".to_string()], + )) +} + /// Validate a transfer and store a quote for it. pub async fn prepare_transfer( ctx: &DispatchCtx, diff --git a/crates/openhuman-core/src/web3/wallet/mod.rs b/crates/openhuman-core/src/web3/wallet/mod.rs index 9515299aac8..85a580ffa3e 100644 --- a/crates/openhuman-core/src/web3/wallet/mod.rs +++ b/crates/openhuman-core/src/web3/wallet/mod.rs @@ -68,9 +68,10 @@ pub use endpoints::solana_cluster; pub use execution::{ balances, chain_status, execute_prepared, execute_prepared_as, 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, - ProviderStatus, SupportedAsset, TxLookupInfo, TxReceiptInfo, TxState, TxStatusInfo, + supported_assets, token_balances, tx_receipt, tx_status, BalanceInfo, ChainStatus, + ExecutePreparedParams, ExecutionResult, PrepareTransferParams, PreparedKind, PreparedStatus, + PreparedTransaction, ProviderStatus, SupportedAsset, TokenBalanceInfo, TxLookupInfo, + TxReceiptInfo, TxState, TxStatusInfo, }; #[cfg(feature = "web3")] pub use ops::{ diff --git a/crates/openhuman-core/src/web3/wallet/rpc.rs b/crates/openhuman-core/src/web3/wallet/rpc.rs index 9bb596d9c8b..2fae57a670f 100644 --- a/crates/openhuman-core/src/web3/wallet/rpc.rs +++ b/crates/openhuman-core/src/web3/wallet/rpc.rs @@ -78,11 +78,17 @@ async fn rpc_call_to_inner( ); let client = client(); let response = client.post(url).json(&payload).send().await.map_err(|e| { - RpcCallError::Transport(format!("wallet RPC transport failed for {method}: {e}")) + RpcCallError::Transport(format!( + "wallet RPC transport failed for {method}: {}", + e.without_url() + )) })?; let status = response.status(); let raw_body = response.text().await.map_err(|e| { - RpcCallError::Transport(format!("wallet RPC read body failed for {method}: {e}")) + RpcCallError::Transport(format!( + "wallet RPC read body failed for {method}: {}", + e.without_url() + )) })?; log::debug!( "{LOG_PREFIX} jsonrpc method={method} status={status} body_len={}", @@ -118,12 +124,12 @@ pub async fn rest_get_text(url: &str) -> Result { .get(url) .send() .await - .map_err(|e| format!("wallet REST GET transport failed: {e}"))?; + .map_err(|e| format!("wallet REST GET transport failed: {}", e.without_url()))?; let status = response.status(); let body = response .text() .await - .map_err(|e| format!("wallet REST GET read body failed: {e}"))?; + .map_err(|e| format!("wallet REST GET read body failed: {}", e.without_url()))?; if !status.is_success() { return Err(format!( "wallet REST GET HTTP failure: status={status} body={body}" @@ -145,12 +151,12 @@ pub async fn rest_post_text(url: &str, body: &str, content_type: &str) -> Result .body(body.to_string()) .send() .await - .map_err(|e| format!("wallet REST POST transport failed: {e}"))?; + .map_err(|e| format!("wallet REST POST transport failed: {}", e.without_url()))?; let status = response.status(); let text = response .text() .await - .map_err(|e| format!("wallet REST POST read body failed: {e}"))?; + .map_err(|e| format!("wallet REST POST read body failed: {}", e.without_url()))?; if !status.is_success() { return Err(format!( "wallet REST POST HTTP failure: status={status} body={text}" diff --git a/crates/openhuman-core/src/web3/wallet/rpc_tests.rs b/crates/openhuman-core/src/web3/wallet/rpc_tests.rs index 19e28c2637b..473798d95c9 100644 --- a/crates/openhuman-core/src/web3/wallet/rpc_tests.rs +++ b/crates/openhuman-core/src/web3/wallet/rpc_tests.rs @@ -1,4 +1,4 @@ -use super::redact_rpc_url; +use super::{redact_rpc_url, rest_get_text, rest_post_text, rpc_call_to}; #[test] fn redact_rpc_url_strips_path_and_query() { @@ -12,3 +12,50 @@ fn redact_rpc_url_strips_path_and_query() { fn redact_rpc_url_handles_invalid_values() { assert_eq!(redact_rpc_url("not a url"), ""); } + +/// A port nothing listens on, so every request fails in transport. +fn refused_endpoint(path: &str) -> String { + let listener = std::net::TcpListener::bind("127.0.0.1:0").expect("bind"); + let port = listener.local_addr().expect("addr").port(); + drop(listener); + format!("http://127.0.0.1:{port}{path}") +} + +const KEYED_PATH: &str = "/v2/secret-path-key?api-key=secret-query-key"; + +fn assert_no_endpoint_secret(error: &str) { + assert!( + error.contains("transport failed"), + "unexpected error: {error}" + ); + assert!( + !error.contains("secret-query-key") && !error.contains("secret-path-key"), + "a transport error must not carry the endpoint URL: {error}" + ); +} + +#[tokio::test] +async fn a_json_rpc_transport_error_does_not_carry_the_endpoint_url() { + let error = rpc_call_to::( + &refused_endpoint(KEYED_PATH), + "getTokenAccountsByOwner", + serde_json::json!([]), + ) + .await + .unwrap_err(); + assert_no_endpoint_secret(&error); +} + +#[tokio::test] +async fn a_rest_transport_error_does_not_carry_the_endpoint_url() { + assert_no_endpoint_secret( + &rest_get_text(&refused_endpoint(KEYED_PATH)) + .await + .unwrap_err(), + ); + assert_no_endpoint_secret( + &rest_post_text(&refused_endpoint(KEYED_PATH), "00", "text/plain") + .await + .unwrap_err(), + ); +} diff --git a/crates/openhuman-core/src/web3/wallet/schemas.rs b/crates/openhuman-core/src/web3/wallet/schemas.rs index d5f486e95c4..f22bc1dc27c 100644 --- a/crates/openhuman-core/src/web3/wallet/schemas.rs +++ b/crates/openhuman-core/src/web3/wallet/schemas.rs @@ -85,6 +85,7 @@ pub fn all_wallet_controller_schemas() -> Vec { wallet_schemas("generate_mnemonic"), wallet_schemas("validate_mnemonic"), wallet_schemas("derive_recovery_material"), + wallet_schemas("token_balances"), wallet_schemas("policy_get"), wallet_schemas("policy_update"), wallet_schemas("ledger_list"), @@ -157,6 +158,10 @@ pub fn all_wallet_registered_controllers() -> Vec { schema: wallet_schemas("derive_recovery_material"), handler: handle_derive_recovery_material, }, + RegisteredController { + schema: wallet_schemas("token_balances"), + handler: handle_token_balances, + }, RegisteredController { schema: wallet_schemas("policy_get"), handler: handle_policy_get, @@ -428,6 +433,18 @@ pub fn wallet_schemas(function: &str) -> ControllerSchema { required: true, }], }, + "token_balances" => ControllerSchema { + namespace: "wallet", + function: "token_balances", + description: "List catalogued token balances for the wallet accounts: today the configured Solana cluster's USDC SPL mint, summed over the owner's token accounts. A row whose providerStatus is missing could not be read and shows zero.", + inputs: vec![], + outputs: vec![FieldSchema { + name: "result", + ty: TypeSchema::Json, + comment: "Array of {chain, evmNetwork?, address, assetSymbol, tokenAddress, decimals, raw, formatted, providerStatus}.", + required: true, + }], + }, "policy_get" => ControllerSchema { namespace: "wallet", function: "policy_get", @@ -635,6 +652,14 @@ fn handle_derive_recovery_material( }) } +fn handle_token_balances(ctx: DispatchCtx, _params: Map) -> ControllerFuture { + Box::pin(async move { + crate::web3::wallet::token_balances(&ctx) + .await? + .into_cli_compatible_json() + }) +} + fn handle_policy_get(ctx: DispatchCtx, _params: Map) -> ControllerFuture { Box::pin(async move { super::policy_ops::policy_get(&ctx) diff --git a/crates/openhuman-core/src/web3/wallet/schemas_tests.rs b/crates/openhuman-core/src/web3/wallet/schemas_tests.rs index 0795d82a780..f3ab812ac63 100644 --- a/crates/openhuman-core/src/web3/wallet/schemas_tests.rs +++ b/crates/openhuman-core/src/web3/wallet/schemas_tests.rs @@ -6,8 +6,8 @@ use crate::core::all::{ #[test] fn wallet_schema_wire_contracts_are_preserved() { - assert_eq!(all_wallet_controller_schemas().len(), 19); - assert_eq!(all_wallet_registered_controllers().len(), 19); + assert_eq!(all_wallet_controller_schemas().len(), 20); + assert_eq!(all_wallet_registered_controllers().len(), 20); assert_schema_controller_parity( &all_wallet_controller_schemas(), &all_wallet_registered_controllers(), diff --git a/docs/gitbooks/en/features/wallet.md b/docs/gitbooks/en/features/wallet.md index 83ed9d8b7cc..0375ccaf074 100644 --- a/docs/gitbooks/en/features/wallet.md +++ b/docs/gitbooks/en/features/wallet.md @@ -83,7 +83,7 @@ The agent reaches the wallet through eight tools: | --- | --- | | `wallet_status` | Onboarding status and account addresses. | | `wallet_chain_status` | Per-chain readiness and active RPC. | -| `wallet_balances` | Live balances per account and network. | +| `wallet_balances` | Live native and token (USDC on Solana) balances, as `{native, tokens}`. If the token read fails, `tokens` is empty and `tokensError` says why; the native rows are still returned. | | `wallet_prepare_transfer` | Build a validated, fee-estimated quote. | | `wallet_execute_prepared` | Execute a prepared quote, only within the spend policy. | | `wallet_tx_status` | Transaction lifecycle state by hash. | diff --git a/tests/json_rpc_wallet_e2e.rs b/tests/json_rpc_wallet_e2e.rs index bc5dfded4e9..09d6852c1ed 100644 --- a/tests/json_rpc_wallet_e2e.rs +++ b/tests/json_rpc_wallet_e2e.rs @@ -310,6 +310,33 @@ async fn json_rpc_wallet_execution_surface_round_trips() { ); } + // token_balances: the module reads the catalogued USDC mint for the one + // Solana account. The mock answers no SPL accounts, so the amount may be + // zero or marked missing, but the row and its shape must arrive. + let tokens = post_json_rpc( + &rpc_base, + 2104, + "openhuman.wallet_token_balances", + json!({}), + ) + .await; + let body = assert_no_jsonrpc_error(&tokens, "wallet_token_balances"); + let result = body.get("result").unwrap_or(body); + let token_rows = result.as_array().expect("token balances array"); + assert_eq!( + token_rows.len(), + 1, + "one USDC row for the Solana account: {result}" + ); + assert_eq!(token_rows[0]["chain"], "solana"); + assert_eq!(token_rows[0]["assetSymbol"], "USDC"); + assert_eq!(token_rows[0]["decimals"], 6); + let raw = token_rows[0]["raw"].as_str().expect("raw present"); + assert!( + raw.chars().all(|c| c.is_ascii_digit()), + "raw must be decimal, got: {raw}" + ); + // prepare_transfer + execute_prepared (happy path). let prep = post_json_rpc( &rpc_base, diff --git a/vendor/tinywallet b/vendor/tinywallet index 30e92e630c5..522121a4512 160000 --- a/vendor/tinywallet +++ b/vendor/tinywallet @@ -1 +1 @@ -Subproject commit 30e92e630c5130a486e0dd8bbac64330a48f3470 +Subproject commit 522121a451241691bc5f2c8f8d63928b2f0d949f