-
Notifications
You must be signed in to change notification settings - Fork 68
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
Multicall CCIP-read gateway #22
+38,294
−16,287
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
f6a58af
Replace ethers-ccip-read-provider with ethers.js on client
makoto aac1828
Remove @chainlink/ethers-ccip-read-provider from contracts
makoto aed2da0
yarn lint --fix
makoto 1802de4
Add mockprovider
makoto 9043bb2
Fix failing test
makoto f9ebfc0
Merge sendRPC and callFunction into MockProvider
makoto 1e7daab
Fix lint
makoto 8772fe2
Add error class
makoto 6cf5f7f
Fix lint error
makoto c8e083a
Rename to chainName
makoto eac7fce
multicoin
makoto b48058d
Change the default chainId to 3117
makoto 20e3c42
Add litecoin to *.offchainexample.eth
makoto 5f2e3ac
Resolve conflict
makoto 3bcf20a
Remove console.log
makoto 060e025
Fix lint error
makoto 80bccfb
eth address
makoto 0de1f23
Simplify multicoin call
makoto de14b44
Remove comment
makoto 46a626f
Resolve conflicts
makoto e810b7f
Add contenthash example
makoto 34bcc03
Merge branch 'main' into multicall
makoto 72bfbb2
Change the console.log order
makoto 202a137
Upgraded ens-contracts to 0.0.12
makoto 084acbc
WIP add batchgateway and batchclient
makoto ae32ef9
Make multicoin work
makoto cd388ea
Return multiple query
makoto 0540307
Tidy up
makoto c3d1e03
Refactoring
makoto 2abac74
Add readme
makoto ecb2ea9
Update the lint error
makoto 0ce7d6f
Update readme
makoto 34864db
Fix lint error
makoto 2c86d15
Fix lint error on batch-gateway
makoto b779881
Fix lint on gateway
makoto 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 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 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 |
---|---|---|
|
@@ -7,18 +7,24 @@ | |
"author": "Nick Johnson <[email protected]>", | ||
"license": "MIT", | ||
"workspaces": [ | ||
"packages/contracts", | ||
"packages/gateway", | ||
"packages/client" | ||
"packages/batchclient", | ||
"packages/batchgateway", | ||
"packages/client", | ||
"packages/gateway" | ||
], | ||
"private": true, | ||
"scripts": { | ||
"start:gateway": "yarn workspace @ensdomains/offchain-resolver-gateway start", | ||
"start:client": "yarn workspace @ensdomains/offchain-resolver-client start", | ||
"start:batch:gateway": "yarn workspace @ensdomains/offchain-resolver-batch-gateway start", | ||
"start:batch:client": "yarn workspace @ensdomains/offchain-resolver-batch-client start", | ||
"test": "yarn workspaces run test", | ||
"lint": "yarn workspaces run lint", | ||
"build": "yarn workspaces run build", | ||
"docs": "typedoc --entryPointStrategy packages packages/server packages/ethers-ccip-read-provider", | ||
"clean": "rm -fr node_modules && yarn workspaces run clean" | ||
}, | ||
"dependencies": { | ||
"@ensdomains/ens-contracts": "^0.0.12" | ||
} | ||
} |
This file contains 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,4 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
dist |
This file contains 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Nick Johnson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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,13 @@ | ||
# ENS offchain resolution client | ||
This package implements a very simple dig-like tool for querying ENS names, with support for offchain resolution. It is intended as a way to test out your code and run the demo, rather than a production-quality tool. | ||
|
||
Most of the code in this package is boilerplate implementing ENSIP 10; once support for this is added to Ethers, this code will be a lot simpler than it is now. Please do not use this code in production! | ||
|
||
## Usage: | ||
``` | ||
$ yarn start --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 test.eth | ||
``` | ||
|
||
`--registry` is the address of the ENS registry. If you are running this on mainnet, this will be `0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e`. | ||
|
||
`--provider` can optionally be specified to supply the URL to an Ethereum web3 provider; it defaults to `http://localhost:8545/`. |
This file contains 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,62 @@ | ||
{ | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"start": "node dist/index.js", | ||
"build": "tsdx build", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why", | ||
"clean": "rm -fr node_modules dist", | ||
"test": "echo No tests" | ||
}, | ||
"peerDependencies": {}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
}, | ||
"name": "@ensdomains/offchain-resolver-batch-client", | ||
"author": "Nick Johnson", | ||
"module": "dist/client.esm.js", | ||
"size-limit": [ | ||
{ | ||
"path": "dist/client.cjs.production.min.js", | ||
"limit": "10 KB" | ||
}, | ||
{ | ||
"path": "dist/client.esm.js", | ||
"limit": "10 KB" | ||
} | ||
], | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^7.0.5", | ||
"husky": "^7.0.4", | ||
"size-limit": "^7.0.5", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.4" | ||
}, | ||
"dependencies": { | ||
"@ensdomains/address-encoder": "^0.2.17", | ||
"commander": "^8.3.0", | ||
"cross-fetch": "^3.1.5", | ||
"ethers": "^5.6.2" | ||
} | ||
} |
This file contains 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,127 @@ | ||
import { formatsByCoinType } from '@ensdomains/address-encoder'; | ||
import { Command } from 'commander'; | ||
import ethers from 'ethers'; | ||
import { abi as UniversalResolver_abi } from '@ensdomains/ens-contracts/artifacts/contracts/utils/UniversalResolver.sol/UniversalResolver.json'; | ||
import { abi as OffchainResolver_abi } from '@ensdomains/offchain-resolver-contracts/artifacts/contracts/OffchainResolver.sol/OffchainResolver.json'; | ||
import { abi as Gateway_abi } from '@ensdomains/ens-contracts/artifacts/contracts/utils/OffchainMulticallable.sol/BatchGateway.json'; | ||
import { abi as IResolverService_abi } from '@ensdomains/offchain-resolver-contracts/artifacts/contracts/OffchainResolver.sol/IResolverService.json'; | ||
import { abi as Resolver_abi } from '@ensdomains/ens-contracts/artifacts/contracts/resolvers/Resolver.sol/Resolver.json'; | ||
import fetch from 'cross-fetch'; | ||
|
||
const IResolverService = new ethers.utils.Interface(IResolverService_abi); | ||
|
||
function getDnsName(name: string) { | ||
const n = name.replace(/^\.|\.$/gm, ''); | ||
|
||
var bufLen = n === '' ? 1 : n.length + 2; | ||
var buf = Buffer.allocUnsafe(bufLen); | ||
|
||
let offset = 0; | ||
if (n.length) { | ||
const list = n.split('.'); | ||
for (let i = 0; i < list.length; i++) { | ||
const len = buf.write(list[i], offset + 1); | ||
buf[offset] = len; | ||
offset += len + 1; | ||
} | ||
} | ||
buf[offset++] = 0; | ||
return ( | ||
'0x' + | ||
buf.reduce( | ||
(output, elem) => output + ('0' + elem.toString(16)).slice(-2), | ||
'' | ||
) | ||
); | ||
} | ||
|
||
const GatewayI = new ethers.utils.Interface(Gateway_abi); | ||
const program = new Command(); | ||
program | ||
.requiredOption('-r --registry <address>', 'ENS registry address') | ||
.option('-p --provider <url>', 'web3 provider URL', 'http://localhost:8545/') | ||
.option('-i --chainId <chainId>', 'chainId', '1337') | ||
.option('-n --chainName <name>', 'chainName', 'unknown') | ||
.option('-u --uAddress <uaddress>', 'Universal Resolver address') | ||
.argument('<name>'); | ||
|
||
program.parse(process.argv); | ||
|
||
const options = program.opts(); | ||
const ensAddress = options.registry; | ||
const uAddress = options.uAddress; | ||
const chainId = parseInt(options.chainId); | ||
const chainName = options.chainName; | ||
const provider = new ethers.providers.JsonRpcProvider(options.provider, { | ||
chainId, | ||
name: chainName, | ||
ensAddress, | ||
}); | ||
(async () => { | ||
const name = program.args[0] || 'test.eth'; | ||
const node = ethers.utils.namehash(name); | ||
const dnsName = getDnsName(name); | ||
const uResolver = new ethers.Contract( | ||
uAddress, | ||
UniversalResolver_abi, | ||
provider | ||
); | ||
|
||
const [resolverAddress] = await uResolver.callStatic.findResolver(dnsName); | ||
if (resolverAddress) { | ||
const offchainResolver = new ethers.Contract( | ||
resolverAddress, | ||
OffchainResolver_abi, | ||
provider | ||
); | ||
const iface = new ethers.utils.Interface(Resolver_abi); | ||
const coinTypes = [60, 0]; | ||
const callDatas = coinTypes.map(coinType => { | ||
const addrData = iface.encodeFunctionData('addr(bytes32,uint256)', [ | ||
node, | ||
coinType, | ||
]); | ||
return IResolverService.encodeFunctionData('resolve', [ | ||
dnsName, | ||
addrData, | ||
]); | ||
}); | ||
try { | ||
await offchainResolver.callStatic.multicall(callDatas); | ||
} catch (e) { | ||
if (e && e.errorArgs) { | ||
const url = e.errorArgs.urls[0]; | ||
const lowerTo = e.errorArgs.sender.toLowerCase(); | ||
const callData = e.errorArgs.callData; | ||
const gatewayUrl = url | ||
.replace('{sender}', lowerTo) | ||
.replace('{data}', callData); | ||
const result = await fetch(gatewayUrl); | ||
const { data: resultData } = await result.json(); | ||
const { responses: decodedQuery } = GatewayI.decodeFunctionResult( | ||
'query', | ||
resultData | ||
); | ||
for (let index = 0; index < decodedQuery.length; index++) { | ||
const dq = decodedQuery[index]; | ||
const { result: addrResult } = IResolverService.decodeFunctionResult( | ||
'resolve', | ||
dq | ||
); | ||
const coinType = coinTypes[index]; | ||
const { encoder } = formatsByCoinType[coinType]; | ||
const finalResult = iface.decodeFunctionResult( | ||
'addr(bytes32,uint256)', | ||
addrResult | ||
); | ||
const hex = finalResult[0].slice(2); | ||
const buffered = Buffer.from(hex, 'hex'); | ||
const decodedResult = encoder(buffered); | ||
console.log({ name, coinType, finalResult, decodedResult }); | ||
} | ||
} else { | ||
console.log(105, e); | ||
} | ||
} | ||
} | ||
})(); |
This file contains 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,36 @@ | ||
{ | ||
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs | ||
"include": ["src", "types"], | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"lib": ["dom", "esnext"], | ||
"importHelpers": true, | ||
// output .d.ts declaration files for consumers | ||
"declaration": true, | ||
// output .js.map sourcemap files for consumers | ||
"sourceMap": true, | ||
// match output dir to input dir. e.g. dist/index instead of dist/src/index | ||
"rootDir": "./src", | ||
// stricter type-checking for stronger correctness. Recommended by TS | ||
"strict": true, | ||
// linter checks for common issues | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
// noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
// use Node's module resolution algorithm, instead of the legacy TS one | ||
"moduleResolution": "node", | ||
// transpile JSX to React.createElement | ||
"jsx": "react", | ||
// interop between ESM and CJS modules. Recommended by TS | ||
"esModuleInterop": true, | ||
// significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS | ||
"skipLibCheck": true, | ||
// error out if import and file system have a casing mismatch. Recommended by TS | ||
"forceConsistentCasingInFileNames": true, | ||
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
} | ||
} |
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.
Can't all of this be replaced by a simple call to Ethers to resolve the name now?