-
Notifications
You must be signed in to change notification settings - Fork 111
feat(walletconnect): add WalletConnect v2 support for EVM and Cosmos #2223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@smk762 this https://github.com/KomodoPlatform/komodo-defi-framework/blob/8a96e79b4a7b44eacd403f9c9522ccbf2a29c060/mm2src/coins/eth/v2_activation.rs#L170-L172 is an API breaking change. Users and GUIs have to use the below after the PR is merged. "priv_key_policy": { "type": "ContextPrivKey" } |
…tionPolicy::public_key()`
shamardy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the huge effort @borngraced. All the below comments are either questions or things that can be done later in another PR to not delay this anymore.
| let delete_request = SessionDeleteRequest { | ||
| code: USER_REQUESTED, | ||
| message: "User Disconnected".to_owned(), | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow this to be passed in the request?
| pub(crate) const RELAY_ADDRESS: &str = "wss://relay.walletconnect.com"; | ||
| pub(crate) const PROJECT_ID: &str = "86e916bcbacee7f98225dde86b697f5b"; | ||
| pub(crate) const AUTH_TOKEN_SUB: &str = "http://127.0.0.1:3000"; | ||
| pub(crate) const AUTH_TOKEN_DURATION: Duration = Duration::from_secs(5 * 60 * 60); | ||
| pub(crate) const APP_NAME: &str = "Komodefi Framework"; | ||
| pub(crate) const APP_DESCRIPTION: &str = "WallectConnect Komodefi Framework Playground"; | ||
|
|
||
| #[inline] | ||
| pub(crate) fn generate_metadata() -> Metadata { | ||
| Metadata { | ||
| description: APP_DESCRIPTION.to_owned(), | ||
| url: AUTH_TOKEN_SUB.to_owned(), | ||
| icons: vec!["https://avatars.githubusercontent.com/u/21276113?s=200&v=4".to_owned()], | ||
| name: APP_NAME.to_owned(), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be part of the external wallet initialization request in this PR #2411
mm2src/coins/eth/wallet_connect.rs
Outdated
| wc.validate_update_active_chain_id(session_topic, &chain_id).await?; | ||
|
|
||
| let (account_str, _) = wc.get_account_and_properties_for_chain_id(session_topic, &chain_id)?; | ||
| let message = "Authenticate with Komodefi"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be part of the request instead, so whitelabels and GUIs can place their own messages. Can be done in another PR though.
| async fn wc_send_tx<'a>( | ||
| &self, | ||
| _ctx: &WalletConnectCtx, | ||
| _params: Self::Params<'a>, | ||
| ) -> Result<Self::SendTxData, Self::Error> { | ||
| todo!() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we are not using this, so not a priority to implement in this PR but this comment so that I can remember all the todos.
| Params::SessionRequest(_param) => { | ||
| // TODO: Implement when integrating KDF as a Dapp. | ||
| return MmError::err(WalletConnectError::NotImplemented); | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this PR an implementation of KDF as a Dapp? A better note would be that this in not needed for our current usecases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. As a Dapp
|
|
||
| self.validate_chain_id(&session, chain_id)?; | ||
|
|
||
| // TODO: uncomment when WalletConnect wallets start listening to chainChanged event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in another PR
| }; | ||
| }, | ||
| "accountsChanged" => { | ||
| // TODO: Handle accountsChanged event logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we need this implemented in next PRs. Will add it to the issue checklist, this should be done by disabling and enabling the coin again with a different pubkey.
* dev: feat(walletconnect): add WalletConnect v2 support for EVM and Cosmos (#2223) feat(ibc-routing-part-1): supporting entire Cosmos network for swaps (#2459) fix(test): fix HD Wallet message signing tests (#2474) improvement(builds): enable static CRT linking for MSVC builds (#2464) feat(wallet): implement HD multi-address support for message signing (#2432)
Existing docs for wallet connect suggest using Is it correct to assume the following?
|
* lr-swap-wip: (37 commits) fix custom token error name fix getting chain_id from protocol_data refactor (review): use dedicated large error cfg, add new fn to FromApiValueError, fix TODO, use experimental namespace for lr rpc, more Ticker alias feat(walletconnect): add WalletConnect v2 support for EVM and Cosmos (GLEECBTC#2223) feat(ibc-routing-part-1): supporting entire Cosmos network for swaps (GLEECBTC#2459) fix(test): fix HD Wallet message signing tests (GLEECBTC#2474) improvement(builds): enable static CRT linking for MSVC builds (GLEECBTC#2464) feat(wallet): implement HD multi-address support for message signing (GLEECBTC#2432) fix(p2pk): validate expected pubkey correctly for p2pk inputs (GLEECBTC#2408) chore(docs): update old urls referencing atomicdex or old docs pages (GLEECBTC#2428) improvement(p2p): remove hardcoded seeds (GLEECBTC#2439) fix(evm-api): find enabled erc20 token using platform ticker (GLEECBTC#2445) chore(docs): add DeepWiki badge to README (GLEECBTC#2463) chore(core): organize deps using workspace.dependencies (GLEECBTC#2449) feat(db-arch): more dbdir to address_dir replacements (GLEECBTC#2398) chore(build-artifacts): remove duplicated mm2 build artifacts (GLEECBTC#2448) feat(pubkey-banning): expirable bans (GLEECBTC#2455) fix(eth-balance-events): serialize eth address using AddrToString (GLEECBTC#2440) chore(deps): remove base58 and replace it completely with bs58 (GLEECBTC#2427) feat(tron): initial groundwork for full TRON integration (GLEECBTC#2425) ...
* dev: (30 commits) chore(core): replace hash_raw_entry with stable entry() API (GLEECBTC#2473) chore(core): adapt `MmError` and usages for compatibility with new rustc versions (GLEECBTC#2443) feat(wallet): add `delete_wallet` RPC (GLEECBTC#2497) chore(release): add changelog entries for v2.5.0-beta (GLEECBTC#2494) chore(release): bump kdf version to 2.5.0-beta (GLEECBTC#2492) feat(tests): zcoin unit test to validate dex fee (GLEECBTC#2460) fix(zcoin): correctly track unconfirmed z-coin notes (GLEECBTC#2331) improvement(orders): remove BTC specific volume from min_trading_vol logic (GLEECBTC#2483) feat(ibc-routing-part-2): supporting entire Cosmos network for swaps (GLEECBTC#2476) fix(startup): don't initialize WalletConnect during startup (GLEECBTC#2485) fix(dns): better ip resolution (GLEECBTC#2487) improvement(event-streaming): strong type streamer IDs (GLEECBTC#2441) bump timed-map to `1.4.1` (GLEECBTC#2481) improvement(RPC): unified interface for legacy and current RPC interfaces (GLEECBTC#2450) improvement(tendermint): `tendermint_tx_internal_id` helper (GLEECBTC#2438) feat(walletconnect): add WalletConnect v2 support for EVM and Cosmos (GLEECBTC#2223) feat(ibc-routing-part-1): supporting entire Cosmos network for swaps (GLEECBTC#2459) fix(test): fix HD Wallet message signing tests (GLEECBTC#2474) improvement(builds): enable static CRT linking for MSVC builds (GLEECBTC#2464) feat(wallet): implement HD multi-address support for message signing (GLEECBTC#2432) ... # Conflicts: # mm2src/coins/qrc20.rs # mm2src/mm2_main/src/lp_swap/maker_swap.rs
#1543
This PR introduces the integration of WalletConnect into the Komodo DeFi Framework (KDF), enabling secure wallet connections for Cosmos and EVM-based chains. KDF acts as the DApp(in this PR), allowing users to initiate and manage transactions securely with external wallets e.g via Metamask.
Changes included:
TendermintandEVM.TendermintandEVMhttps://specs.walletconnect.com/2.0/specs/clients/sign/
https://specs.walletconnect.com/2.0/specs/clients/core/pairing/
https://specs.walletconnect.com/2.0/specs/clients/core/crypto/
https://specs.walletconnect.com/2.0/specs/servers/relay/
https://docs.reown.com/advanced/multichain/rpc-reference/ethereum-rpc
Additional improvements include cleanup of unused dependencies, minor code refinements, and WASM compatibility
Updated deps:
Added deps:
Removed deps:
How to test using EVM coin e.g
ETH(Native && WASM)cargo run)ETHcoin (set"priv_key_policy": "wallet_connect": { "session_topic": your_session_topic" }in activation params).Note: To add more
eip155chains, modify the chains array like this:["eip155:1", "eip155:250"]New RPC Methods
New connection
method: wc_new_connection{ "method": "wc_new_connection", "userpass": "{{ _.userpass }}", "mmrpc": "2.0", "params": { "required_namespaces": { "eip155": { "chains": [ "eip155:1" ], "methods": [ "eth_sendTransaction", "eth_signTransaction", "personal_sign" ], "events": [ "accountsChanged", "chainChanged" ] }, "cosmos": { "chains": [ "cosmos:cosmoshub-4" ], "methods": [ "cosmos_signDirect", "cosmos_signAmino", "cosmos_getAccounts" ], "events": [] } } } }Get/Retrieve Walletconnect session(s)
method: wc_get_session | wc_get_sessions{ "method": "wc_get_session" | "wc_get_sessions", "userpass": "{{ _.userpass }}", "mmrpc": "2.0", "params": { "topic": "3a6327f78840427d3a428e8fbaaaaabc8c89c582bb2ff4464d3c73d8e2e5b253" } }Ping Walletconnect session
method: wc_ping_session{ "method": "wc_ping_session", "userpass": "{{ _.userpass }}", "mmrpc": "2.0", "params": { "topic": "3a6327f78840427d3a428e8fbaaaaabc8c89c582bb2ff4464d3c73d8e2e5b253" } }Delete Walletconnect session
method: wc_delete_session{ "method": "wc_delete_session", "userpass": "{{ _.userpass }}", "mmrpc": "2.0", "params": { "topic": "3a6327f78840427d3a428e8fbaaaaabc8c89c582bb2ff4464d3c73d8e2e5b253" } }Active ETH/ERC
method: enable_eth_with_tokens{ "priv_key_policy": { "wallet_connect": { "session_topic": "3a6327f78840427d3a428e8fbaaaaabc8c89c582bb2ff4464d3c73d8e2e5b253" } }, ... }Active Tendermint/Cosmos
method: enable_tendermint_with_assets{ "activation_params": { "wallet_connect": { "session_topic": "'3a6327f78840427d3a428e8fbaaaaabc8c89c582bb2ff4464d3c73d8e2e5b253" } }, ... }cc @smk762