Skip to content
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

CCIP-read support #59

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/ensjs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
],
"no-useless-return": ["off"],
"radix": ["error", "as-needed"],
"no-bitwise": ["off"]
"no-bitwise": ["off"],
"import/no-extraneous-dependencies": ["off"],
"no-empty": ["error", { "allowEmptyCatch": true }]
},
"ignorePatterns": ["node_modules", "dist", "data", "cache", "esbuild.js"]
}
3 changes: 3 additions & 0 deletions packages/ensjs/ens-test-env.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ require('dotenv').config({

process.env.ADDRESS_ETH_REGISTRAR = '0xc5a5C42992dECbae36851359345FE25997F5C42d'
process.env.ADDRESS_NAME_WRAPPER = '0x9E545E3C0baAB3E08CdfD552C960A1050f373042'
process.env.BATCH_GATEWAY_URLS = JSON.stringify([
'https://universal-offchain-unwrapper.ens-cf.workers.dev/',
])

/**
* @type {import('@ensdomains/ens-test-env').ENSTestEnvConfig}
Expand Down
4 changes: 2 additions & 2 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
},
"devDependencies": {
"@ensdomains/buffer": "^0.0.13",
"@ensdomains/ens-contracts": "^0.0.14",
"@ensdomains/ens-contracts": "^0.0.15",
"@ensdomains/ens-test-env": "workspace:*",
"@ethersproject/abi": "^5.6.0",
"@ethersproject/providers": "^5.6.2",
Expand All @@ -100,7 +100,7 @@
"eslint-plugin-jest": "^27.0.1",
"ganache": "^7.4.0",
"glob": "^8.0.3",
"hardhat": "^2.10.1",
"hardhat": "2.10.2",
"hardhat-abi-exporter": "^2.8.0",
"hardhat-deploy": "^0.11.12",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/contracts/getContractAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const addresses: Record<
'1': '0x580AF46E06DaaD47eb5940526FD64d95b815Cb70',
'3': '0x74e20bd2a1fe0cdbe45b9a1d89cb7e0a45b36376',
'4': '0x74e20bd2a1fe0cdbe45b9a1d89cb7e0a45b36376',
'5': '0x9380F1974D2B7064eA0c0EC251968D8c69f0Ae31',
'5': '0x687c30Cc44bFA39A1449e86E172BF002E7b3f0b0',
},
BulkRenewal: {
'1': '0xfF252725f6122A92551A5FA9a6b6bf10eb0Be035',
Expand Down
49 changes: 40 additions & 9 deletions packages/ensjs/src/functions/batchWrappers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ethers } from 'ethers'
import { ENSArgs } from '..'
import ccipLookup from '../utils/ccip'
import { hexEncodeName } from '../utils/hexEncodedName'

export const universalWrapper = {
Expand All @@ -11,16 +12,16 @@ export const universalWrapper = {
const universalResolver = await contracts?.getUniversalResolver()!
return {
to: universalResolver.address,
data: universalResolver.interface.encodeFunctionData('resolve', [
hexEncodeName(name),
data,
]),
data: universalResolver.interface.encodeFunctionData(
'resolve(bytes,bytes)',
[hexEncodeName(name), data],
),
}
},
decode: async ({ contracts }: ENSArgs<'contracts'>, data: string) => {
const universalResolver = await contracts?.getUniversalResolver()!
const response = universalResolver.interface.decodeFunctionResult(
'resolve',
'resolve(bytes,bytes)',
data,
)
if (!response || !response[0]) {
Expand Down Expand Up @@ -75,17 +76,47 @@ export const multicallWrapper = {
]),
}
},
async decode({ contracts }: ENSArgs<'contracts'>, data: string) {
async decode(
{ contracts, provider }: ENSArgs<'contracts' | 'provider'>,
data: string,
transactions: ethers.providers.TransactionRequest[],
) {
if (!data) return
const multicall = await contracts?.getMulticall()!
try {
const [result] = multicall.interface.decodeFunctionResult(
'tryAggregate',
data,
)
return result
} catch (e) {
return e
const ccipChecked = await Promise.all(
(result as [boolean, string][]).map(
async ([success, returnData], i) => {
let newArr: [boolean, string] = [success, returnData]
// OffchainLookup(address,string[],bytes,bytes4,bytes)
if (!success && returnData.startsWith('0x556f1830')) {
try {
const newData = await ccipLookup(
provider!,
transactions[i],
returnData,
)
if (newData) {
newArr = [true, newData]
}
} catch {}
}
return {
...newArr,
success: newArr[0],
returnData: newArr[1],
}
},
),
)
return ccipChecked
} catch (e: any) {
console.error(e)
return
}
},
}
4 changes: 2 additions & 2 deletions packages/ensjs/src/functions/getName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const raw = async ({ contracts }: ENSArgs<'contracts'>, address: string) => {
const reverseNode = `${address.toLowerCase().substring(2)}.addr.reverse`
return {
to: universalResolver.address,
data: universalResolver.interface.encodeFunctionData('reverse', [
data: universalResolver.interface.encodeFunctionData('reverse(bytes)', [
hexEncodeName(reverseNode),
]),
}
Expand All @@ -21,7 +21,7 @@ const decode = async (
const universalResolver = await contracts?.getUniversalResolver()!
try {
const result = universalResolver.interface.decodeFunctionResult(
'reverse',
'reverse(bytes)',
data,
)
return {
Expand Down
6 changes: 4 additions & 2 deletions packages/ensjs/src/functions/getOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const decode = async (
name: string,
contract?: 'nameWrapper' | 'registry' | 'registrar',
): Promise<Owner | undefined> => {
if (data === null) return
if (!data) return
const labels = name.split('.')
if (contract || labels.length === 1) {
const singleOwner = singleContractOwnerDecode(data)
Expand All @@ -119,7 +119,7 @@ const decode = async (
}
}
const result = await multicallWrapper.decode(data)
if (result === null) return
if (!result) return
const nameWrapper = await contracts?.getNameWrapper()!

const decodedData = [result[0][1], result[1][1], result[2]?.[1]].map(
Expand Down Expand Up @@ -163,6 +163,7 @@ const decode = async (
// this means that the subname is wrapped
if (
registryOwner === nameWrapper.address &&
nameWrapperOwner &&
ethers.utils.hexStripZeros(nameWrapperOwner) !== '0x'
) {
return {
Expand All @@ -186,6 +187,7 @@ const decode = async (
// and for wrapped names, owner and registrant are the same thing
if (
registryOwner === nameWrapper.address &&
nameWrapperOwner &&
ethers.utils.hexStripZeros(nameWrapperOwner) !== '0x'
) {
return {
Expand Down
29 changes: 29 additions & 0 deletions packages/ensjs/src/functions/getProfile-ccip.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import dotenv from 'dotenv'
import { ENS } from '..'
import setup from '../tests/setup'

dotenv.config()

let ensInstance: ENS

beforeAll(async () => {
;({ ensInstance } = await setup(true))
})

jest.setTimeout(20000)

describe('getProfile', () => {
it('should return a profile from a ccip-read name', async () => {
const result = await ensInstance.getProfile('1.offchainexample.eth', {
fallback: {
texts: ['email', 'description'],
contentHash: true,
coinTypes: ['0', '60'],
},
})
expect(result).toBeTruthy()
if (result) {
expect(result.address).toBe('0x41563129cDbbD0c5D3e1c86cf9563926b243834d')
}
})
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/getProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('getProfile', () => {
'0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
)
expect(result.resolverAddress).toBe(
deploymentAddresses.NoMulticallResolver.toLowerCase(),
deploymentAddresses.NoMulticallResolver,
)
}
})
Expand Down
Loading