-
Notifications
You must be signed in to change notification settings - Fork 23
Add ethers.js adapter support #41
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b572246
feat: add ethers adapters
mo-hak 12242c5
Merge pull request #1 from mo-hak/codex/add-support-for-ethersjs-in-sdk
mo-hak 1fc6330
Merge remote-tracking branch 'origin/main' into feature/ethers-adapte…
thodges-gh 58b8ced
test(ccip-js): add ethers-adapter testnet integration variant; skip H…
thodges-gh 05d454e
Fix integration tests and skip Hedera tests
thodges-gh bbf67b0
* CCIP - JS
zeuslawyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { Provider, Signer, TypedDataField } from 'ethers' | ||
| import type {Address, Hash, Transport, WalletClient, PublicClient } from 'viem' | ||
|
|
||
| import { custom, createPublicClient, createWalletClient } from 'viem' | ||
| import { toAccount } from 'viem/accounts' | ||
|
|
||
| /** Convert an ethers provider to a viem transport. */ | ||
| export function ethersProviderToTransport(provider: Provider): Transport { | ||
| return custom({ | ||
| async request({ method, params }) { | ||
| return (provider as any).send(method, params as any) | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| /** Convert an ethers signer to a viem LocalAccount. */ | ||
| export async function ethersSignerToAccount(signer: Signer) { | ||
| return toAccount({ | ||
| address: (await signer.getAddress()) as unknown as Address, | ||
| async signMessage({ message }) { | ||
| const data = typeof message === 'string' ? message : new TextDecoder().decode(message as any) | ||
| return signer.signMessage(data) as unknown as Hash | ||
| }, | ||
| async signTransaction(txn) { | ||
| return signer.signTransaction({ | ||
| chainId: txn.chainId, | ||
| data: txn.data, | ||
| gasLimit: txn.gas, | ||
| gasPrice: txn.gasPrice, | ||
| nonce: txn.nonce, | ||
| to: txn.to, | ||
| value: txn.value, | ||
| type: txn.type === 'legacy' ? 0 : txn.type === 'eip2930' ? 1 : txn.type === 'eip1559' ? 2 : undefined, | ||
| ...(txn.type && txn.accessList ? { accessList: txn.accessList } : {}), | ||
| ...(txn.maxPriorityFeePerGas ? { maxPriorityFeePerGas: txn.maxPriorityFeePerGas } : {}), | ||
| ...(txn.maxFeePerGas ? { maxFeePerGas: txn.maxFeePerGas } : {}), | ||
| } as any) as unknown as Hash | ||
| }, | ||
| async signTypedData({ domain, types, message }) { | ||
| const { EIP712Domain: _removed, ...rest } = types as any | ||
| const signTypedData = (signer as any)._signTypedData ?? (signer as any).signTypedData | ||
| return signTypedData(domain ?? {}, rest as Record<string, TypedDataField[]>, message) as unknown as Hash | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| /** Create a viem PublicClient from an ethers provider. */ | ||
| export function ethersProviderToPublicClient(provider: Provider, chain: any): PublicClient { | ||
| return createPublicClient({ chain: chain as any, transport: ethersProviderToTransport(provider) }) as unknown as PublicClient | ||
| } | ||
|
|
||
| /** Create a viem WalletClient from an ethers signer. */ | ||
| export async function ethersSignerToWalletClient( | ||
| signer: Signer & { provider: Provider | null }, | ||
| chain: any, | ||
| ): Promise<WalletClient> { | ||
| if (!signer.provider) { | ||
| throw new Error('ethers signer must be connected to a provider') | ||
| } | ||
| return createWalletClient({ | ||
| chain: chain as any, | ||
| transport: ethersProviderToTransport(signer.provider), | ||
| account: await ethersSignerToAccount(signer), | ||
| }) as unknown as WalletClient | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Note: we will need to bump version on this before we publish
Current published version: https://www.npmjs.com/package/@chainlink/ccip-js