-
Notifications
You must be signed in to change notification settings - Fork 190
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
Adds ViemSigner
compatibility layer
#294
Conversation
EthBridger.from
to expand provider supportEthBridger.from
to expand provider support
dc5f21e
to
6b66f06
Compare
ff2c531
to
9deb273
Compare
bdbb3e4
to
a2e90fa
Compare
EthBridger.from
to expand provider supportViemSigner
compatibility layer
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Default Name.
|
f3d521e
to
1794dfb
Compare
export const getWeb3Url = (provider: Providerish) => { | ||
if (isHttpProvider(provider)) { | ||
// @ts-expect-error - private member | ||
if (provider.clientUrl) { | ||
// @ts-expect-error - private member | ||
return provider.clientUrl | ||
// @ts-expect-error - private member | ||
} else if (provider.currentProvider && provider.currentProvider.clientUrl) { | ||
// @ts-expect-error - private member | ||
return provider.currentProvider.clientUrl | ||
// @ts-expect-error - private member | ||
} else if (provider._socketPath) { | ||
// @ts-expect-error - private member | ||
return provider._socketPath | ||
} | ||
} | ||
return undefined | ||
} |
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.
what's happening here with the @ts-expect-error
?
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.
We access private fields, but they're not true private fields. We can still access them, but TS doesn't like us accessing them.
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 think we should also have unit tests for this one
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.
added unit tests 77290dd
chain: { | ||
...mainnet, | ||
id: 1337, | ||
rpcUrls: { | ||
default: { | ||
http: [config.ethUrl], | ||
}, | ||
public: { | ||
http: [config.ethUrl], | ||
}, | ||
}, | ||
}, |
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.
why wouldn't you use ethLocal
here?
const hash = await this.publicClient.sendRawTransaction({ | ||
serializedTransaction, | ||
const hash = await this.walletClient.sendTransaction({ | ||
...request, |
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.
Is this to create a copy and make sure request
is not changed?
It is viem's responsibility to ensure the function doesn't create side effects to request
, and by the look of its code we should pass request
directly
https://github.com/wevm/viem/blob/main/src/actions/wallet/sendTransaction.ts#L121
unless we are passing additional params than request
, I don't see why we should spread it
describe('Provider Utilities', () => { | ||
describe('ethers v5', () => { | ||
it('should return the URL for an actual EthersV5 provider', () => { | ||
const provider = new JsonRpcProvider('http://localhost:8545') | ||
const url = getEthersV5Url(provider) | ||
expect(url).to.be.equal('http://localhost:8545') | ||
}) | ||
|
||
it('should correctly identify an actual EthersV5 JsonRpcProvider', () => { | ||
const provider = new JsonRpcProvider('http://localhost:8545') | ||
expect(isEthersV5JsonRpcProvider(provider)).to.be.true | ||
}) | ||
|
||
it('should return false for an EthersV6 provider', () => { | ||
const provider = new JsonRpcProviderv6('http://localhost:8546') | ||
expect(isEthersV5JsonRpcProvider(provider)).to.be.false | ||
}) | ||
|
||
it('should return false for a Web3 provider', () => { | ||
const provider = new Web3.providers.HttpProvider('http://localhost:8545') | ||
expect(isEthersV5JsonRpcProvider(provider)).to.be.false | ||
}) | ||
|
||
it('should return false for a Viem PublicClient', () => { | ||
const provider = createPublicClient({ | ||
transport: http('http://localhost:8545'), | ||
}) | ||
expect(isEthersV5JsonRpcProvider(provider)).to.be.false | ||
}) | ||
}) |
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 set of description doesn't match with what's in the tests
the tests are creating different providers and testing each of them against whether they are ethers v5 provider
whereas the description says
here's an ethers v5 provider, it should return an ethers v5 provider
,
here's an ethers v5 provider, (?) should correctly identify it's a v5 provider
,
here's an ethers v5 provider, (?) should correctly identify it's not a v6 provider
,
here's an ethers v5 provider, (?) should correctly identify it's not a web3 provider
so i'd either change the tests to:
describe('Provider Utilities', () => {
describe('ethers v5', () => {
it('should return the URL for an actual EthersV5 provider', () => {
const provider = new JsonRpcProvider('http://localhost:8545')
const url = getEthersV5Url(provider)
expect(url).to.be.equal('http://localhost:8545')
})
it('should be correctly identified as an EthersV5 JsonRpcProvider', () => {
const provider = new JsonRpcProvider('http://localhost:8545')
expect(isEthersV5JsonRpcProvider(provider)).to.be.true
})
it('should not be identified as an EthersV6 provider', () => {
const provider = new JsonRpcProvider('http://localhost:8545')
expect(isEthersV6JsonRpcProvider(provider)).to.be.false
})
...
})
or
describe('Provider Utilities', () => {
describe('isEthersV5JsonRpcProvider', () => {
it('should correctly identify an EthersV5 JsonRpcProvider', () => {
const provider = new JsonRpcProvider('http://localhost:8545')
const url = getEthersV5Url(provider)
expect(url).to.be.equal('http://localhost:8545')
expect(isEthersV5JsonRpcProvider(provider)).to.be.true
})
it('should correctly identify an EthersV6 provider is not an EthersV5 provider', () => {
const provider = new JsonRpcProviderv6('http://localhost:8546')
expect(isEthersV5JsonRpcProvider(provider)).to.be.false
})
...
})
something along those lines ^
feel free to figure out what's best
ViemSigner
usingcreateViemSigner
before passing in the signer to the sdk.