Skip to content

refactor(contractkit): migrate to viem-native contract interaction [2/8]#767

Open
pahor167 wants to merge 1 commit intopahor/viem-A-connect-utilsfrom
pahor/viem-B-contractkit
Open

refactor(contractkit): migrate to viem-native contract interaction [2/8]#767
pahor167 wants to merge 1 commit intopahor/viem-A-connect-utilsfrom
pahor/viem-B-contractkit

Conversation

@pahor167
Copy link
Copy Markdown
Contributor

@pahor167 pahor167 commented Apr 1, 2026

Stack

A β†’ B β†’ C β†’ D1 β†’ D2 β†’ D3 β†’ D4 β†’ D5 (CI)

Changes

  • Migrate BaseWrapper from proxySend/proxyCall to contract.write/contract.read
  • Add strongly-typed generic ABIs to all 36 wrappers (~110 any eliminated)
  • Replace web3-contract-cache.ts with contract-factory-cache.ts
  • Delete PromiEventStub.ts
  • Remove web3 from kit.ts and mini-kit.ts
  • Replace CeloTransactionObject with direct tx hash + waitForTransactionReceipt

Part of the web3 β†’ viem migration. No CI requirement on this PR.


PR-Codex overview

This PR focuses on refactoring the contractkit package to replace web3 dependencies with a new connection model. It improves type safety, updates method calls, and enhances transaction handling, aligning with the new architecture.

Detailed summary

  • Removed web3 dependency and related files.
  • Updated method signatures to use SolidityValue and other types.
  • Refactored newKitFromWeb3 to newKitFromProvider.
  • Changed transaction handling to use viemClient for receipt waiting.
  • Updated all wrappers to utilize new ABI-based contract interactions.
  • Replaced proxy methods with direct contract calls.
  • Enhanced type safety in contract methods and wrappers.
  • Updated test cases to reflect the new connection model and transaction handling.

The following files were skipped due to too many changes: packages/sdk/contractkit/src/wrappers/GoldToken.test.ts, packages/sdk/contractkit/src/wrappers/LockedGold.test.ts, packages/sdk/contractkit/src/mini-contract-cache.ts, packages/sdk/contractkit/src/kit.ts, packages/sdk/contractkit/src/wrappers/FederatedAttestations.test.ts, packages/sdk/contractkit/src/wrappers/Reserve.ts, packages/sdk/contractkit/src/wrappers/Escrow.ts, packages/sdk/contractkit/src/contract-factory-cache.ts, packages/sdk/contractkit/src/wrappers/Reserve.test.ts, packages/sdk/contractkit/src/proxy.ts, packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts, packages/sdk/contractkit/src/wrappers/MultiSig.ts, packages/sdk/contractkit/src/wrappers/EpochManager.ts, packages/sdk/contractkit/src/wrappers/Validators.test.ts, packages/sdk/contractkit/src/kit.test.ts, packages/sdk/contractkit/src/wrappers/Attestations.ts, packages/sdk/contractkit/src/wrappers/Escrow.test.ts, packages/sdk/contractkit/src/wrappers/SortedOracles.ts, packages/sdk/contractkit/src/wrappers/Governance.test.ts, packages/sdk/contractkit/src/wrappers/Accounts.test.ts, packages/sdk/contractkit/src/wrappers/LockedGold.ts, packages/sdk/contractkit/src/wrappers/EpochManager.test.ts, packages/sdk/contractkit/src/wrappers/BaseWrapper.ts, packages/sdk/contractkit/src/wrappers/Election.test.ts, packages/sdk/contractkit/src/wrappers/SortedOracles.test.ts, packages/sdk/contractkit/src/wrappers/Accounts.ts, packages/sdk/contractkit/src/wrappers/Election.ts, packages/sdk/contractkit/src/wrappers/Validators.ts, packages/sdk/contractkit/src/wrappers/Governance.ts, packages/sdk/contractkit/src/wrappers/ReleaseGold.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

- Migrate BaseWrapper from proxySend/proxyCall to contract.write/contract.read
- Add strongly-typed generic ABIs to BaseWrapper and all 36 wrappers (~110 any eliminated)
- Replace web3-contract-cache.ts with contract-factory-cache.ts
- Delete PromiEventStub.ts
- Remove web3 dependency from kit.ts and mini-kit.ts
- Replace CeloTransactionObject with direct tx hash + waitForTransactionReceipt
@pahor167 pahor167 requested a review from a team as a code owner April 1, 2026 09:07
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

⚠️ No Changeset found

Latest commit: 2d1623c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d1623cf9a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 150 to +153
if (url.endsWith('.ipc')) {
try {
const net = require('net')
web3 = new Web3(new Web3.providers.IpcProvider(url, net))
} catch (e) {
console.error('.ipc only works in environments with native net module')
}
web3 = new Web3(url)
} else if (url.toLowerCase().startsWith('http')) {
web3 = new Web3(new Web3.providers.HttpProvider(url, options))
return new SimpleIpcProvider(url, net)
} else {
web3 = new Web3(url)
return new SimpleHttpProvider(url, options)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve websocket provider support in getProviderForKit

getProviderForKit now routes every non-.ipc URL through SimpleHttpProvider, so ws:///wss:// RPC endpoints are treated as HTTP and break at runtime. The previous implementation delegated non-HTTP URLs to new Web3(url), which supported websocket providers; this change removes that path and will fail for deployments configured with websocket-only nodes.

Useful? React with πŸ‘Β / πŸ‘Ž.

Comment on lines +120 to +124
address: this.contract.address,
event: eventAbi as any,
fromBlock,
toBlock,
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Forward event filters when querying past logs

getPastEvents no longer passes options.filter (or other indexed-arg constraints) into getLogs, so callers that rely on filtered event queries will now receive unfiltered logs. That changes behavior from the previous contract.getPastEvents(event, options) path and can return incorrect results and much larger log sets for the same query.

Useful? React with πŸ‘Β / πŸ‘Ž.

Comment on lines +140 to +142
} catch {
// Event decoding may fail for proxy contracts; return empty gracefully
return []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Surface getPastEvents failures instead of returning empty logs

The blanket catch converts any RPC/decode failure into [], which makes node outages, malformed responses, and decode bugs look identical to β€œno events found.” This silently corrupts downstream logic that uses event history for state derivation, because failures are no longer observable to callers.

Useful? React with πŸ‘Β / πŸ‘Ž.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant