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

EIP-5559 with getDeferralHandler #245

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
366 changes: 0 additions & 366 deletions ensips/ccip-write/ccip-write.md

This file was deleted.

Binary file removed ensips/ccip-write/images/db.register.png
Binary file not shown.
Binary file removed ensips/ccip-write/images/l2.register.png
Binary file not shown.
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"test": "npm-run-all test:**",
"test:l1": "hardhat test ./test/arb.e2e.spec.ts --network localhost",
"test:db": "hardhat test ./test/db.e2e.spec.ts --network localhost",
"test:metadata": "hardhat test ./test/metadata.e2e.spec.ts --network localhost",
"start:read": "ts-node src/read.ts",
"start:write": "ts-node src/write.ts",
"lint": "eslint . --ext .ts --fix"
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { normalize } from 'viem/ens'
import { getChain } from './client'
import { abi as l1Abi } from '@blockful/contracts/out/L1Resolver.sol/L1Resolver.json'

config({
path: process.env.ENV_FILE || '../.env',
})
Expand Down
90 changes: 53 additions & 37 deletions packages/client/src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from 'dotenv'
import {
Hex,
createPublicClient,
decodeErrorResult,
encodeFunctionData,
http,
namehash,
Expand All @@ -18,7 +19,9 @@ import {
import { normalize, packetToBytes } from 'viem/ens'
import { privateKeyToAccount } from 'viem/accounts'

import { abi as l1Abi } from '@blockful/contracts/out/L1Resolver.sol/L1Resolver.json'
import { abi } from '@blockful/contracts/out/DatabaseResolver.sol/DatabaseResolver.json'
pikonha marked this conversation as resolved.
Show resolved Hide resolved
import { abi as universalResolverResolveAbi } from '@blockful/contracts/out/UniversalResolver.sol/UniversalResolver.json'
pikonha marked this conversation as resolved.
Show resolved Hide resolved
import { abi as scAbi } from '@blockful/contracts/out/SubdomainController.sol/SubdomainController.json'
import { MessageData, DomainData } from '@blockful/gateway/src/types'
import { getRevertErrorData, getChain, handleDBStorage } from './client'

Expand Down Expand Up @@ -57,50 +60,25 @@ const _ = (async () => {
const node = namehash(name)
const signer = privateKeyToAccount(privateKey as Hex)

const duration = 31556952000n

const resolverAddr = await client.getEnsResolver({
name,
universalResolverAddress: universalResolver as Hex,
})

// SUBDOMAIN PRICING

let value = 0n
try {
const [_value /* commitTime */ /* extraData */, ,] =
(await client.readContract({
address: resolverAddr,
abi: l1Abi,
functionName: 'registerParams',
args: [toHex(name), duration],
})) as [bigint, bigint, Hex]
value = _value
} catch {
// interface not implemented by the resolver
}

// REGISTER NEW SUBDOMAIN

const data: Hex[] = [
encodeFunctionData({
functionName: 'setText',
abi: l1Abi,
abi,
args: [node, 'com.twitter', `@${name}`],
}),
encodeFunctionData({
functionName: 'setAddr',
abi: l1Abi,
abi,
args: [node, '0x3a872f8FED4421E7d5BE5c98Ab5Ea0e0245169A0'],
}),
encodeFunctionData({
functionName: 'setAddr',
abi: l1Abi,
abi,
args: [node, 1n, '0x3a872f8FED4421E7d5BE5c98Ab5Ea0e0245169A0'],
}),
encodeFunctionData({
functionName: 'setContenthash',
abi: l1Abi,
abi,
args: [
node,
stringToHex(
Expand All @@ -110,9 +88,10 @@ const _ = (async () => {
}),
]

const duration = 31556952000n
const calldata = {
functionName: 'register',
abi: l1Abi,
abi: scAbi,
args: [
encodedName,
signer.address, // owner
Expand All @@ -124,18 +103,35 @@ const _ = (async () => {
0, // fuses
zeroHash,
],
address: resolverAddr,
account: signer,
value,
}

try {
await client.simulateContract(calldata)
await client.readContract({
address: universalResolver as Hex,
abi: universalResolverResolveAbi,
functionName: 'resolve',
args: [
encodedName,
encodeFunctionData({
functionName: 'writeParams',
abi,
args: [encodedName, encodeFunctionData(calldata)],
}),
],
})
pikonha marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
const data = getRevertErrorData(err)
switch (data?.errorName) {
if (!data || !data.args || data.args?.length === 0) return

const [params] = data.args
const errorResult = decodeErrorResult({
abi,
data: params as Hex,
})
switch (errorResult?.errorName) {
case 'StorageHandledByOffChainDatabase': {
const [domain, url, message] = data.args as [
const [domain, url, message] = errorResult.args as [
DomainData,
string,
MessageData,
Expand All @@ -144,17 +140,37 @@ const _ = (async () => {
return
}
case 'StorageHandledByL2': {
const [chainId, contractAddress] = data.args as [bigint, `0x${string}`]
const [chainId, contractAddress] = errorResult.args as [
bigint,
`0x${string}`,
]

const l2Client = createPublicClient({
chain: getChain(Number(chainId)),
transport: http(providerL2),
}).extend(walletActions)

// SUBDOMAIN PRICING

let value = 0n
try {
const [_value /* commitTime */ /* extraData */, ,] =
(await client.readContract({
address: contractAddress,
abi: scAbi,
functionName: 'registerParams',
args: [encodedName, duration],
})) as [bigint, bigint, Hex]
value = _value
} catch {
// interface not implemented by the resolver
}

try {
const { request } = await l2Client.simulateContract({
...calldata,
address: contractAddress,
value,
})
await l2Client.writeContract(request)
} catch (err) {
Expand Down
Loading
Loading