Skip to content

Commit

Permalink
Upgrade Ethers.JS version used by view-function EAs (#3456)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgard authored Oct 7, 2024
1 parent e3ae0e2 commit 62ba1ac
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 192 deletions.
6 changes: 6 additions & 0 deletions .changeset/mean-schools-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chainlink/view-function-multi-chain-adapter': minor
'@chainlink/view-function-adapter': minor
---

Upgrade ethers.js
80 changes: 78 additions & 2 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/sources/view-function-multi-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.3.2",
"ethers": "^5.4.6",
"ethers": "^6.13.2",
"tslib": "2.4.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TransportDependencies } from '@chainlink/external-adapter-framework/tra
import { AdapterResponse, makeLogger, sleep } from '@chainlink/external-adapter-framework/util'
import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription'
import { EndpointContext } from '@chainlink/external-adapter-framework/adapter'
import { ethers, utils } from 'ethers'
import { ethers } from 'ethers'
import { BaseEndpointTypes, inputParameters } from '../endpoint/function'
import { AdapterInputError } from '@chainlink/external-adapter-framework/validation/error'

Expand All @@ -13,7 +13,7 @@ export type MultiChainFunctionTransportTypes = BaseEndpointTypes
type RequestParams = typeof inputParameters.validated

export class MultiChainFunctionTransport extends SubscriptionTransport<MultiChainFunctionTransportTypes> {
providers: Record<string, ethers.providers.JsonRpcProvider> = {}
providers: Record<string, ethers.JsonRpcProvider> = {}

async initialize(
dependencies: TransportDependencies<MultiChainFunctionTransportTypes>,
Expand Down Expand Up @@ -72,11 +72,11 @@ export class MultiChainFunctionTransport extends SubscriptionTransport<MultiChai
}

if (!this.providers[networkName]) {
this.providers[networkName] = new ethers.providers.JsonRpcProvider(rpcUrl, chainId)
this.providers[networkName] = new ethers.JsonRpcProvider(rpcUrl, chainId)
}

const iface = new utils.Interface([signature])
const fnName = iface.functions[Object.keys(iface.functions)[0]].name
const iface = new ethers.Interface([signature])
const fnName = iface.getFunctionName(signature)

const encoded = iface.encodeFunctionData(fnName, [...(inputParams || [])])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`execute function endpoint should return error for invalid input 1`] = `
{
"errorMessage": "unsupported fragment (argument="value", value="symbol () view returns (string)", code=INVALID_ARGUMENT, version=abi/5.7.0)",
"errorMessage": "no matching function (argument="key", value="symbol() view returns (string)", code=INVALID_ARGUMENT, version=6.13.3)",
"statusCode": 502,
"timestamps": {
"providerDataReceivedUnixMs": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,49 @@ export const mockETHMainnetContractCallResponseSuccess = (): nock.Scope =>
encodedQueryParams: true,
})
.persist()
.post('/', { method: 'eth_chainId', params: [], id: /^\d+$/, jsonrpc: '2.0' })
.post('/', (body: any) => Array.isArray(body))
.reply(
200,
(_, request: JsonRpcPayload) => ({ jsonrpc: '2.0', id: request['id'], result: '0x1' }),
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
.persist()
.post('/', {
method: 'eth_call',
params: [{ to: '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c', data: '0x50d25bcd' }, 'latest'],
id: /^\d+$/,
jsonrpc: '2.0',
})
.reply(
200,
(_, request: JsonRpcPayload) => ({
jsonrpc: '2.0',
id: request['id'],
result: '0x000000000000000000000000000000000000000000000000000000005ad789f8',
}),
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
.persist()
.post('/', {
method: 'eth_call',
params: [
{
to: '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c',
data: '0xb5ab58dc0000000000000000000000000000000000000000000000060000000000001df4',
},
'latest',
],
id: /^\d+$/,
jsonrpc: '2.0',
})
.reply(
200,
(_, request: JsonRpcPayload) => ({
jsonrpc: '2.0',
id: request['id'],
result: '0x000000000000000000000000000000000000000000000000000000005cf7ff3b',
}),
(uri, requestBody: any[]) => {
// Create an array of mocked responses for each batched request
return requestBody.map((request: JsonRpcPayload) => {
if (request.method === 'eth_chainId') {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x1',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data === '0x50d25bcd'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000000000005ad789f8',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data ===
'0xb5ab58dc0000000000000000000000000000000000000000000000060000000000001df4'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000000000005cf7ff3b',
}
} else {
// Default response for unsupported calls
return {
jsonrpc: '2.0',
id: request.id,
error: { code: -32601, message: 'Method not found' },
}
}
})
},
[
'Content-Type',
'application/json',
Expand All @@ -91,10 +74,38 @@ export const mockETHGoerliContractCallResponseSuccess = (): nock.Scope =>
encodedQueryParams: true,
})
.persist()
.post('/', { method: 'eth_chainId', params: [], id: /^\d+$/, jsonrpc: '2.0' })
.post('/', (body: any) => Array.isArray(body))
.reply(
200,
(_, request: JsonRpcPayload) => ({ jsonrpc: '2.0', id: request['id'], result: '0x5' }),
(uri, requestBody: any[]) => {
// Create an array of mocked responses for each batched request
return requestBody.map((request: JsonRpcPayload) => {
if (request.method === 'eth_chainId') {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x5',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x779877a7b0d9e8603169ddbd7836e478b4624789' &&
request.params[0].data === '0x50d25bcd'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000eead809f678d30f0',
}
} else {
// Default response for unsupported calls
return {
jsonrpc: '2.0',
id: request.id,
error: { code: -32601, message: 'Method not found' },
}
}
})
},
[
'Content-Type',
'application/json',
Expand All @@ -107,27 +118,3 @@ export const mockETHGoerliContractCallResponseSuccess = (): nock.Scope =>
],
)
.persist()
.post('/', {
method: 'eth_call',
params: [{ to: '0x779877a7b0d9e8603169ddbd7836e478b4624789', data: '0x50d25bcd' }, 'latest'],
id: /^\d+$/,
jsonrpc: '2.0',
})
.reply(
200,
(_, request: JsonRpcPayload) => ({
jsonrpc: '2.0',
id: request['id'],
result: '0x000000000000000000000000000000000000000000000000eead809f678d30f0',
}),
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
2 changes: 1 addition & 1 deletion packages/sources/view-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.3.2",
"ethers": "^5.4.6",
"ethers": "^6.13.2",
"tslib": "2.4.1"
}
}
Loading

0 comments on commit 62ba1ac

Please sign in to comment.