Skip to content
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
mainfrom
cursor/clob-client-wallet-abstraction-af52
Draft

feat: abstract away wallet type specification with auto-detection#333
mustafa-poly wants to merge 4 commits into
mainfrom
cursor/clob-client-wallet-abstraction-af52

Conversation

@mustafa-poly
Copy link
Copy Markdown
Contributor

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 signatureType and funderAddress:

// Before: must know the exact wallet type
const client = new ClobClient(
    host, chainId, wallet, creds,
    SignatureType.POLY_GNOSIS_SAFE,  // how do I know this?
    safeAddress,
);

Now users can use the new ClobClient.create() factory method which auto-detects the wallet type from an on-chain check:

// After: just provide funderAddress + RPC, SDK figures out the type
const client = await ClobClient.create({
    host,
    chainId,
    signer: wallet,
    creds,
    funderAddress: "0xMyPolymarketWallet...",
    rpcUrl: "https://polygon-rpc.com",
});

How It Works

The detection works by calling the Gnosis Safe getOwners() function selector (0xa0e67e2b) on the funder address:

  • If the call returns data → it's a Gnosis Safe (POLY_GNOSIS_SAFE)
  • If the call reverts or returns empty → it's a Polymarket Proxy (POLY_PROXY)
  • If no code exists at the address → error with helpful message
  • If no funderAddress or 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.ts

  • detectWalletType(funderAddress, clientOrUrl, chainId?) — low-level detection
  • resolveWalletConfig(signerAddress, options) — high-level resolver handling all cases
  • WalletDetectionResult type

Modified: src/client.ts

  • ClobClientConfig interface — typed config object (cleaner than 13 positional params)
  • ClobClient.create(config) — async factory method with auto-detection
  • Fully backward compatible: existing constructor is unchanged

Modified: src/index.ts

  • Exports detectWalletType, resolveWalletConfig, WalletDetectionResult, ClobClientConfig

Updated: examples/signatureTypes.ts

  • Shows both the existing explicit API and the new auto-detection flow

New Tests

  • tests/wallet-detection/wallet-detection.test.ts — 14 tests for detection logic
  • tests/client/create-factory.test.ts — 4 tests for factory method
  • All tests use mocked PublicClient (no real RPC calls)

Backward Compatibility

This is a purely additive change. The existing ClobClient constructor, SignatureType enum, and all current APIs remain unchanged. Users can adopt ClobClient.create() at their own pace.

Open in Web Open in Cursor 

cursoragent and others added 4 commits March 21, 2026 16:52
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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants