This repository was archived by the owner on May 11, 2026. It is now read-only.
feat: abstract away wallet type specification with auto-detection#333
Draft
mustafa-poly wants to merge 4 commits into
Draft
feat: abstract away wallet type specification with auto-detection#333mustafa-poly wants to merge 4 commits into
mustafa-poly wants to merge 4 commits into
Conversation
Add detectWalletType() and resolveWalletConfig() functions that determine whether a funder address is a Polymarket Gnosis Safe or Polymarket Proxy wallet by making an on-chain getOwners() call. - detectWalletType: checks bytecode and calls getOwners() selector to distinguish Safe (POLY_GNOSIS_SAFE) from Proxy (POLY_PROXY) - resolveWalletConfig: higher-level helper that handles all cases: EOA (no funder), explicit signatureType, and auto-detection - Accepts either a viem PublicClient or an RPC URL string Co-authored-by: Mustafa <mustafa-poly@users.noreply.github.com>
Add ClobClientConfig interface and static ClobClient.create() async factory method that auto-detects SignatureType when a funderAddress is provided but signatureType is omitted. - ClobClientConfig: typed config object replacing positional params - ClobClient.create(): resolves wallet type via on-chain check, then constructs the client with correct signatureType and funderAddress - Fully backward compatible: existing constructor unchanged - Export new types and functions from index.ts Co-authored-by: Mustafa <mustafa-poly@users.noreply.github.com>
Show both the existing explicit API and the new ClobClient.create() factory method that auto-detects wallet type from funderAddress. Co-authored-by: Mustafa <mustafa-poly@users.noreply.github.com>
- 14 tests for detectWalletType and resolveWalletConfig - 4 tests for ClobClient.create() factory method - Tests use mocked PublicClient to avoid real RPC calls Co-authored-by: Mustafa <mustafa-poly@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds wallet type auto-detection so users no longer need to manually specify whether their wallet is a Polymarket Proxy or Gnosis Safe. Previously, creating a client with a smart-contract wallet required knowing and passing both
signatureTypeandfunderAddress:Now users can use the new
ClobClient.create()factory method which auto-detects the wallet type from an on-chain check:How It Works
The detection works by calling the Gnosis Safe
getOwners()function selector (0xa0e67e2b) on the funder address:POLY_GNOSIS_SAFE)POLY_PROXY)funderAddressor it matches the signer → EOA (no RPC call needed)This approach is robust against factory init code hash changes (which have caused issues with CREATE2 derivation in the Rust SDK).
Changes
New:
src/wallet-detection.tsdetectWalletType(funderAddress, clientOrUrl, chainId?)— low-level detectionresolveWalletConfig(signerAddress, options)— high-level resolver handling all casesWalletDetectionResulttypeModified:
src/client.tsClobClientConfiginterface — typed config object (cleaner than 13 positional params)ClobClient.create(config)— async factory method with auto-detectionModified:
src/index.tsdetectWalletType,resolveWalletConfig,WalletDetectionResult,ClobClientConfigUpdated:
examples/signatureTypes.tsNew Tests
tests/wallet-detection/wallet-detection.test.ts— 14 tests for detection logictests/client/create-factory.test.ts— 4 tests for factory methodPublicClient(no real RPC calls)Backward Compatibility
This is a purely additive change. The existing
ClobClientconstructor,SignatureTypeenum, and all current APIs remain unchanged. Users can adoptClobClient.create()at their own pace.