Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Oct 29, 2024
1 parent 985c344 commit b18615c
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/components/pages/migrate/MigrationTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useApprovedNamesForMigration } from '@app/hooks/migration/useApprovedNa
import { makeIntroItem } from '@app/transaction-flow/intro'
import { createTransactionItem, TransactionData } from '@app/transaction-flow/transaction'
import { useTransactionFlow } from '@app/transaction-flow/TransactionFlowProvider'
import { REBATE_DATE } from '@app/utils/constants'

import { MigrationNamesList, NameListTab } from './MigrationNamesList'
import { MigrationSection } from './MigrationSection'
Expand Down Expand Up @@ -545,7 +546,7 @@ const ExtensionTab = ({
const [activeTab, setNameListTab] = useState<ExtensionTabType>('eligible')

const claimedNames = allNames.filter(
(name) => name.expiryDate && name.expiryDate.date > new Date(2030, 11, 31, 0, 0),
(name) => name.expiryDate && name.expiryDate.date > REBATE_DATE,
)

const eligibleNames = allNames.filter((name) => !claimedNames.includes(name))
Expand Down
43 changes: 0 additions & 43 deletions src/migration/bulkRenewal.ts

This file was deleted.

74 changes: 70 additions & 4 deletions src/transaction-flow/input/BulkRenewal/BulkRenewal-flow.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,92 @@
import { useState } from 'react'
import { namehash } from 'viem'
import { useClient, useReadContract } from 'wagmi'

import { NameWithRelation } from '@ensdomains/ensjs/subgraph'
import { Dialog } from '@ensdomains/thorin'

import { InvoiceItem } from '@app/components/@atoms/Invoice/Invoice'
import { DateSelection } from '@app/components/@molecules/DateSelection/DateSelection'
import { ONE_YEAR } from '@app/utils/time'
import { createTransactionItem } from '@app/transaction-flow/transaction'
import { bulkRenewalContract } from '@app/transaction-flow/transaction/bulkRenew'
import { REBATE_DATE } from '@app/utils/constants'
import { calculateDatesDiff, secondsFromDateDiff, secondsToDate } from '@app/utils/date'
import { ONE_YEAR, secondsToYears } from '@app/utils/time'

export type Props = { data: { names: NameWithRelation[] } }

const abi = [
{
inputs: [
{
internalType: 'string[]',
name: 'names',
type: 'string[]',
},
{
internalType: 'uint256',
name: 'targetExpiry',
type: 'uint256',
},
],
name: 'getTargetExpiryPriceData',
outputs: [
{
internalType: 'uint256',
name: 'total',
type: 'uint256',
},
{
internalType: 'uint256[]',
name: 'durations',
type: 'uint256[]',
},
{
internalType: 'uint256[]',
name: 'prices',
type: 'uint256[]',
},
],
stateMutability: 'view',
type: 'function',
},
] as const

const BulkRenewalFlow = ({ data }: Props) => {
const sortedNames = data.names.toSorted((a, b) => a.expiryDate?.value - b.expiryDate?.value)
const sortedNames = data.names.toSorted((a, b) => a.expiryDate!.value! - b.expiryDate!.value!)

const minDateDiff = calculateDatesDiff(sortedNames[0].expiryDate!.date, REBATE_DATE)

const minSeconds = secondsFromDateDiff({
startDate: sortedNames[0].expiryDate!.date,
additionalDays: minDateDiff.diff.days,
additionalMonths: minDateDiff.diff.months,
additionalYears: minDateDiff.diff.years,
})

const [seconds, setSeconds] = useState(() => 5 * ONE_YEAR)
const [seconds, setSeconds] = useState(() => minSeconds)
const [durationType, setDurationType] = useState<'years' | 'date'>('years')

// const client = useClient()

// const {
// data: expiryData,
// error,
// status,
// } = useReadContract({
// abi,
// address: bulkRenewalContract[client.chain.id!]!,
// functionName: 'getTargetExpiryPriceData',
// args: [data.names.map((name) => namehash(name.name!)), BigInt(seconds)],
// })

return (
<>
<Dialog.Heading title={`Extend ${data.names.length} names`} />
<Dialog.Content>
<DateSelection
{...{ seconds, setSeconds, durationType }}
minSeconds={5 * ONE_YEAR}
minSeconds={minSeconds}
mode="extend"
onChangeDurationType={setDurationType}
/>
Expand Down
102 changes: 102 additions & 0 deletions src/transaction-flow/transaction/bulkRenew.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { TFunction } from 'react-i18next'
import { goerli, holesky, localhost, mainnet, sepolia } from 'viem/chains'
import { encodeFunctionData } from 'viem/utils'

import type { Transaction, TransactionDisplayItem, TransactionFunctionParameters } from '@app/types'

type Data = { names: `0x${string}`[]; durations: bigint[]; prices: bigint[] }

export const targetExpiryAbi = [
{
inputs: [
{
internalType: 'string[]',
name: 'names',
type: 'string[]',
},
{
internalType: 'uint256',
name: 'targetExpiry',
type: 'uint256',
},
],
name: 'getTargetExpiryPriceData',
outputs: [
{
internalType: 'uint256',
name: 'total',
type: 'uint256',
},
{
internalType: 'uint256[]',
name: 'durations',
type: 'uint256[]',
},
{
internalType: 'uint256[]',
name: 'prices',
type: 'uint256[]',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'string[]',
name: 'names',
type: 'string[]',
},
{
internalType: 'uint256[]',
name: 'durations',
type: 'uint256[]',
},
{
internalType: 'uint256[]',
name: 'prices',
type: 'uint256[]',
},
],
name: 'renewAllWithTargetExpiry',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
] as const

export const bulkRenewalContract = {
[mainnet.id]: '0xnotdeployedyet',
[goerli.id]: '0xdeprecated',
[localhost.id]: '0xnotdeployedyet',
[holesky.id]: '0x76aafA281Ed5155f83926a12ACB92e237e322A8C',
[sepolia.id]: '0xf9c8c83adda8d52d9284cdbef23da10b5f9869bf',
} as const

const displayItems = (
{ names }: Data,
t: TFunction<'translation', undefined>,
): TransactionDisplayItem[] => [
{
label: 'names',
value: names.map((name) => `0x${name}`).join(', '),
},
{
label: 'action',
value: t('transaction.info.fuses.CAN_EXTEND_EXPIRY'),
},
]

const transaction = async ({ client, data }: TransactionFunctionParameters<Data>) => {
return {
to: bulkRenewalContract[client.chain.id],
data: encodeFunctionData({
abi: targetExpiryAbi,
functionName: 'renewAllWithTargetExpiry',
args: [data.names, data.durations, data.prices],
}),
}
}

export default { displayItems, transaction } satisfies Transaction<Data>
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export const IS_DEV_ENVIRONMENT =
process.env.NEXT_PUBLIC_PROVIDER

export const INVALID_NAME = '[Invalid ENS Name]'

export const REBATE_DATE = new Date(2030, 11, 31, 0, 0)

0 comments on commit b18615c

Please sign in to comment.